ASP.net core OpenTelemetry tracing implementation at Controller level

andrew choi 1 Reputation point
2022-09-16T00:36:58.28+00:00

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");  
}  
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,188 questions
{count} votes