OpenTelemetry .NET instrumentation
OpenTelemetry is the supported way to send traces, metrics, and logs from a .NET application to Osuite. There are two paths, and you pick one per service.
Two ways to instrument .NET
Section titled “Two ways to instrument .NET”- SDK in code — add the OpenTelemetry packages and configure them in
Program.cs. You control which instrumentations load, and you can create custom spans and metrics. This is the recommended path for services you build and deploy yourself. - Zero-code automatic instrumentation — the
OpenTelemetry.AutoInstrumentationdistribution attaches to your process through the CLR profiler and instruments supported libraries without any code change. Use it when you cannot modify the application or want a fast path across many services.
Both paths export over OTLP to the same Osuite ingest endpoint and are configured with the same environment variables.
| SDK in code | Zero-code automatic | |
|---|---|---|
| Code changes | Required (Program.cs) | None |
| Custom spans and metrics | Yes | No (add the SDK to extend) |
| Attaches via | Package references | CLR profiler |
| Best for | Services you own | Existing or third-party apps |
Choose your path
Section titled “Choose your path”Zero-code automatic instrumentation
Section titled “Zero-code automatic instrumentation”Follow these steps to instrument a .NET service without changing its code. The installer downloads the automatic instrumentation, and the environment variables point it at Osuite.
-
Download and install the automatic instrumentation.
Terminal window curl -L -O https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases/latest/download/otel-dotnet-auto-install.shsh ./otel-dotnet-auto-install.shFROM mcr.microsoft.com/dotnet/aspnet:8.0RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*RUN curl -L -O https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases/latest/download/otel-dotnet-auto-install.sh \&& sh ./otel-dotnet-auto-install.shCOPY bin/Release/net8.0/publish/ /app/WORKDIR /appENTRYPOINT ["sh", "-c", ". /root/.otel-dotnet-auto/instrument.sh && dotnet MyApp.dll"]Install the automatic instrumentation in the image (see the Docker tab), then set the environment variables on the container.
apiVersion: apps/v1kind: Deploymentmetadata:name: my-servicespec:replicas: 1selector:matchLabels:app: my-servicetemplate:metadata:labels:app: my-servicespec:containers:- name: my-serviceimage: registry.example.com/my-service:latestenv:- name: OTEL_EXPORTER_OTLP_ENDPOINTvalue: "https://ingest.<region>.osuite.io:443"- name: OTEL_EXPORTER_OTLP_HEADERSvalueFrom:secretKeyRef:name: osuite-ingestkey: otlp-headers- name: OTEL_SERVICE_NAMEvalue: "my-service"- name: OTEL_RESOURCE_ATTRIBUTESvalue: "service.environment=production"Create the secret once, holding the full header string:
Terminal window kubectl create secret generic osuite-ingest \--from-literal=otlp-headers='x-osuite-ingest-token=<your-ingest-token>' -
Set the Osuite environment variables. The automatic instrumentation exports over OTLP by default, so only the endpoint, token, and resource attributes are required.
Terminal window export OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.<region>.osuite.io:443export OTEL_EXPORTER_OTLP_HEADERS=x-osuite-ingest-token=<your-ingest-token>export OTEL_SERVICE_NAME=my-serviceexport OTEL_RESOURCE_ATTRIBUTES=service.environment=productionTerminal window docker run \-e OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.<region>.osuite.io:443 \-e OTEL_EXPORTER_OTLP_HEADERS=x-osuite-ingest-token=<your-ingest-token> \-e OTEL_SERVICE_NAME=my-service \-e OTEL_RESOURCE_ATTRIBUTES=service.environment=production \registry.example.com/my-service:latestThe environment variables are set on the container in the previous step.
-
Load the instrumentation into the current shell and run the application. On a bare host, source
instrument.shbefore starting the process; the Docker and Kubernetes tabs do this in the container entrypoint.Terminal window . $HOME/.otel-dotnet-auto/instrument.shdotnet run
The service appears in APM within a minute of receiving traffic. If nothing arrives, see Troubleshooting.