question

andrewchoi-4221 avatar image
0 Votes"
andrewchoi-4221 asked tinywang-msft commented

ASP.net core OpenTelemetry tracing implementation at Controller level

I am on .net 6 asp.net core. In my web api project, I have the following registration of opentelemetry services.

 services.AddOpenTelemetryTracing(providerBuilder =>
             {
                 providerBuilder
                        
                     .AddSource("DataInsight")
                     .SetResourceBuilder(ResourceBuilder.CreateDefault()
                         .AddService("InsightDataService"))
                     .AddHttpClientInstrumentation()
                     .AddAspNetCoreInstrumentation(
                         options =>
                         {
                             options.Enrich = Enrich;
                             options.RecordException = true;
                         }
                     )
                     .AddSqlClientInstrumentation()
                     .AddConsoleExporter()
                     .AddOtlpExporter(opt =>
                     {
                         opt.Endpoint = new Uri("http://localhost:58459");
                     });
             });

In my controller, I had the following code to create an activity and addTag. However, the tags are not being added to the trace of my output.

 using var activity = Startup.ActivitySource.StartActivity("GetReportData");
 if (activity.IsAllDataRequested)
 {
 activity?.SetTag("GetData1", "Success");
 activity?.AddTag("GetLinkData", "Success");
 }


dotnet-aspnet-core-webapi
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, actually I didn't find a document about how to use OpenTelemetry in asp.net core. You may go to their site to get assistance...


0 Votes 0 ·

0 Answers