> ## Documentation Index
> Fetch the complete documentation index at: https://docs.atla-ai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Passing context around in a micro-service architecture

> How to handle sampling in distributed systems with multiple microservices

Sampling in a distributed OpenTelemetry system requires coordination between services to ensure consistent sampling decisions across your entire application.

In a microservice architecture, every service needs to use the same sampling method to maintain trace consistency. Without this coordination, you might end up with incomplete traces where some spans are sampled while others are not.

## Recommended Approach

### Main Orchestrating Application

Set the sampling method in your primary service that initiates requests:

```python theme={null}
from atla_insights import configure
from atla_insights.sampling import TraceRatioSamplingOptions

configure(
    token=os.environ["ATLA_INSIGHTS_TOKEN"],
    sampling=TraceRatioSamplingOptions(rate=0.10)  # 10% sampling rate
)
```

### All Other Microservices

Configure downstream services to inherit the sampling decision from the main application:

```python theme={null}
from atla_insights import configure
from opentelemetry.sdk.trace.sampling import ParentBased, ALWAYS_ON

configure(
    token=os.environ["ATLA_INSIGHTS_TOKEN"],
    sampling=ParentBased(ALWAYS_ON)  # Inherits decision from parent trace
)
```

## How This Works

1. **Parent-based sampling**: The `ParentBased(ALWAYS_ON)` sampler checks if there's a parent span from another service
2. **Inheritance**: If a parent span exists and was sampled, the child service will also sample
3. **Consistency**: This ensures that either the entire distributed trace is sampled or none of it is
