epok
View as Markdown

Trace a .NET app

The official OpenTelemetry .NET auto-instrumentation instruments ASP.NET Core, HttpClient, SQL and gRPC without code changes. Epok accepts OTLP over HTTP, so keep the HTTP exporter; there is no gRPC endpoint.

Time to first span: about 5 min. API key: app.epok.cloud, then Settings, then API Keys.

1. Set the OTLP endpoint and key

Set these in the environment that starts your app. Use the base URL; the exporter appends /v1/traces. The header name must be x-api-key.

bash
export OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.epok.cloud"
export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"   # not gRPC
export OTEL_EXPORTER_OTLP_HEADERS="x-api-key=YOUR_API_KEY"
export OTEL_EXPORTER_OTLP_COMPRESSION="gzip"
export OTEL_SERVICE_NAME="checkout-service"          # becomes service.name

2. Install the auto-instrumentation

Run the official install script, then load its environment file in the shell that starts the app. The file sets the profiler and startup hooks.

bash
# Linux and macOS. For Windows, use otel-dotnet-auto-install.ps1
# and instrument.ps1 from the same release.
curl -sSfL -o otel-dotnet-auto-install.sh \
  https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases/latest/download/otel-dotnet-auto-install.sh
sh ./otel-dotnet-auto-install.sh

# Load the auto-instrumentation into the current shell, then run the app.
. $HOME/.otel-dotnet-auto/instrument.sh
dotnet run

3. Set service.name

OTEL_SERVICE_NAME becomes the service.name resource attribute. Use one stable name per service. This is the name you filter by in Epok.

4. Verify traces in Epok

  1. Send a request through your app.
  2. Open Traces in the app and filter by service name checkout-service.
  3. A span tree appears within a few seconds. The service summary fills in after a few minutes of traffic.

Logs

The auto-instrumentation can also export ILogger records over the same OTLP endpoint. This is on by default (OTEL_DOTNET_AUTO_LOGS_ENABLED=true), but upstream marks it experimental, and it needs Microsoft.Extensions.Logging 8.0 or later on .NET (not .NET Framework). For the stable path, set OTEL_DOTNET_AUTO_LOGS_ENABLED=false and add the logging bridge where you build the host:

csharp
// Program.cs, after the builder is created.
// Packages: OpenTelemetry.Extensions.Hosting,
//           OpenTelemetry.Exporter.OpenTelemetryProtocol
using OpenTelemetry.Logs;

builder.Logging.AddOpenTelemetry(logging =>
{
    logging.IncludeFormattedMessage = true;
    logging.IncludeScopes = true;
    logging.AddOtlpExporter(); // reads OTEL_EXPORTER_OTLP_* from the environment
});

Troubleshooting

  1. No spans arrive. The auto-instrumentation environment was not loaded in the shell that starts the app, or the exporter is using gRPC. Source instrument.sh and set OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf.
  2. Spans show as unknown_service. OTEL_SERVICE_NAME did not reach the process. Set it in the same environment that starts the app.
  3. 401 or 403. 401 means no key was found; check the header is exactly x-api-key in OTEL_EXPORTER_OTLP_HEADERS. 403 means the key was read and rejected; check its scope and whether it was rotated.

Next