Setup and Installation

Get up and running with OpenTelemetry in just a few quick steps! The setup process consists of two phases--getting OpenTelemetry installed and configured, and then validating that configuration to ensure that data is being sent as expected.

OpenTelemetry automatically captures telemetry from your application's libraries, frameworks, and environment. This guide explains how to install, configure, and validate your OpenTelemetry setup.

Requirements

  • .NET Framework 4.6+ and .NET Standard 2.0.
  • A service to add OpenTelemetry to. You can use this example application or bring your own.
  • A Lightstep account, or another OpenTelemetry backend.

Need an account? Create a free Lightstep account here.

Installation

To get started with OpenTelemetry, you need to install both the API and SDK packages. These can either be installed using an IDE or by command line like below:

dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol -v 0.4.0-beta.2

Run OpenTelemetry

To set up OpenTelemetry in your application, you need to create a TracerProvider. The example below creates a TracerProvider configured via environment variables.

Your Access Token can be found in your project settings page.

ENV VARS

  • LSACCESSTOKEN is required when connecting to Lightstep. .
  • LSSERVICENAME the name of your service as it will appear in Lightstep.
  • LSSERVICEVERSION is not required but very much recommended.
 using var otel = Sdk.CreateTracerProvider(b => b
                .AddActivitySource("MyCompany.MyProduct.MyLibrary")
                .UseOtlpExporter(opt =>
                {
                    opt.Endpoint = "ingest.lightstep.com:443"
                    opt.Headers = new Metadata
                    {
                        { "lightstep-access-token", Environment.GetEnvironmentVariable("LS_ACCESS_TOKEN")}
                    };
                    opt.Credentials = new SslCredentials();
                })
                .SetResource(Resources.CreateServiceResource(Environment.GetEnvironmentVariable("LS_SERVICE_NAME"), serviceVersion: Environment.GetEnvironmentVariable("LS_SERVICE_VERSION"))));

Auto-Instrumentation

The following libraries are currently supported by OpenTelemetry. Visit the READMEs for installation instructions.

Validate Installation by Checking for Traces

With your application running, you can now verify that you’ve installed OpenTelemetry correctly by confirming that telemetry data is being reported to your observability backend.

To do this, you need to make sure that your application is actually generating data. Applications will generally not produce traces unless they are being interacted with, and opentelemetry will often buffer data before sending it. So it may take some amount of time and interaction before your application data begins to appear in your backend.

Validate your traces in Lightstep:

  1. Trigger an action in your app that generates a web request.
  2. In Lightstep, click on the Explorer in the sidebar.
  3. Refresh your query until you see traces.
  4. View the traces and verify that important aspects of your application are captured by the trace data.