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

How can I export opentelemetry data into a file without a backend collector for testing

我有一个使用 OpenTelemetry 的 C# 应用程序。

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

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

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

我也试过 Otlp Exporter

.AddOtlpExporter(options => options.Endpoint = new Uri(@"C:\temp\a.txt"))

但是returns下面的错误

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

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

有什么办法可以简单地输出到一个文件中,方便测试和调试吗?

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

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