dotnet add package OpenTelemetry
OpenTelemetry SDK is a reference implementation of the OpenTelemetry API. It implements the Tracing API, the Metrics API, and the Context API. OpenTelemetry SDK deals with concerns such as sampling, processing pipeline, exporting telemetry to a particular backend etc. The default implementation consists of the following.
- Set of Built-in samplers
- Set of Built-in
processors.
- SimpleProcessor which sends Activities to the exporter without any batching.
- BatchingProcessor which batches and sends Activities to the exporter.
- Extensibility options for users to customize SDK.
Please follow the tutorial and get started in 5 minutes.
Samplers are used to control the noise and overhead introduced by OpenTelemetry by reducing the number of samples of traces collected and sent to the backend. If no sampler is explicitly specified, the default is to use AlwaysOnSampler. The following example shows how to change it to TraceIdRatioBasedSampler with sampling probability of 25%.
using OpenTelemetry;
using OpenTelemetry.Trace;
using var otel = Sdk.CreateTracerProvider(b => b
.AddActivitySource("MyCompany.MyProduct.MyLibrary")
.SetSampler(new TraceIdRatioBasedSampler(0.25))
.UseConsoleExporter());
- Logs
- Metrics
- Trace