OpenTelemetry Integration for .NET Applications

The main approach for integrating with OpenTelemetry is to configure the default OTLP exporter of any application that is monitored by OpenTelemetry to send its data to the Instana agent. This is described on the OpenTelemetry page.

The OpenTelemetry integration can be further customized with additional components. The available OpenTelemetry components for .NET are described on this page.

Serverless OpenTelemetry Exporter

The NuGet package OpenTelemetry.Exporter.Instana converts OpenTelemetry tracing data to the Instana format and sends it to the Instana back end.

The Instana .NET OpenTelemetry exporter is designed primarily for usage in serverless environments, such as AWS Fargate or Google Run. Instana already provides support for OpenTelemetry for SaaS and self-hosted solutions by using the host agent. However, if your .NET applications run in a serverless environment, where the agent is not present, the OpenTelemetry exporter is the way to go.

To use the exporter, install the package into your project, import it into the tracing module, and create a new instance of InstanaExporter.

The exporter expects two Instana environment variables that must be provided to the application:

  • INSTANA_AGENT_KEY
  • INSTANA_ENDPOINT_URL

For example, you can configure the exporter into the tracing module as follows:

using System.Diagnostics;
using OpenTelemetry;
using OpenTelemetry.Trace;
using OpenTelemetry.Resources;
using System;
using System.Threading;
using System.Data;
using System.Collections.Generic;
using OpenTelemetry.Exporter.Instana;
using System.Threading.Tasks

// Define some important constants and the activity source
var serviceName = "Instana.OpenTelemetryTestApp.TestService";
var serviceVersion = "1.0.0";

    using var tracerProvider = Sdk.CreateTracerProviderBuilder()
        .AddSource(serviceName)
        .SetResourceBuilder(
            ResourceBuilder.CreateDefault()
                .AddService(serviceName: serviceName, serviceVersion: serviceVersion))
        .AddSqlClientInstrumentation()
        .AddConsoleExporter()
        // Add the Instana Exporter.
        // Make sure to provide the agent key and back end endpoint URL environment variables:
        // * INSTANA_AGENT_KEY
        // * INSTANA_ENDPOINT_URL
        .AddInstanaExporter()
        .Build();

...

This is all that's needed. When the application monitored by OpenTelemetry runs, the Instana exporter will convert the OpenTelemetry spans to Instana spans, and send them to the back end endpoint.

The OpenTelemetry trace visualization will be present in Instana, like regular Instana tracing spans.