Skip to content

Latest commit

 

History

History
112 lines (82 loc) · 3.2 KB

README.md

File metadata and controls

112 lines (82 loc) · 3.2 KB

Uptrace for .NET

Documentation Chat

Introduction

uptrace-dotnet is an OpenTelemery distribution configured to export traces and metrics to Uptrace.

Installation

Install uptrace-dotnet:

dotnet add package Uptrace.OpenTelemetry

Usage Tracer

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.

Usage Meter

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.

Runtime metrics

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();

Links