Open JerryNixon opened 1 month ago
Hi @JerryNixon, regarding the configuration topics, I think we could try something like:
{
"runtime": {
...
"telemetry": {
"otel": {
"enabled": true,
"endpoint": "@env('OTEL_EXPORTER_OTLP_ENDPOINT')"
}
},
...
}
}
Doing it this way, the OTEL config can live alongside the already existing one for appinsights, and we could handle both config at code level as .NET Aspire does.
What is it?
Use OpenTelemetry to add tracing events and top-level counters for exporting to monitors and the health endpoint.
Value prop
Besides aligning with industry trends, CorrelationId (TraceId) is crucial for cross-service traceability in OpenTelemetry. It links spans across multiple services, providing a full view of a request’s lifecycle in distributed systems.
Versus logging
This does not mean Serilog is unnecessary. Serilog handles logging, while OpenTelemetry focuses on tracing and metrics. Both are useful and often work together.
OpenTelemetry
OpenTelemetry is the standard for shipping metrics and events in Azure.
Learn more
OpenTelemetry can work alongside
ILogger
for logging, but metrics and traces are handled separately. OpenTelemetry is designed for distributed tracing and metrics collection, whileILogger
focuses on logging.Concepts
Here’s a table of the common types of metrics in OpenTelemetry: | Counter | A single value| | Histogram | A distribution of values | Event | A point-in-time log or action recorded within a span. | | Activity (Span) | A time-bound operation with a start and end, with zero or more events. | | Trace | A collection of spans representing a full operation lifecycle across services. | | TraceId | A CorrelationId automatically incorporated by middleware or generated. | | Propagator | Injects and extracts TraceId, typically via headers. | | Exporter | Sends telemetry data to systems (e.g., Prometheus, Jaeger, Zipkin). | | Sampler | Decides which traces to capture and whether to record/export them. | | AlwaysOnSampler | Records all traces. | | AlwaysOffSampler | Discards all traces. | | ParentBasedSampler | Uses the sampling decision of the parent span. | | TraceIdRatioBasedSampler | Samples a percentage of traces based on a ratio. | | Resource | Metadata describing the entity producing telemetry data (e.g., service name). |
Code Sample
View the code sample here
Relevant NuGet packages
OpenTelemetry is ASP.NET middleware:
Metrics & Traces to Add to Data API builder
Per API request: Captures metrics or traces for each individual API request, giving a detailed view of specific executions (e.g., database query times for each call).
Per endpoint: Aggregates metrics or traces based on the API endpoint (e.g.,
/api1
,/api2
), providing overall performance stats for specific API routes.Per cache event: Tracks when cache hits or misses occur, logging each event as it happens.
Global: Applies to the entire application or service (e.g., API startup events), capturing broad, system-wide metrics or events.
Discussion
/metrics
?