OpenTelemetry.net、SqlClient 中未调用丰富回调
这是在 .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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于未将 IsAllDataRequested 属性设置为 true 的活动,不会调用丰富。
The Enrich is not called for activities that don't have the IsAllDataRequested property set to true.