uptrace-dotnet is an OpenTelemery distribution configured to export traces and metrics to Uptrace.
Install uptrace-dotnet:
dotnet add package Uptrace.OpenTelemetry
You can configure Uptrace client using a DSN (Data Source Name, e.g.
https://<token>@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://<token>@api.uptrace.dev/<project_id>")
.AddUptrace()
.Build();
See the basic example to try OpenTelemetry and Uptrace.
You can configure Uptrace client using a DSN (Data Source Name, e.g.
https://<token>@uptrace.dev/<project_id>
) from the project settings page.
using System;
using System.Diagnostics;
using System.Diagnostics.Metrics;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using Uptrace.OpenTelemetry;
var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter("MyMeter") // subscribe to all the meters you want
.AddMeter("*") // or subscribe to all meters
// see https://docs.microsoft.com/en-us/dotnet/core/diagnostics/available-counters for more
//.AddMeter("System.Runtime")
.SetResourceBuilder(
ResourceBuilder
.CreateDefault()
.AddEnvironmentVariableDetector()
.AddService(serviceName: "myservice", serviceVersion: "1.0.0")
)
// copy your project DSN here or use UPTRACE_DSN env var
.AddUptrace()
.Build();
See the metrics example to try OpenTelemetry and Uptrace.
To collect telemetry about runtime behavior, install OpenTelemetry.Instrumentation.Runtime:
dotnet add package OpenTelemetry.Instrumentation.Runtime
And enable the instrumentation:
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddRuntimeMetrics()
.Build();