The OpenTelemetry Collector is a vendor-agnostic proxy that receives, processes, and exports telemetry data (traces, metrics, logs). It eliminates vendor lock-in and provides a unified pipeline for all your observability data.
What Is the OTel Collector?
The OpenTelemetry Collector is a CNCF project component that acts as a central hub for telemetry data. It receives data from your applications, processes it (filtering, sampling, enriching), and exports it to any backend.
Key Features:
- Vendor-agnostic (50+ exporters)
- Traces, metrics, and logs in one pipeline
- Processing: filtering, sampling, batching
- Multiple receivers (OTLP, Jaeger, Prometheus, etc.)
- Tail-based sampling
- Resource detection
- Health check extension
- pprof and zpages debugging
Installation
# Docker
docker run -d -p 4317:4317 -p 4318:4318 \
-v $(pwd)/otel-config.yaml:/etc/otelcol/config.yaml \
otel/opentelemetry-collector-contrib:latest
# Kubernetes via Helm
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
helm install otel-collector open-telemetry/opentelemetry-collector
Collector Configuration
# otel-config.yaml
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
prometheus:
config:
scrape_configs:
- job_name: 'my-app'
scrape_interval: 15s
static_configs:
- targets: ['app:8080']
processors:
batch:
timeout: 5s
send_batch_size: 1000
filter:
metrics:
exclude:
match_type: strict
metric_names:
- go_gc_duration_seconds
attributes:
actions:
- key: environment
value: production
action: upsert
exporters:
otlp:
endpoint: jaeger:4317
tls:
insecure: true
prometheus:
endpoint: 0.0.0.0:8889
logging:
loglevel: info
service:
pipelines:
traces:
receivers: [otlp]
processors: [batch, attributes]
exporters: [otlp, logging]
metrics:
receivers: [otlp, prometheus]
processors: [batch, filter]
exporters: [prometheus, logging]
logs:
receivers: [otlp]
processors: [batch]
exporters: [logging]
Send Data to Collector
from opentelemetry import trace, metrics
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter
# Setup tracing
trace.set_tracer_provider(TracerProvider())
tracer_provider = trace.get_tracer_provider()
tracer_provider.add_span_processor(
BatchSpanProcessor(OTLPSpanExporter(endpoint="http://localhost:4317"))
)
# Setup metrics
metric_reader = PeriodicExportingMetricReader(
OTLPMetricExporter(endpoint="http://localhost:4317"),
export_interval_millis=5000
)
metrics.set_meter_provider(MeterProvider(metric_readers=[metric_reader]))
# Use
tracer = trace.get_tracer("my-service")
meter = metrics.get_meter("my-service")
request_counter = meter.create_counter("http.requests", description="HTTP request count")
with tracer.start_as_current_span("handle-request") as span:
span.set_attribute("http.method", "GET")
span.set_attribute("http.url", "/api/users")
request_counter.add(1, {"method": "GET", "path": "/api/users"})
Collector Health API
# Health check
curl http://localhost:13133/
# zpages for debugging
curl http://localhost:55679/debug/tracez
# pprof profiling
curl http://localhost:1777/debug/pprof/
Resources
- OTel Collector Docs
- Collector GitHub — 4.5K+ stars
- Contrib Repo
Need to scrape web data for your observability pipeline? Check out my web scraping tools on Apify — production-ready actors for Reddit, Google Maps, and more. Questions? Email me at spinov001@gmail.com
Top comments (0)