问题描述
我们如何使用 openTelemetry 和导出器作为 AddOtlpExporter 在任何数据库中保存行跟踪数据
在我的应用程序中添加了以下 nuget 包 OpenTelemetry.Exporter.OpenTelemetryProtocol(1.0.1 OpenTelemetry(1.0.1)
我的应用程序是带有 Target Framework .netstandard2.0 的类库
// Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
// and use OTLP exporter.
var openTelemetry = Sdk.CreateTracerProviderBuilder()
.AddSource("Samples.SampleClient","Samples.SampleServer")
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("otlp-test"))
.AddOtlpExporter(opt => opt.Endpoint = new Uri("http://localhost:54300/WeatherForecast/GetTrace"))
.Build();
using (var sample = new InstrumentationWithActivitySource())
{
sample.Start();
}
InstrumentationWithActivitySource : 您可以从链接中找到代码: https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/examples/Console/InstrumentationWithActivitySource.cs
http://localhost:54300/WeatherForecast/GetTrace 这个简单的 web api 返回字符串
我想将跟踪原始数据接收到此 API 中
你能帮我如何接收原始数据以便我可以保存到数据库中吗? 我不想使用 AddZipkinExporter 或其他一些工具来接收跟踪/日志数据。
解决方法
Otlp 导出器通过 gRPC 通道导出跟踪,因此您需要有 gRPC 服务器来接收跟踪。 您可以做的是,您可以在两者之间使用 otlp 收集器,这样您的应用程序将通过 gRPC 通道将跟踪发送到 otpl-collector,并且您可以配置 otlp 收集器以在 otlphttp 导出器的帮助下以 HTTP 格式导出跟踪。
在收集器配置中的导出器中配置您的网络服务 URI,如下所示。
[]<typename A,auto B,typename Q>{};
使用 this proto 反序列化 API 输入,然后您可以将其存储在 您所需格式的数据库。