OpenTelemetry

Use OpenTelemetry to trace performance of your Ucommerce project

OpenTelemetryarrow-up-right has become the industry standard for tracing and metrics. Ucommerce comes with support for OpenTelemetry out of the box, and includes tracing for all pipelines.

To enable OpenTelemetry, see the OpenTelemetry documentationarrow-up-right. To add the Ucommerce pipeline tracing, add ucommerce.web.infrastructure.pipelines as a source. See example below:

public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicationBuilder builder)
{
    builder.Logging.AddOpenTelemetry(logging =>
    {
        logging.IncludeFormattedMessage = true;
        logging.IncludeScopes = true;
    });

    builder.Services.AddOpenTelemetry()
        .WithMetrics(metrics =>
        {
            metrics.AddAspNetCoreInstrumentation()
                .AddHttpClientInstrumentation()
                .AddRuntimeInstrumentation();
        })
        .WithTracing(tracing =>
        {
            tracing.AddAspNetCoreInstrumentation()
                .AddHttpClientInstrumentation()
                .AddSqlClientInstrumentation()
                .AddSource("ucommerce.web.infrastructure.pipelines");
        });

    builder.AddOpenTelemetryExporters();

    return builder;
}

Leveraging OpenTelemetry when developing locally is easy using .NET Aspirearrow-up-right as it gives you a nice UI to monitor all ressources. For production, use Azure Application Insights or similar.

Last updated