# OpenTelemetry

[OpenTelemetry](https://opentelemetry.io/) 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 documentation](https://opentelemetry.io/docs/languages/dotnet/). To add the Ucommerce pipeline tracing, add `ucommerce.web.infrastructure.pipelines`  as a source. See example below:

{% code overflow="wrap" %}

```csharp
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;
}
```

{% endcode %}

Leveraging OpenTelemetry when developing locally is easy using [.NET Aspire](https://learn.microsoft.com/en-us/dotnet/aspire/get-started/aspire-overview) as it gives you a nice UI to monitor all ressources. For production, use Azure Application Insights or similar.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev.ucommerce.net/readme/miscellaneous/opentelemetry.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
