如何在dotnet C#中使用开放式遥测设置弹性云可观察性的环境?

发布于 2025-01-24 05:49:24 字数 291 浏览 0 评论 0原文

我配置了我的跟踪提供商,仪器和OTLP出口商,它们在弹性云可观察性仪表板中效果很好。

设置服务名称很容易,但是似乎并没有设置环境名称的常见API。

因此,当我单击跟踪时,我看到的只是全部或未定义。

I have configured my tracing provider, instrumentation and OTLP Exporter which works great in Elastic Cloud Observability dashboards.

It is easy to set the service name but there does not seem seem to be a common API to set the Environment name.

So when I click on Traces all I see is All or Not Defined.

enter image description here

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

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

发布评论

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

评论(1

楠木可依 2025-01-31 05:49:24

仔细浏览了围绕开放遥测的弹性搜索文档后,我发现绝对没有有关如何做到这一点的信息!

-edit-最近允许W3C使用弹性架构常见模式。因此,引用

您需要与Otel Exporter一起通过的属性就像

  • service.envorirnment * *
  • ,但我也通过deployment.environment.environment
  • 和'host.name'
  • 和“ host.hostname”
  • 在这里有意义的其他任何弹性常见模式

是可以为您解决问题的代码段。

 var otelAttributes = new List<KeyValuePair<string, object>>();
 otelAttributes.Add(new KeyValuePair<string, object>("deployment.environment", environmentName));

然后,您需要在资源建立器中添加属性

 sdkSetup
 .AddSource("*")
 .SetSampler(new TraceIdRatioBasedSampler(samplerRateValue))
 .SetResourceBuilder(
      ResourceBuilder
       CreateDefault()
       .AddService(ResourceNameHelper.ServiceName)
       .AddAttributes(otelAttributes) // <-- Over Here
       .AddTelemetrySdk()
  )

,现在的环境将用您的所有跟踪,指标和日志

“在此处输入图像说明”

After carefully skimming the Elastic Search documentation around Open Telemetry I found absolutely no information on how to do this!?

-Edit - Recently Elastic had allowed W3C to use the Elastics Common Schema for... everything. So reference that going forward

The attribute that you need to pass along with OTEL Exporter would be like

  • service.environment *
  • but I also pass deployment.environment
  • and 'host.name'
  • and 'host.hostname'
  • any other Elastic Common Schema that make sense

Here is the code snippet that will solve the problem for you.

 var otelAttributes = new List<KeyValuePair<string, object>>();
 otelAttributes.Add(new KeyValuePair<string, object>("deployment.environment", environmentName));

Then you need to add the attributes within the ResourceBuilder

 sdkSetup
 .AddSource("*")
 .SetSampler(new TraceIdRatioBasedSampler(samplerRateValue))
 .SetResourceBuilder(
      ResourceBuilder
       CreateDefault()
       .AddService(ResourceNameHelper.ServiceName)
       .AddAttributes(otelAttributes) // <-- Over Here
       .AddTelemetrySdk()
  )

And now environments will be tagged with all your Traces, Metrics and Logs

enter image description here

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