Общая настройка DealTracingHosting (Deal.Grpc.Hosting + Deal.Api): AspNetCore/Http/GrpcNetClient инструментация, OTLP-экспорт во внешний коллектор, имя сервиса из env. Логи обогащаются TraceId/SpanId.
21 lines
608 B
C#
21 lines
608 B
C#
using System.Diagnostics;
|
|
using Serilog.Core;
|
|
using Serilog.Events;
|
|
|
|
namespace Deal.Api.Logging;
|
|
|
|
internal sealed class TraceContextEnricher : ILogEventEnricher
|
|
{
|
|
void ILogEventEnricher.Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
|
|
{
|
|
Activity? activity = Activity.Current;
|
|
if (activity is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("TraceId", activity.TraceId.ToString()));
|
|
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("SpanId", activity.SpanId.ToString()));
|
|
}
|
|
}
|