📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What is the OpenTelemetry Collector? Explain receivers, processors, exporters and pipelines, agent versus gateway deployment, and why you would put a Collector between your .NET services and Application Insights or another vendor instead of exporting directly.

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.

Mid-Level Theory Intermediate application-insights cloud-native observability opentelemetry opentelemetry-collector otlp

🎯 Key points

  • Collector = vendor-neutral process that receives, processes and exports traces, metrics and logs
  • Pipelines per signal: receivers (otlp, prometheus) -> processors -> exporters (azuremonitor, otlp, prometheus)
  • Processor order matters: memory_limiter first, then attributes/filter/redaction, batch last
  • Agent (sidecar or DaemonSet, near the app) vs gateway (central, scaled deployment); choose by scale: direct export, agent only, or agent + gateway
  • Reasons: switch or dual-ship vendors by config, redact PII centrally, tail sampling, buffer and retry, reduce app SDK config
  • Tail sampling needs all spans of a trace on one instance: load-balancing exporter keyed by trace id
  • Distributions: core (minimal), contrib (includes the azuremonitor exporter and tail_sampling), custom builds with the Collector Builder (OCB) to include only needed components
  • Cost: another tier to scale and monitor, like every part of the telemetry pipeline; direct export with the Azure Monitor distro is fine for small estates

⏱ 30-second answer

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.

  • Processors handle memory limiting, batching, redaction of PII, filtering and tail sampling.
  • Exporters ship to Application Insights (azuremonitor), Prometheus, Grafana, or several at once.
  • Run it as an agent next to the app, a central gateway, or both.

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.

🗣 Full answer (senior)

How I would answer this in an interview

"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_ENDPOINT at a collector. Inside the collector I define pipelines: an otlp receiver, then processors, then one or more exporters. The processors are where the value is. memory_limiter stops it falling over under a burst, attributes or transform strips things like email addresses or tokens before data leaves our network, filter drops health-check spans, tail_sampling keeps every error and slow trace but only a few per cent of the healthy ones, and batch groups 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 contrib azuremonitor exporter 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."


Components

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 export or collector?

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

Production example

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.

🔍 What the interviewer is checking

Checks whether the candidate knows how the Collector works and when the extra tier is worth it over direct export.

Green flags

  • Names receivers, processors, exporters and per-signal pipelines
  • Knows processor ordering (memory_limiter first, batch last)
  • Explains agent versus gateway and the trace-id routing needed for tail sampling
  • Mentions central PII redaction and vendor decoupling, and the cost of operating it

Red flags

  • Thinks the Collector is a storage backend or UI
  • Has never heard of tail sampling or assumes it works on any replica
  • No plan for monitoring the collector itself

📚 Learn in depth

1. Pipeline anatomy

          +------------------------- 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.

2. Agent and gateway

node 1: [app] -> [agent DaemonSet: k8sattributes, loadbalancing exporter by traceID] --\
node 2: [app] -> [agent DaemonSet] ------------------------------------------------------> [gateway x3: tail_sampling, transform, batch] -> vendors
  • Agent: close to the app, cheap hop, adds host and pod metadata, offloads batching and retry from the app.
  • Gateway: central policy (sampling, redaction, routing), holds vendor credentials so apps never do, scales horizontally.

3. Tail sampling

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.

4. Distributions

  • Core (otelcol): a minimal set of components.
  • Contrib (otelcol-contrib): hundreds of components, including azuremonitor and tail_sampling.
  • Custom builds with the OpenTelemetry Collector Builder (OCB) include only what you use, which shrinks the attack surface. Vendors also ship their own distributions.

5. Reliability of the collector

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.

6. The .NET side

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.

Try it yourself

  1. Run otelcol-contrib in Docker with an OTLP receiver and debug exporter, point a .NET API at it and read the spans in its output.
  2. Add a filter processor that drops /health spans and confirm they disappear.
  3. Add a transform processor that deletes url.query and check the exported data.
  4. Configure tail_sampling to keep errors and 10% of the rest; generate traffic with 5% failures and compare counts.
  5. Kill the backend and watch the collector's queue size and retry metrics.

💻 Code

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] }

⚠ Common mistakes

  • Mistake: Hard-coding a vendor exporter and sampling rules in every service. Why it is wrong: Changing vendor or policy means a change and redeploy in every repo. Instead: Export OTLP from apps and keep vendor and policy in the collector.
  • Mistake: Leaving out 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.
  • Mistake: Running tail sampling on several replicas without trace-id routing. Why it is wrong: Spans of one trace land on different instances, so decisions are made on partial traces. Instead: Use the loadbalancing exporter in an agent tier keyed by trace id.
  • Mistake: Deriving request-rate and error metrics from sampled traces. Why it is wrong: The numbers are biased by the sampling rate. Instead: Use SDK metrics or the spanmetrics connector before sampling.
  • Mistake: Not monitoring the telemetry pipeline itself: the collector, its queues and the backend's ingestion. Why it is wrong: When any part of it drops data silently you lose visibility exactly during incidents. Instead: Scrape the collector's internal metrics, alert on refused, dropped and failed-to-send counts and queue saturation, and watch backend ingestion and throttling (for example Log Analytics daily cap and ingestion latency) from a separate path.
  • Mistake: Expecting the 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.
  • Mistake: Running the full contrib image in production with every component enabled. Why it is wrong: Larger attack surface and image for components you do not use. Instead: Build a custom distribution with OCB that includes only the receivers, processors and exporters you configure.
  • Mistake: Assuming the collector removes PII by default. Why it is wrong: It forwards whatever it receives. Instead: Write explicit redaction rules and test them, especially for Privacy Act obligations.

🏛 Senior insight: trade-offs

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.

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions tail sampling in the collector Why: Checks they understand head versus tail sampling and the cost trade-off.
    How to answer

    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.

  2. When: Candidate mentions filtering or dropping attributes Why: Checks they can find and fix a metric cardinality explosion, often done in the collector.
    How to answer

    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.

  3. When: Candidate mentions exporting to several vendors Why: Checks they can compare tracing backends behind the collector.
    How to answer

    All of them store and show traces; they differ in who runs them and how they price and store data.

    • Application Insights: managed by Azure, correlates traces with logs, exceptions and metrics, gives you Application Map and KQL. You pay per GB ingested and retained.
    • Jaeger v2: open source, built on the OpenTelemetry Collector, ingests OTLP natively; you run it and its storage (Elasticsearch/OpenSearch or Cassandra).
    • Grafana Tempo: stores traces in object storage, so it's cheap at high volume, and pairs with Prometheus and Loki.
    • Zipkin: older and simpler; OpenTelemetry has deprecated its Zipkin exporter, so send OTLP instead.

    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.

🛠 Real-world problems: how you handle them

Telemetry bill tripled and PII found in spans
Situation
[30] .NET services on AKS exported directly to Application Insights with 100% sampling; a new feature added customer emails as span attributes, and monthly ingestion cost jumped from [A$4,000] to [A$12,000].
Signals
Azure Cost Management showed Log Analytics ingestion spiking; a data review found `user.email` in the `dependencies` and `requests` tables; healthy-request traces were [95%] of volume.
Investigation
Queried ingestion by table and by `cloud_RoleName` in Log Analytics to find the top contributors; inspected sample spans to find the attribute; reviewed each service's OpenTelemetry setup and found [five] different exporter and sampling configurations.
Resolution
Immediate: set a daily cap and a fixed-rate sampling override on the noisiest services, and purged the affected data per the privacy team's process. Real fix: deployed an agent DaemonSet plus a three-replica gateway with `transform` redaction, health-check filtering and tail sampling, and switched services to plain OTLP.
Prevention
A collector config test in CI that sends a span with known PII and asserts it is removed, alerts on collector dropped spans and ingestion per day, and a service template that only exports OTLP.

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.

↩ Usually asked after

More in Optional Advanced Tools

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me