The OTLP (OpenTelemetry Protocol) exporter implementation.
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocolYou can configure the OtlpExporter through Options types properties
and environment variables.
The Options type setters take precedence over the environment variables.
-
BatchExportProcessorOptions: Configuration options for the batch exporter. Only used if ExportProcessorType is set to Batch. -
Endpoint: Target to which the exporter is going to send traces or metrics. The endpoint must be a valid Uri with scheme (http or https) and host, and MAY contain a port and path. -
ExportProcessorType: Whether the exporter should use Batch or Simple exporting processor. -
Headers: Optional headers for the connection. -
HttpClientFactory: A factory function called to create theHttpClientinstance that will be used at runtime to transmit telemetry over HTTP when theHttpProtobufprotocol is configured. See Configure HttpClient for more details. -
TimeoutMilliseconds: Max waiting time for the backend to process a batch. -
Protocol: OTLP transport protocol. Supported values:OtlpExportProtocol.GrpcandOtlpExportProtocol.HttpProtobuf.
See the TestOtlpExporter.cs for
an example of how to use the exporter.
The following environment variables can be used to override the default
values of the OtlpExporterOptions
(following the OpenTelemetry specification).
| Environment variable | OtlpExporterOptions property |
|---|---|
OTEL_EXPORTER_OTLP_ENDPOINT |
Endpoint |
OTEL_EXPORTER_OTLP_HEADERS |
Headers |
OTEL_EXPORTER_OTLP_TIMEOUT |
TimeoutMilliseconds |
OTEL_EXPORTER_OTLP_PROTOCOL |
Protocol (grpc or http/protobuf) |
The following environment variables can be used to override the default
values of the PeriodicExportingMetricReaderOptions
(following the OpenTelemetry specification.
| Environment variable | PeriodicExportingMetricReaderOptions property |
|---|---|
OTEL_METRIC_EXPORT_INTERVAL |
ExportIntervalMilliseconds |
OTEL_METRIC_EXPORT_TIMEOUT |
ExportTimeoutMilliseconds |
The following environment variables can be used to override the default values of the attribute limits (following the OpenTelemetry specification).
OTEL_ATTRIBUTE_VALUE_LENGTH_LIMITOTEL_ATTRIBUTE_COUNT_LIMIT
The following environment variables can be used to override the default values of the span limits (following the OpenTelemetry specification).
OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMITOTEL_SPAN_ATTRIBUTE_COUNT_LIMITOTEL_SPAN_EVENT_COUNT_LIMITOTEL_SPAN_LINK_COUNT_LIMITOTEL_EVENT_ATTRIBUTE_COUNT_LIMITOTEL_LINK_ATTRIBUTE_COUNT_LIMIT
This package currently only supports exporting traces and metrics. Support for
exporting logs is provided by installing the
OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs
package.
Once the OTLP log exporter is stable, it'll be folded into this package. Check this milestone for tracking.
If your application is targeting .NET Core 3.1, and you are using an insecure
(HTTP) endpoint, the following switch must be set before adding OtlpExporter.
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport",
true);See this for more information.
The HttpClientFactory option is provided on OtlpExporterOptions for users
who want to configure the HttpClient used by the OtlpTraceExporter and/or
OtlpMetricExporter when HttpProtobuf protocol is used. Simply replace the
function with your own implementation if you want to customize the generated
HttpClient:
services.AddOpenTelemetry()
.WithTracing(builder => builder
.AddOtlpExporter(o =>
{
o.Protocol = OtlpExportProtocol.HttpProtobuf;
o.HttpClientFactory = () =>
{
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("X-MyCustomHeader", "value");
return client;
};
}));For users using
IHttpClientFactory
you may also customize the named "OtlpTraceExporter" and/or "OtlpMetricExporter"
HttpClient using the built-in AddHttpClient extension:
services.AddHttpClient(
"OtlpTraceExporter",
configureClient: (client) =>
client.DefaultRequestHeaders.Add("X-MyCustomHeader", "value"));Note: The single instance returned by HttpClientFactory is reused by all
export requests.
This component uses an EventSource with the name "OpenTelemetry-Exporter-OpenTelemetryProtocol" for its internal logging. Please refer to SDK troubleshooting for instructions on seeing these internal logs.