如何在没有后端收集器的情况下将 opentelemetry 数据导出到文件中进行测试

kzf*_*fid 4 c# open-telemetry

我有使用 OpenTelemetry 的 c# 应用程序。

不同的后端收集器有不同的导出器(例如 Jaeger)

但在我的开发环境中,没有设置这样的后端服务。

虽然我可以使用控制台导出器,但它会与我的其他消息混合在一起。

我也尝试过 Otlp Exporter

.AddOtlpExporter(options => options.Endpoint = new Uri(@"C:\temp\a.txt"))
Run Code Online (Sandbox Code Playgroud)

但返回以下错误

System.NotSupportedException: 'Endpoint URI scheme (file) is not supported. Currently only "http" and "https" are supported.'
Run Code Online (Sandbox Code Playgroud)

目前似乎不支持文件架构。

有什么方法可以简单地将其输出到文件中以便于测试和调试吗?

小智 5

您始终可以编写自己的导出器。它的实现应该相当简单,您可以使用控制台导出器作为模板,只需写入文件而不是控制台。

https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Exporter.Console/ConsoleActivityExporter.cs