Observability and Distributed Tracing: A Complete Guide
What is Observability?
Observability – this is the ability of a system to provide information about its internal state based on external outputs. It’s built upon three pillars: metrics, logs, and traces.
Tracing with OpenTelemetry
The code demonstrates basic tracing using the OpenTelemetry library. This allows you to track requests as they flow through your service.
`const { trace } = require('@opentelemetry/api');` initializes the tracing API, and `trace.getTracer('my-service')` creates a tracer for your application.
Exporting Traces with Zipkin
The code uses the Zipkin exporter to send traces to a Zipkin service, typically running on `http://localhost:9411/api/v2/spans`. This allows you to visualize and analyze your distributed requests.
`const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');` imports the exporter, and the code creates a new instance configured to send traces to the specified URL.
Sampling Strategies
To avoid overwhelming systems with trace data, sampling is used. This technique selects a subset of requests to trace fully.
Adaptive sampling dynamically adjusts the sampling rate based on system load, ensuring that critical traces are always captured while minimizing overhead during low-load periods.
Frequently asked questions
What is adaptive sampling?
Adaptive sampling dynamically adjusts the sampling rate based on system load, ensuring that critical traces are always captured while minimizing overhead during low-load periods.
What is TraceIdRatioBasedSampler?
TraceIdRatioBasedSampler is a sampling strategy within OpenTelemetry that adjusts the sampling rate based on the ratio of active trace IDs, providing intelligent control over trace data collection.
What does `const sampler = new TraceIdRatioBasedSampler(0.1);` do?
This line creates a TraceIdRatioBasedSampler instance with a sampling rate of 10%. This means that 10% of all trace IDs will be fully sampled, while the remaining 90% will be discarded.
What is `const sdk = new NodeSDK({`?
This line creates a new NodeSDK instance, which is the core of the OpenTelemetry SDK. The configuration object within the brackets allows you to customize various aspects of the SDK's behavior.
▶ Try it live
Everything above runs in your browser — open Hash Function Avalanche Visualizer and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.