OpenTelemetry .NET distro for Uptrace

This document explains how to configure OpenTelemetry .NET SDK to export spans and metrics to Uptrace using OTLP/gRPC.

To learn about OpenTelemetry API, see OpenTelemetry .NET Tracing APIopen in new window and OpenTelemetry .NET Metrics APIopen in new window.

Uptrace .NET

uptrace-dotnetopen in new window is a thin wrapper over opentelemetry-dotnetopen in new window that configures OpenTelemetry SDK to export data to Uptrace. It does not add any new functionality and is provided only for your convenience.

To install uptrace-dotnet:

dotnet add package Uptrace.OpenTelemetry --prerelease


You can configure Uptrace client using a DSN (Data Source Name) from the project settings page.

using System;
using System.Diagnostics;

using OpenTelemetry;
using OpenTelemetry.Trace;
using OpenTelemetry.Resources;

using Uptrace.OpenTelemetry;

var serviceName = "myservice";
var serviceVersion = "1.0.0";

var openTelemetry = Sdk.CreateTracerProviderBuilder()
    .AddSource("*") // subscribe to all activity sources
            .AddService(serviceName: serviceName, serviceVersion: serviceVersion)
    // copy your project DSN here or use UPTRACE_DSN env var

You can also use environment variables to configure the client:

Env varDescription
UPTRACE_DSNA data source that is used to connect to For example, https://<token><project_id>.
OTEL_RESOURCE_ATTRIBUTESKey-value pairs to be used as resource attributes. For example,,service.version=1.0.0.
OTEL_SERVICE_NAME=myserviceSets the value of the resource attribute. Takes precedence over OTEL_RESOURCE_ATTRIBUTES.
OTEL_PROPAGATORSPropagators to be used as a comma separated list. The default is tracecontext,baggage.

See OpenTelemetry documentationopen in new window for details.


Spend 5 minutes to install OpenTelemetry distro, generate your first trace, and click the link in your terminal to view the trace.

git clone
cd example/basic
  • Step 2. Run the example to get a link for the generated trace:
$ UPTRACE_DSN="" dotnet run<trace_id>
  • Step 3. Follow the link to view the trace:

Basic trace

Already using OTLP exporter?

If you are already using OTLP exporter, you can continue to use it with Uptrace by changing some configuration options.

To maximize performance and efficiency, consider the following recommendations when configuring OpenTelemetry SDK.

Use BatchSpanProcessor to export multiple spans in a single request.AllEssential
Enable gzip compression to compress the data before sending and reduce the traffic cost.AllEssential
Prefer delta metrics temporality, because such metrics are smaller and Uptrace must convert cumulative metrics to delta anyway.MetricsRecommended
Use AWS X-Ray ID generator for OpenTelemetry.Traces, LogsOptional

To configure OpenTelemetry to send data to Uptrace, use the provided endpoint and pass the DSN via uptrace-dsn header:

# Uncomment the appropriate protocol for your programming language.
# Only for OTLP/gRPC
# Only for OTLP/HTTP

# Pass Uptrace DSN in gRPC/HTTP headers.
export OTEL_EXPORTER_OTLP_HEADERS="uptrace-dsn="

# Enable gzip compression.

# Enable exponential histograms.

# Prefer delta temporality.

When configuring BatchSpanProcessor, use the following settings:

# Maximum allowed time to export data in milliseconds.

# Maximum batch size.
# Using larger batch sizes can be problematic,
# because Uptrace rejects requests larger than 20MB.

# Maximum queue size.
# Increase queue size if you have lots of RAM, for example,
# `10000 * number_of_gigabytes`.

# Max concurrent exports.
# Setting this to the number of available CPUs might be a good idea.


If you encounter any issue with OpenTelemetry .NET, try the following guides:

What's next?

Next, instrument more operations to get a more detailed picture. Try to prioritize network calls, disk operations, database queries, error and logs.

You can also create your own instrumentations using OpenTelemetry .NET Tracing APIopen in new window.

Last Updated: