Skip to content

.NET

Run this in your project directory:

Terminal window
dotnet add package OpenTelemetry.Extensions.Hosting
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
dotnet add package OpenTelemetry.Instrumentation.AspNetCore

Add this to Program.cs, before builder.Build():

builder.Services.AddOpenTelemetry()
.WithTracing(tracing => tracing.AddAspNetCoreInstrumentation())
.WithMetrics(metrics => metrics.AddAspNetCoreInstrumentation().AddMeter("checkout"))
.WithLogging()
.UseOtlpExporter();

Then set these where your app runs. Replace YOUR_INGEST_KEY with your key and checkout with your service name.

Terminal window
export OTEL_SERVICE_NAME=checkout
export OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=production
export OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.siteqwality.com
export OTEL_EXPORTER_OTLP_HEADERS=Authorization=YOUR_INGEST_KEY
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf

Start it as usual, for example with dotnet run. Requests to your app are now traced automatically.

Keep using ILogger. Its records arrive as logs, linked to the trace of the request that wrote them:

logger.LogInformation("order placed, orderId={OrderId}", 42);
var orders = new Meter("checkout").CreateCounter<long>("orders.placed");
orders.Add(1);

Meters are sent when their name is added with AddMeter, as checkout is in step 2.

Open Logs, Traces or Metrics. New data usually shows up within a minute, and a page that says it is waiting for data switches to your data on its own.

The code on this page comes from a runnable example that is checked against our ingest rules every month.

Nothing arriving? Check that the key is an ingest key for this account, that your account has early access, and the status codes in Ingest routes and limits.