Covers the OpenTelemetry Collector: OTLP receivers, processors (memory_limiter, batch, attributes, filter, tail_sampling), exporters (Azure Monitor, Prometheus, OTLP), pipelines per signal, core versus contrib distributions, agent and gateway patterns, and the trade-off against direct export from the .NET SDK or the Azure Monitor distro.
The OpenTelemetry Collector is a vendor-neutral process that sits between your services and your backends. Apps send OTLP to it; it runs pipelines per signal (traces, metrics, logs) made of receivers, processors and exporters.
azuremonitor), Prometheus, Grafana, or several at once.The point is decoupling: the .NET service only knows "send OTLP to the collector", so changing vendor, adding a second one or tightening sampling is configuration, not a redeploy of every service. The trade-off is one more component to scale, secure and monitor; with three services exporting straight to Azure Monitor you may not need it.
"The Collector is the OpenTelemetry project's own telemetry pipeline. My .NET service uses the OpenTelemetry SDK with the OTLP exporter and points
OTEL_EXPORTER_OTLP_ENDPOINTat a collector. Inside the collector I define pipelines: anotlpreceiver, then processors, then one or more exporters. The processors are where the value is.memory_limiterstops it falling over under a burst,attributesortransformstrips things like email addresses or tokens before data leaves our network,filterdrops health-check spans,tail_samplingkeeps every error and slow trace but only a few per cent of the healthy ones, andbatchgroups data for efficient export.I deploy it as an agent, a DaemonSet or sidecar near the app that adds Kubernetes metadata with
k8sattributes, plus a gateway tier that does sampling and exporting. Because tail sampling needs every span of a trace on the same instance, the agents use the load-balancing exporter keyed by trace id. On Azure, the gateway exports to Application Insights with the contribazuremonitorexporter and to Prometheus or Grafana if another team wants it. Aspire's dashboard itself is just an OTLP endpoint, so the same app config works locally.The mistake I see is every service hard-coding a vendor exporter and its own sampling rules, so changing anything is twenty pull requests, and nobody can guarantee PII is scrubbed. The opposite mistake is putting a single collector replica in the path with no memory limit and no monitoring of the collector itself, so when it falls over you lose all telemetry exactly during the incident. The collector moves policy to one place, and that place then needs to be treated as production infrastructure."
| Part | Examples | Job |
|---|---|---|
| Receiver | otlp (gRPC 4317, HTTP 4318), prometheus, filelog, hostmetrics |
Get data in (push or pull) |
| Processor | memory_limiter, batch, attributes, transform, filter, k8sattributes, tail_sampling |
Shape, enrich, protect, reduce |
| Exporter | azuremonitor, otlp/otlphttp, prometheusremotewrite, loadbalancing, debug |
Send data out |
| Extension | health_check, pprof, zpages |
Operate the collector itself |
| Connector | spanmetrics, routing |
Join pipelines (e.g. derive RED metrics from spans) |
| Direct from the app (Azure Monitor distro / OTLP to vendor) | Through a collector | |
|---|---|---|
| Moving parts | Fewest | One more tier to run |
| Changing vendor | Code or config change in every service | One config change |
| PII redaction | Per service | Central, enforceable |
| Sampling | Head-based in each SDK | Head plus tail-based |
| Buffering when vendor is down | SDK in-memory only | Queues, retries, optional persistent storage |
| Best for | Few services, one backend | Many services, several backends, compliance needs |
Moving [30] services from direct Application Insights export to a collector gateway with tail sampling (all errors, all traces over [1 s], [5%] of the rest) cut ingestion from [180 GB] to [40 GB] a day while keeping every failed request. A transform processor removed user.email and query strings before export, which closed a [Privacy Act] audit finding.
Checks whether the candidate knows how the Collector works and when the extra tier is worth it over direct export.
Green flags
Red flags
+------------------------- collector -------------------------+
apps ---> | receivers processors (in order) exporters |
OTLP | otlp ---> memory_limiter -> k8sattributes -> transform -> |--> azuremonitor
| filter -> batch |--> prometheusremotewrite
| prometheus (scrape) -------------------------------------> |--> debug (dev only)
+-------------------------------------------------------------+
Each signal has its own pipeline (traces, metrics, logs), and a receiver or exporter can be shared by several pipelines. Processors run in the order listed, so put memory_limiter first (it refuses data before the process runs out of memory) and batch near the end.
node 1: [app] -> [agent DaemonSet: k8sattributes, loadbalancing exporter by traceID] --\
node 2: [app] -> [agent DaemonSet] ------------------------------------------------------> [gateway x3: tail_sampling, transform, batch] -> vendors
Head sampling decides at the first span, before you know if the request failed. Tail sampling waits (for example decision_wait: 10s) until a trace is complete, then applies policies such as status_code: ERROR, latency > 1000ms and probabilistic 5%. It needs all spans of a trace on one collector instance and holds traces in memory, so size it from span rate x wait time. Metrics derived from sampled spans are biased; compute RED metrics with spanmetrics before sampling or use SDK metrics.
otelcol): a minimal set of components.otelcol-contrib): hundreds of components, including azuremonitor and tail_sampling.Exporters have a sending queue and retry with back-off; enable file_storage for a persistent queue if losing a few minutes of data on restart matters. Monitor the collector's own metrics (accepted, refused, dropped and failed-to-send spans, queue size) and alert on drops. Run at least two gateway replicas behind a Service.
The SDK uses AddOtlpExporter() and honours OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES. Aspire service defaults call UseOtlpExporter() when the endpoint variable is set, so the same code sends to the Aspire dashboard locally and to a collector in the cluster.
otelcol-contrib in Docker with an OTLP receiver and debug exporter, point a .NET API at it and read the spans in its output.filter processor that drops /health spans and confirm they disappear.transform processor that deletes url.query and check the exported data.tail_sampling to keep errors and 10% of the rest; generate traffic with 5% failures and compare counts.A .NET 10 service that only knows about OTLP, and a collector gateway config that redacts, samples and exports to Application Insights.
// Program.cs: vendor-neutral telemetry; the endpoint comes from OTEL_EXPORTER_OTLP_ENDPOINT.
using OpenTelemetry.Resources;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenTelemetry()
.ConfigureResource(r => r.AddService("orders-api"))
.WithTracing(t => t
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation())
.WithMetrics(m => m
.AddAspNetCoreInstrumentation()
.AddRuntimeInstrumentation())
.UseOtlpExporter(); // one exporter for traces, metrics and logs; no vendor SDK in the app
builder.Logging.AddOpenTelemetry(o => o.IncludeScopes = true);
var app = builder.Build();
app.MapGet("/orders/{id:guid}", (Guid id) => Results.Ok(new { id }));
app.Run();
# collector-gateway.yaml (otelcol-contrib)
receivers:
otlp:
protocols: { grpc: { endpoint: 0.0.0.0:4317 }, http: { endpoint: 0.0.0.0:4318 } }
processors:
memory_limiter: { check_interval: 1s, limit_percentage: 80, spike_limit_percentage: 20 }
transform/redact:
trace_statements:
- context: span
statements:
- delete_key(attributes, "user.email")
- delete_key(attributes, "url.query")
filter/health:
traces:
span: [ 'attributes["url.path"] == "/health"' ]
tail_sampling:
decision_wait: 10s
policies:
- { name: errors, type: status_code, status_code: { status_codes: [ERROR] } }
- { name: slow, type: latency, latency: { threshold_ms: 1000 } }
- { name: rest, type: probabilistic, probabilistic: { sampling_percentage: 5 } }
batch: {}
exporters:
azuremonitor:
connection_string: ${env:APPLICATIONINSIGHTS_CONNECTION_STRING}
service:
pipelines:
traces: { receivers: [otlp], processors: [memory_limiter, filter/health, transform/redact, tail_sampling, batch], exporters: [azuremonitor] }
metrics: { receivers: [otlp], processors: [memory_limiter, batch], exporters: [azuremonitor] }
logs: { receivers: [otlp], processors: [memory_limiter, batch], exporters: [azuremonitor] }
memory_limiter, or putting it after other processors. Why it is wrong: A traffic spike makes the collector run out of memory and drop everything. Instead: Put memory_limiter first in every pipeline and set container limits to match.loadbalancing exporter in an agent tier keyed by trace id.spanmetrics connector before sampling.azuremonitor exporter in the core image. Why it is wrong: It is a contrib component, so the core otelcol build fails to start with an unknown exporter. Instead: Use otelcol-contrib, a vendor distribution, or a custom OCB build that includes it.The collector turns telemetry policy into infrastructure: what to keep, what to scrub, where to send. That is valuable as soon as more than one team, more than one backend, or a compliance requirement is involved, and it is the cheapest lever on observability cost because tail sampling and filtering happen before you pay for ingestion. But it is also a new tier in the critical path of your incident response, so it needs redundancy, limits and its own alerts.
| Option | When it fits | Cost | When not to |
|---|---|---|---|
| Direct export (Azure Monitor distro) | Few services, Application Insights only | Per-service config, head sampling only | Many teams, several backends |
| Agent only | Want metadata and offloaded retry, simple policy | DaemonSet to run | Need tail sampling across nodes |
| Agent + gateway | Many services, tail sampling, central redaction | Two tiers to scale and monitor | Small estates |
| Vendor distribution | Single vendor with support needs | Some lock-in to their build | You want a minimal custom build |
Measure ingestion volume and cost per day before and after, the share of error traces retained (should be 100%), and collector drop rates.
Head sampling decides at the start of a trace: the root service keeps, say, 10%, and the decision travels in the traceparent sampled flag so every service records the same traces. In .NET that's ParentBasedSampler(new TraceIdRatioBasedSampler(0.1)). It's cheap, but it decides before knowing whether the request will fail.
Tail sampling decides after the trace completes: the OpenTelemetry Collector buffers spans (about 30 s), then keeps all errors, all traces slower than a threshold, and a small random baseline. It needs every span of a trace on the same Collector, so you route by trace id with the loadbalancing exporter, and it costs memory.
Always compute metrics before sampling, so dashboards and alerts stay accurate. The trade-off: head sampling is simple and cheap; tail sampling keeps the interesting traces but adds infrastructure you must run.
Cardinality is the number of unique label combinations; each is a separate time series. A user_id label multiplies a metric's series by the number of active users, and on a histogram that is again multiplied by every bucket, so 20 routes × 5 status codes × 17 buckets × 50,000 users is 85 million series.
I confirm it with prometheus_tsdb_head_series (or the Azure Monitor workspace's active series and ingestion metrics), find the metric with topk(10, count by (__name__) ({__name__=~".+"})), and the label with count(count by (user_id) (...)). I stop the bleeding without a deploy by dropping the label in the OpenTelemetry Collector or with Prometheus labeldrop, then remove the tag in code and move per-user questions to traces and logs.
The trade-off: per-user detail is real value, but metrics are the wrong place for unbounded data.
All of them store and show traces; they differ in who runs them and how they price and store data.
From .NET you instrument once with OpenTelemetry and export OTLP, ideally through a Collector that can batch, sample and fan out. The trade-off: managed backends cost money per GB; self-hosted ones cost engineering time.
How to tell it (STAR)
**S:** Our telemetry bill tripled in a month, and in the same review we found customer emails in our traces. **T:** I owned fixing both without losing the data we needed for incidents. **A:** I traced the volume by table and service, found healthy traces were [95%] of it, and that each service had its own exporter config. I put in a collector gateway with redaction, health-check filtering and tail sampling that keeps every error and slow request, moved services to plain OTLP, and added a CI test that proves PII is stripped. **R:** Ingestion fell by [about 70%], we kept [100%] of error traces, and the privacy finding was closed.
Last updated 23 Nov 2026.