如何在 ASP.NET Web 应用程序中访问 splunk-otel-collector 生成的 TraceId?

问题描述 投票:0回答:1

在当前项目中,我将应用程序日志发送到Splunk,而splunk-otel-collector负责将仪器日志发送到SignalFx。问题是我们使用CloudFrontID作为correlationID来过滤Splunk中的日志,而SignalFx生成并使用TraceId进行日志记录。我目前面临将应用程序日志的correlationID 与SignalFx 的TraceId 关联起来的挑战。

我尝试使用“Serilog.Enrichers.Span”NuGet 包在应用程序日志中记录 TraceId 值。但是,Splunk 中未记录任何值。

var loggerConfig =
    new LoggerConfiguration().MinimumLevel.ControlledBy(LogLevel)
        .Destructure.UsingAttributes()
        .Enrich.WithSpan(new SpanOptions
        {
            IncludeTraceFlags = true,
            LogEventPropertiesNames = new SpanLogEventPropertiesNames()
            {
                ParentId = "ParentId1",
                SpanId = "SpanId1",
                TraceId = "TraceId1",
                OperationName = "OperationName1"
            },
            IncludeBaggage = true,
            IncludeOperationName = true,
            IncludeTags = true,
        })
        .Enrich.FromLogContext();

如何在 ASP.NET Web 应用程序(框架版本:4.7.2)中访问 splunk-otel-collector 生成的 TraceId?

c# asp.net splunk open-telemetry signalfx
1个回答
0
投票

要在日志中注入跟踪上下文字段,请在运行检测的应用程序之前将 SIGNALFX_LOGS_INJECTION 环境变量设置为 true 来启用日志关联。

参考:https://github.com/signalfx/signalfx-dotnet-tracing/blob/main/docs/correlated-traces-with-logs.md

启用此环境变量:SIGNALFX_LOGS_INJECTION后,我能够在Splunk中看到traceId值。

© www.soinside.com 2019 - 2024. All rights reserved.