|
| 1 | +--- |
| 2 | +navigation_title: SDK sampling issues |
| 3 | +description: Learn how to troubleshoot missing or incomplete traces in EDOT SDKs caused by head sampling configuration. |
| 4 | +applies_to: |
| 5 | + serverless: all |
| 6 | + product: |
| 7 | + elastic-otel-sdk: ga |
| 8 | +products: |
| 9 | + - id: observability |
| 10 | + - id: edot-sdk |
| 11 | +--- |
| 12 | + |
| 13 | +# Missing or incomplete traces due to SDK sampling |
| 14 | + |
| 15 | +If traces or spans are missing in Kibana, the issue might be related to SDK-level sampling configuration. By default, SDKs use head-based sampling, meaning the decision to record or drop a trace is made when the trace is first created. |
| 16 | + |
| 17 | +Both SDK-level and Collector-based sampling can result in gaps in telemetry if misconfigured. Refer to [Missing or incomplete traces due to Collector sampling](../edot-collector/misconfigured-sampling-collector.md) for more details. |
| 18 | + |
| 19 | +## Symptoms |
| 20 | + |
| 21 | +You might notice one or more of the following behaviors when SDK-level sampling is impacting your traces: |
| 22 | + |
| 23 | +- Only a small subset of traces reaches {{es}} or {{kib}}, even though SDKs are exporting spans. |
| 24 | +- Transactions look incomplete because some spans are missing. |
| 25 | +- Trace volume is unexpectedly low compared to logs or metrics. |
| 26 | + |
| 27 | +## Causes |
| 28 | + |
| 29 | +These factors can result in missing spans or traces when sampling is configured at the SDK level: |
| 30 | + |
| 31 | +- Head sampling at the SDK level drops traces before they're exported. |
| 32 | +- Default sampling rates (for example `1/100` or `1/1000`) might be too low for your workload. |
| 33 | +- Environment variables like `OTEL_TRACES_SAMPLER` or `OTEL_TRACES_SAMPLER_ARG` are not set, not recognized, or formatted in a way the SDK doesn't support. |
| 34 | +- Inconsistent configuration across services can lead to fragmented or incomplete traces. |
| 35 | +- Some SDKs enforce stricter formats for sampler arguments, which can cause values to be ignored if not matched precisely. |
| 36 | + |
| 37 | +## Resolution |
| 38 | + |
| 39 | +Follow these steps to resolve SDK sampling configuration issues: |
| 40 | + |
| 41 | +::::{stepper} |
| 42 | + |
| 43 | +:::{step} Check SDK environment variables |
| 44 | + |
| 45 | +- Confirm that `OTEL_TRACES_SAMPLER` and `OTEL_TRACES_SAMPLER_ARG` are set correctly. |
| 46 | +- For testing, you can temporarily set: |
| 47 | + |
| 48 | + ```bash |
| 49 | + export OTEL_TRACES_SAMPLER=always_on |
| 50 | + ``` |
| 51 | +- In production, consider using `parentbased_traceidratio` with an explicit ratio. |
| 52 | +::: |
| 53 | + |
| 54 | +:::{step} Align configuration across services |
| 55 | + |
| 56 | +- Use consistent sampling configuration across all instrumented services to help avoid dropped child spans or fragmented traces. |
| 57 | +::: |
| 58 | + |
| 59 | +:::{step} Adjust sampling ratios for your traffic |
| 60 | + |
| 61 | +- For low-traffic applications, avoid extremely low ratios (such as `1/1000`). |
| 62 | + |
| 63 | + For example, the following configuration samples ~20% of traces: |
| 64 | + |
| 65 | + ```bash |
| 66 | + export OTEL_TRACES_SAMPLER=parentbased_traceidratio |
| 67 | + export OTEL_TRACES_SAMPLER_ARG=0.2 |
| 68 | + ``` |
| 69 | +::: |
| 70 | + |
| 71 | +:::{step} Use Collector tail sampling for advanced scenarios |
| 72 | + |
| 73 | +- Head sampling can't evaluate the full trace context before making a decision. |
| 74 | +- For more control (for example "keep all errors, sample 10% of successes"), use Collector tail sampling. |
| 75 | + |
| 76 | + For more information, refer to [Missing or incomplete traces due to Collector sampling](../edot-collector/misconfigured-sampling-collector.md). |
| 77 | +::: |
| 78 | + |
| 79 | +:::: |
| 80 | + |
| 81 | +## Resources |
| 82 | + |
| 83 | +- [OTEL_TRACES_SAMPLER environment variable specifications](https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#otel_traces_sampler) |
| 84 | +- [OpenTelemetry sampling concepts - contrib documentation](https://opentelemetry.io/docs/concepts/sampling/) |
| 85 | +- [Missing or incomplete traces due to Collector sampling](../edot-collector/misconfigured-sampling-collector.md) |
0 commit comments