You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/serverless/apm/apm-transaction-sampling.mdx
+52-6Lines changed: 52 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,23 +28,69 @@ Head-based sampling is quick and easy to set up.
28
28
Its downside is that it's entirely random — interesting
29
29
data might be discarded purely due to chance.
30
30
31
-
### Distributed tracing with head-based sampling
31
+
### Distributed tracing
32
32
33
33
In a _distributed_ trace, the sampling decision is still made when the trace is initiated.
34
34
Each subsequent service respects the initial service's sampling decision, regardless of its configured sample rate;
35
35
the result is a sampling percentage that matches the initiating service.
36
36
37
-
In this example, `Service A` initiates four transactions and has sample rate of `.5` (`50%`).
38
-
The sample rates of `Service B` and `Service C` are ignored.
37
+
In the example in _Figure 1_, `Service A` initiates four transactions and has a sample rate of `.5` (`50%`).
38
+
The upstream sampling decision is respected, so even if the sample rate is defined and is a different
39
+
value in `Service B` and `Service C`, the sample rate will be `.5` (`50%`) for all services.
40
+
41
+
**Figure 1. Upstream sampling decision is respected**
39
42
40
43

41
44
42
-
In this example, `Service A` initiates four transactions and has a sample rate of `1` (`100%`).
43
-
Again, the sample rates of `Service B` and `Service C` are ignored.
45
+
In the example in _Figure 2_, `Service A` initiates four transactions and has a sample rate of `1` (`100%`).
46
+
Again, the upstream sampling decision is respected, so the sample rate for all services will
47
+
be `1` (`100%`).
48
+
49
+
**Figure 2. Upstream sampling decision is respected**
44
50
45
51

46
52
47
-
### OpenTelemetry with head-based sampling
53
+
### Trace continuation strategies with distributed tracing
54
+
55
+
In addition to setting the sample rate, you can also specify which _trace continuation strategy_ to use.
56
+
There are three trace continuation strategies: `continue`, `restart`, and `restart_external`.
57
+
58
+
The **`continue`** trace continuation strategy is the default and will behave similar to the examples in
59
+
the [Distributed tracing section](#distributed-tracing).
60
+
61
+
Use the **`restart_external`** trace continuation strategy on an Elastic-monitored service to start
62
+
a new trace if the previous service did not have a `traceparent` header with `es` vendor data.
63
+
This can be helpful if a transaction includes an Elastic-monitored service that is receiving requests
64
+
from an unmonitored service.
65
+
66
+
In the example in _Figure 3_, `Service A` is an Elastic-monitored service that initiates four transactions
67
+
with a sample rate of `.25` (`25%`). Because `Service B` is unmonitored, the traces started in
68
+
`Service A` will end there. `Service C` is an Elastic-monitored service that initiates four transactions
69
+
that start new traces with a new sample rate of `.5` (`50%`). Because `Service D` is also
70
+
Elastic-monitored service, the upstream sampling decision defined in `Service C` is respected.
71
+
The end result will be three sampled traces.
72
+
73
+
**Figure 3. Using the `restart_external` trace continuation strategy**
74
+
75
+

76
+
77
+
Use the **`restart`** trace continuation strategy on an Elastic-monitored service to start
78
+
a new trace regardless of whether the previous service had a `traceparent` header.
79
+
This can be helpful if an Elastic-monitored service is publicly exposed, and you do not
80
+
want tracing data to possibly be spoofed by user requests.
81
+
82
+
In the example in _Figure 4_, `Service A` and `Service B` are Elastic-monitored services that use the
83
+
default trace continuation strategy. `Service A` has a sample rate of `.25` (`25%`), and that
84
+
sampling decision is respected in `Service B`. `Service C` is an Elastic-monitored service that
85
+
uses the `restart` trace continuation strategy and has a sample rate of `1` (`100%`).
86
+
Because it uses `restart`, the upstream sample rate is _not_ respected in `Service C` and all four
87
+
traces will be sampled as new traces in `Service C`. The end result will be five sampled traces.
88
+
89
+
**Figure 4. Using the `restart` trace continuation strategy**
90
+
91
+

92
+
93
+
### OpenTelemetry
48
94
49
95
Head-based sampling is implemented directly in the APM agents and SDKs.
50
96
The sample rate must be propagated between services and the managed intake service in order to produce accurate metrics.
0 commit comments