Skip to content

Commit a3510c0

Browse files
proposal for correlating synthetics traces (#825)
* proposal for correlating synthetics traces * address feedback and add more details * formatting fix * apply suggestions from code review Co-authored-by: Felix Barnsteiner <[email protected]> * add span id to the trace link * apply suggestions from code review Co-authored-by: Felix Barnsteiner <[email protected]> * review on user agent and address comments --------- Co-authored-by: Felix Barnsteiner <[email protected]>
1 parent 21964a6 commit a3510c0

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

specs/integrations/synthetics.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
## Synthetics Integration
2+
3+
Synthetic monitors play a crucial role in periodically checking the status of your services and applications on a global scale. General documentation about synthetic monitors can be found in
4+
[Synthetics getting started page](https://www.elastic.co/guide/en/observability/current/synthetics-get-started.html).
5+
6+
This integration goes in to more detail about how the sythetics monitors would
7+
be correlated with the APM traces. Synthetics traces can be categorized in to two
8+
main types
9+
1. HTTP checks - These have one-one mapping with APM transactions
10+
2. Browser checks - These have a one-to-many mapping with APM transactions
11+
12+
### Correlation
13+
14+
The Synthetics agent (including Heartbeat) takes the responsibility of creating the
15+
[`traceparent`](../agents/tracing-distributed-tracing.md#trace_id-parent_id-and-traceparent)
16+
header for each outgoing network request associated with a test during every
17+
monitor execution.
18+
19+
- `trace.id` and `parent.id`
20+
- outgoing requests that are being explicity traced by the synthetics agent
21+
will have the `parent.id` and `trace.id` as part of the trace context.
22+
- must be unique for each step for a browser monitor
23+
- must be unique for a http monitor
24+
- `sampled` Flag
25+
- used to control the sampling decision for all the downstream services.
26+
- 100% sampling when tracing is enabled
27+
28+
#### Browser checks
29+
30+
When executing a Synthetics journey with tracing enabled for all outgoing requests `**/*` or for specific URLs with the --apm_tracing_urls flag, the Synthetics agent takes the following actions:
31+
32+
1. Adds the traceparent header to each matching outgoing request.
33+
2. Includes trace.id and parent.id in all the Step Elasticsearch (ES) documents for the journey.
34+
35+
```ts
36+
// run journey
37+
npx @elastic/synthetics --apm_tracing_urls "elastic.co/*"
38+
39+
// example.journey.ts
40+
journey("elastic e2e", ({ page }) => {
41+
step("home page", async() => {
42+
await page.goto("https://www.elastic.co")
43+
})
44+
step("blog page", async() => {
45+
await page.goto("https://www.elastic.co/blog")
46+
})
47+
})
48+
```
49+
50+
Example of the tracing information added to the ES documents for two steps in the journey:
51+
52+
```json
53+
// Step - homepage
54+
{"type":"step/end","journey":{"name":"elastic e2e"},"step":{"name":"home page","index":1,"status":"failed","duration":{"us":17382122}}, "trace.id": "t1"}
55+
{"type":"journey/network_info","journey":{"name":"elastic e2e"},"step":{"name":"home page","index":1},"http":{"request":{"url":"http://www.elastic.co/","method":"GET"}},"trace.id": "t1", "span.id": "s1"}
56+
57+
58+
// Step - blog page
59+
{"type":"step/end","journey":{"name":"elastic e2e"},"step":{"name":"blog page","index":2,"status":"failed","duration":{"us":17382122}}, "trace.id": "t2"}
60+
{"type":"journey/network_info","journey":{"name":"elastic e2e"},"step":{"name":"blog page","index":2},"http":{"request":{"url":"http://www.elastic.co/blog","method":"GET"}},"trace.id": "t2", "span.id": "s2"}
61+
```
62+
63+
With this tracing information available in the ES documents for each step's network requests, the Synthetics UI can link back to the individual backend transactions in APM.
64+
65+
#### HTTP Checks
66+
67+
For the below HTTP monitor
68+
69+
```yml
70+
# heartbeat.yml
71+
heartbeat.monitors:
72+
- type: http
73+
id: test-http
74+
urls: ["https://www.example.com"]
75+
apm:
76+
enabled: true
77+
```
78+
79+
Heartbeat would add the `traceparent` header to the monitored URL and add the
80+
other tracing related information to the ES documents.
81+
82+
```json
83+
{"event":{"action":"monitor.run"},"monitor":{"id":"test-http","type":"http","status":"up","duration":{"ms":112}}, "trace.id": "t1", "span.id": "s1"}
84+
```
85+
86+
It's important to note that there is no dedicated waterfall information for the HTTP checks in the Synthetics UI. Consequently, the linking here will directly take you to the transaction if the backend is also traced by Elastic APM or OTel (OpenTelemetry)-based agents. This works similar to the Browser checks where the network request is directly linked to the transaction.
87+
88+
**NOTE: The correlation remain applicable even if downstream services are traced by OpenTelemetry (OTel)-based agents. This ensures a consistent and seamless tracing experience regardless of the underlying tracing infrastructure.**
89+
90+
### Identifying Synthetics trace
91+
92+
When tracing is enabled on the Synthetics monitors, the agent appends the `Elastic/Synthetics` to the HTTP `User-Agent` header for all outgoing requests. Tracing UI can use this information to identify the traces that are originated from
93+
Synthetics using the following approaches.
94+
95+
- Elastic APM agents
96+
- The information is stored in `http.headers.user-agent`
97+
- OTel agents
98+
- The information is stored in `user_agent.original`
99+
100+
UI will check both of these fields to identify the Synthetics traces and will
101+
prefer `user_agent.original` if both are present.
102+
103+
There is a limitation with this approach
104+
- users can override the `User-Agent` header in the monitor configuration which
105+
might lead to users seeing only partial traces on APM UI.
106+
107+
When a trace is confirmed to be originated from Synthetics-based monitors, the
108+
Trace Explorer view can be linked back to the Synthetics waterfall.
109+
110+
- `/app/synthetics/link-to/<trace.id>:span.id`
111+
- links back to the explicit browser waterfall step on the Synthetics UI, and
112+
it follows the format `/monitor/:monitorId/test-run/:runId/step/:stepIndex#:spanId`.

0 commit comments

Comments
 (0)