Tracing helps you see what happens in your app, step by step. But how the events are captured—synchronously or asynchronously—can affect your app’s performance. This guide explains both approaches, so you know when to use each.
Tracing records events in your app, such as API requests or database queries. The difference between synchronous and asynchronous tracing lies in how and when these events are recorded.
Synchronous tracing records events in real-time as they occur. This ensures data is captured immediately but can add processing time, especially under heavy load.
1import { trace } from '@opentelemetry/api';
2const tracer = trace.getTracer('sync-app');
3const span = tracer.startSpan('process-data');
4span.end();
5// Hypothetically export the span immediately (not recommended in production)
6// Exporters usually batch spans for performance.
7// When app is exiting this allows to flush data to Otelic before exit
8tracer.getActiveSpanProcessor().forceFlush();
This is the recommended default for most cases. Asynchronous tracing captures events in the background, queuing them for later processing. This method minimizes app delays and is ideal for high-traffic scenarios.
1import { trace } from '@opentelemetry/api';
2const tracer = trace.getTracer('sync-app');
3const span = tracer.startSpan('process-data');
4span.end();
5// No need to flush, it will happen automatically in background.
6// With batching to reduce load.
For most apps, asynchronous tracing is the preferred choice, offering a good balance between performance and data quality. Synchronous tracing is better suited for critical tasks where immediate data capture is a priority.
Otelic.com supports both synchronous and asynchronous tracing. No matter which approach you use, Otelic processes the trace data efficiently, so you can debug faster without worrying about performance issues.