【问题标题】:Enrich callback not being called in OpenTelemetry.net, SqlClient在 OpenTelemetry.net、SqlClient 中未调用丰富回调
【发布时间】:2022-07-18 21:42:36
【问题描述】:

这是在 .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 标签也没有被命中。无法弄清楚为什么这不起作用 - 我从根本上误解了什么吗?

【问题讨论】:

    标签: c# sqlclient open-telemetry


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多