OpenTelemetry.net、SqlClient 中未调用丰富回调

发布于 2025-01-16 07:02:08 字数 1478 浏览 3 评论 0原文

这是在 .NET 6 上。

所以我添加了一个丰富的回调,目的是将每个参数添加为标签:

 appBuilder.Services.AddOpenTelemetryTracing((builder) =>
        
        builder
            .AddAspNetCoreInstrumentation()
            .SetSampler(new AlwaysOnSampler())
            .AddSqlClientInstrumentation(options =>
            {
                options.SetDbStatementForText = true;
                options.SetDbStatementForStoredProcedure = true;
                options.RecordException = true;
                options.EnableConnectionLevelAttributes = true;
                options.Enrich = (activity, eventName, rawObject) =>
                {
                    if (eventName.Equals("OnCustom"))
                    {
                        activity.SetTag("ParametersAdded", "true");
                        if (rawObject is SqlCommand cmd)
                        {
                            foreach (SqlParameter parameter in cmd.Parameters)
                            {
                                activity.SetTag(parameter.ParameterName, parameter.Value.ToString());
                            }
                        }
                    }
                };
            })
            .AddZipkinExporter(options =>
            {
                options.Endpoint = new Uri(appBuilder.Configuration["TraceExporterUrl"]);

            }));

我在 Zipkin 中获取导出,但它没有添加标签,而且似乎没有根本没有点击 Enrich 回调 -ParametersAdded 标签也没有被点击。无法弄清楚为什么这不起作用 - 我是否从根本上误解了某些东西?

This is on .NET 6.

So I've added an enrich callback with the purpose of adding each parameter as a tag:

 appBuilder.Services.AddOpenTelemetryTracing((builder) =>
        
        builder
            .AddAspNetCoreInstrumentation()
            .SetSampler(new AlwaysOnSampler())
            .AddSqlClientInstrumentation(options =>
            {
                options.SetDbStatementForText = true;
                options.SetDbStatementForStoredProcedure = true;
                options.RecordException = true;
                options.EnableConnectionLevelAttributes = true;
                options.Enrich = (activity, eventName, rawObject) =>
                {
                    if (eventName.Equals("OnCustom"))
                    {
                        activity.SetTag("ParametersAdded", "true");
                        if (rawObject is SqlCommand cmd)
                        {
                            foreach (SqlParameter parameter in cmd.Parameters)
                            {
                                activity.SetTag(parameter.ParameterName, parameter.Value.ToString());
                            }
                        }
                    }
                };
            })
            .AddZipkinExporter(options =>
            {
                options.Endpoint = new Uri(appBuilder.Configuration["TraceExporterUrl"]);

            }));

I'm getting the export in Zipkin, but it's not added the tags, and it doesn't seem to be hitting that Enrich callback at all - the ParametersAdded tag isn't being hit either. Can't figure out why this isn't working - Have I fundamentally misunderstood something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幻梦 2025-01-23 07:02:08

对于未将 IsAllDataRequested 属性设置为 true 的活动,不会调用丰富。

The Enrich is not called for activities that don't have the IsAllDataRequested property set to true.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文