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.
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.name2. 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.
# 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 run3. 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
- Send a request through your app.
- Open Traces in the app and filter by service name
checkout-service. - 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:
// 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
- 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.shand setOTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf. - Spans show as
unknown_service.OTEL_SERVICE_NAMEdid not reach the process. Set it in the same environment that starts the app. - 401 or 403. 401 means no key was found; check the header is exactly
x-api-keyinOTEL_EXPORTER_OTLP_HEADERS. 403 means the key was read and rejected; check its scope and whether it was rotated.
Next
- Node.js traces: zero-code auto-instrumentation.
- Go traces: the SDK setup in main, with otelhttp for handlers.
- Java traces: one JVM flag for the official agent.
- Authentication: every accepted credential header.