Otelic Logo

What is the Difference Between Synchronous and Asynchronous Tracing?

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.

1. Understanding Tracing Execution

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.

2. Synchronous Tracing: Immediate but Resource-Intensive

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();

3. Asynchronous Tracing: Efficient but Delayed

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.

Keeps apps responsive during heavy traffic.
Processes trace data in batches for efficiency.
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.

4. Choosing the Right Approach

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.

5. How Otelic.com Makes It Simple

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.

Handles trace processing automatically.
Ensures fast queries for both trace types.

For support, contact us at support@otelic.com

© 2024 Otelic.com - All Rights Reserved.