Commit 3a3275f
[Discover][Traces] Add APM operation IDs to traces log fetching (#268452)
## Summary
Relates to elastic/observability-dev#5348
This PR instruments two log-fetching code paths in the trace document
viewer with APM execution context and explicit error capture, enabling
RED metrics (rate, errors, duration) visibility in APM for those
operations. Without operation IDs, all Kibana search requests appear
identically in APM's search/ese spans with no way to attribute latency
or throughput to a specific feature.
### fetchLogDocumentById
`fetchLogDocumentById` is called when a user opens a log document from
the expanded waterfall flyout. Because this function owns the
`data.search.search` call directly, we can instrument it fully:
- An `executionContext` with `operation_id: fetch-log-by-id` is passed
to the search call. The Kibana HTTP layer forwards this via the
`x-kbn-context` header, and the server-side APM agent attaches it as a
`kibana_meta_operation_id` label on the resulting span.
- The search call is wrapped in a try-catch that calls
`apm.captureError` with the same label, so failures appear in APM with
the correct operation context.
- `toasts.addDanger` is replaced with `toasts.add({ color: 'danger', ...
})` to avoid double error capture: `addDanger` internally calls
`apm.captureError`, which would produce a duplicate error event
alongside ours.
### Logs embeddable (TraceContextLogEvents)
The correlated logs section in the trace document overview renders via
`LazySavedSearchComponent`, which delegates all fetching to
`SearchEmbeddable` internally. Because we do not own the fetch call,
explicit error capture is not feasible: `SearchEmbeddable` handles
errors internally and surfaces them as inline UI state, so failures
never propagate as rejections we can catch or as failed HTTP spans in
APM.
For latency and throughput, we thread `executionContext` with
`operation_id: fetch-trace-context-logs` from `TraceContextLogEvents`
down through `LogEventsComponent` and `LazySavedSearchComponent` to
`SearchEmbeddable`'s `parentApi`. The embeddable reads execution context
from `parentApi` and includes it in every search request, tagging those
spans with `kibana_meta_operation_id: fetch-trace-context-logs` on the
server.
This required adding `executionContext` as a typed prop to
`LogEventsProps` and `SavedSearchComponentProps`, and declaring
`@kbn/core-execution-context-common` in `kbn_references` for both
affected packages.
### How to test
Verify the logs embeddable span label:
- Start Kibana with a synthtrace scenario that includes log documents
correlated to a trace (e.g. `node scripts/synthtrace
logs_traces_hosts`).
- Open a trace document in the doc viewer and expand the Logs section.
- In APM, filter search/ese spans by `labels.kibana_meta_operation_id:
fetch-trace-context-logs` and confirm requests from the logs section
appear with that label.
Verify the fetch log span label and error capture:
- From the expanded waterfall, click a log item to open the log document
flyout.
- In APM, filter by `labels.kibana_meta_operation_id: fetch-log-by-id`
and confirm the fetch span appears.
- To test error capture: temporarily break the fetch (e.g. pass an
invalid index) and confirm a single APM error appears with
`labels.kibana_meta_operation_id: fetch-log-by-id`, not two.
---------
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>1 parent 1f14d4e commit 3a3275f
16 files changed
Lines changed: 129 additions & 28 deletions
File tree
- src/platform
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| 174 | + | |
174 | 175 | | |
175 | 176 | | |
| 177 | + | |
176 | 178 | | |
177 | 179 | | |
178 | 180 | | |
179 | 181 | | |
180 | | - | |
| 182 | + | |
181 | 183 | | |
182 | 184 | | |
183 | 185 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| 60 | + | |
59 | 61 | | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
| 116 | + | |
115 | 117 | | |
116 | 118 | | |
117 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
74 | 73 | | |
75 | 74 | | |
76 | 75 | | |
| |||
209 | 208 | | |
210 | 209 | | |
211 | 210 | | |
212 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
213 | 214 | | |
214 | 215 | | |
215 | 216 | | |
| |||
225 | 226 | | |
226 | 227 | | |
227 | 228 | | |
228 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
229 | 232 | | |
230 | 233 | | |
231 | 234 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
97 | 99 | | |
98 | 100 | | |
99 | 101 | | |
| 102 | + | |
100 | 103 | | |
101 | 104 | | |
102 | 105 | | |
| |||
0 commit comments