OpenTelemetry .NET distro for Uptrace

uptrace-dotnetopen in new window configures opentelemetry-dotnetopen in new window to export spans and metrics to Uptrace using OpenTelemetry protocol (OTLP).

Installation

To install uptrace-dotnet:

dotnet add package Uptrace.OpenTelemetry --prerelease

Configuration

You can configure Uptrace client using a DSN (Data Source Name, e.g. https://<key>@uptrace.dev/<project_id>) from the project settings page.

using System;
using System.Diagnostics;

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

using Uptrace.OpenTelemetry;

var openTelemetry = Sdk.CreateTracerProviderBuilder()
    .AddSource("*") // subscribe to all activity sources
    .SetResourceBuilder(
        ResourceBuilder
            .CreateDefault()
            .AddEnvironmentVariableDetector()
            .AddService("myservice")
    )
    // copy your project DSN here or use UPTRACE_DSN env var
    //.AddUptrace("https://<key>@uptrace.dev/<project_id>")
    .AddUptrace()
    .Build();

You can also use environment variables to configure the client:

Env varDescription
UPTRACE_DSNA data source that is used to connect to uptrace.dev. For example, https://<key>@uptrace.dev/<project_id>.
OTEL_RESOURCE_ATTRIBUTESKey-value pairs to be used as resource attributes. For example, service.name=myservice,service.version=1.0.0.
OTEL_PROPAGATORSPropagators to be used as a comma separated list. The default is tracecontext,baggage.

Getting started

Install OpenTelemetry distro, generate your first trace, and click the link in your terminal to open Uptrace. All it takes is a minute of your time.

git clone https://github.com/uptrace/uptrace-dotnet/tree/master/example/basic
cd example/basic
  • Step 2. Run the example to get a link for the generated trace:
$ UPTRACE_DSN="https://<key>@uptrace.dev/<project_id>" dotnet run -p Example.Basic.csproj
https://uptrace.dev/traces/<trace_id>
  • Step 3. Follow the link to view the trace:

Basic trace

What's next?