OpenTelemetry
OpenTelemetry
An observability standard framework. Unifies traces, metrics, and logs.
OpenTelemetry
An observability standard framework. Unifies traces, metrics, and logs.
OpenTelemetry (OTel) is an open-source standard framework for collecting, processing, and exporting observability data (traces, metrics, logs) from distributed systems. As a project of the CNCF (Cloud Native Computing Foundation), it is the most active project after Kubernetes. Being vendor-neutral, it is not tied to any particular observability tool.
OpenTelemetry was created by the merger of OpenTracing and OpenCensus. It combines the strengths of the two projects to provide a single standard. It consists of the API (interface definition), the SDK (implementation), the Collector (data collection/processing/export), and OTLP (OpenTelemetry Protocol).
Integrating the OpenTelemetry SDK into an application generates traces, metrics, and logs. With auto-instrumentation, common operations such as HTTP requests and database queries can be traced without modifying code. With manual instrumentation, you add custom spans and metrics that fit your business logic.
The OpenTelemetry Collector is deployed as an agent or a gateway to receive, process (filtering, transformation, sampling), and export data. A single Collector can send data simultaneously to multiple backends such as Jaeger, Prometheus, and Datadog. It provides the flexibility to swap backends without changing application code.
// tracing.js - Node.js OpenTelemetry SDK ์ค์
const { NodeSDK } = require('@opentelemetry/sdk-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-grpc');
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-grpc');
const { PeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics');
const { Resource } = require('@opentelemetry/resources');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const sdk = new NodeSDK({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'order-api',
[SemanticResourceAttributes.SERVICE_VERSION]: '2.1.0',
[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: process.env.NODE_ENV
}),
// ํธ๋ ์ด์ค ๋ด๋ณด๋ด๊ธฐ
traceExporter: new OTLPTraceExporter({
url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://otel-collector:4317'
}),
// ๋ฉํธ๋ฆญ ๋ด๋ณด๋ด๊ธฐ
metricReader: new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter(),
exportIntervalMillis: 30000
}),
// ์๋ ๊ณ์ธก (Express, HTTP, DB ๋ฑ)
instrumentations: [
getNodeAutoInstrumentations({
'@opentelemetry/instrumentation-fs': { enabled: false }, // ํ์ผ์์คํ
์ ์ธ
'@opentelemetry/instrumentation-http': {
ignoreIncomingPaths: ['/health', '/metrics']
}
})
]
});
sdk.start();
process.on('SIGTERM', () => sdk.shutdown());
# otel-collector-config.yaml
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
batch:
timeout: 1s
send_batch_size: 1024
memory_limiter:
check_interval: 1s
limit_mib: 4000
spike_limit_mib: 500
# ์ํ๋ง (10%๋ง ์์ง)
probabilistic_sampler:
sampling_percentage: 10
# ๋ฏผ๊ฐ ์ ๋ณด ์ ๊ฑฐ
attributes:
actions:
- key: http.request.header.authorization
action: delete
exporters:
# ํธ๋ ์ด์ค -> Tempo
otlp/tempo:
endpoint: tempo:4317
tls:
insecure: true
# ๋ฉํธ๋ฆญ -> Prometheus
prometheus:
endpoint: 0.0.0.0:8889
# ๋ก๊ทธ -> Loki
loki:
endpoint: http://loki:3100/loki/api/v1/push
service:
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, batch, probabilistic_sampler]
exporters: [otlp/tempo]
metrics:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [prometheus]
logs:
receivers: [otlp]
processors: [memory_limiter, batch, attributes]
exporters: [loki]
SRE: "Our Datadog costs are too high. How about switching to our own Observability stack?"
Developer: "Wouldn't that mean we have to modify all of our code?"
Senior: "If we're using OpenTelemetry, we only need to change the Collector configuration. We leave the code as it is and just switch the exporter to Tempo, Prometheus, and Loki. Having no vendor lock-in is the advantage of OTel."
Interviewer: "Do you have experience adopting OpenTelemetry?"
Candidate: "Yes, I integrated the OTel SDK into Python and Node.js services. With auto-instrumentation, I traced HTTP, PostgreSQL, and Redis calls without modifying code, and I manually added custom spans to the business logic. I deployed the Collector as a sidecar and had it handle sampling and data cleansing. Even when the backend changed, I didn't touch the code, so maintenance was easy."
Take a mock interview on this topic โ WIA SOOM AI Interview ยท Start for free
Reviewer: "You need to propagate the span in this asynchronous task as well. Wrap it with context.with(span.context()), otherwise the trace will break."
Author: "Ah, so that's why the tasks inside Promise.all were showing up as separate traces. I'll add context propagation."