Commit 28e490e
# Backport
This will backport the following commits from `main` to `9.1`:
- [[Discover][APM] Create `accessKnownApmEventFields` for validating
unified traces API
(#241976)](#241976)
<!--- Backport version: 10.1.0 -->
### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)
<!--BACKPORT [{"author":{"name":"Gonçalo Rica Pais da
Silva","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-11-10T15:47:33Z","message":"[Discover][APM]
Create `accessKnownApmEventFields` for validating unified traces API
(#241976)\n\n## Summary\n\nCloses #240857\n\nThis PR implements a new
validation scheme for validating APM events,\nand applying it to the
Unified Trace Waterfall APIs as an initial\nproving ground.
`accessKnownApmEventFields` replaces\n`unflattenKnownApmEventFields` in
its use for validating the\n`getUnifiedTraceItems` responses, removing a
source of overhead with a\nmuch, much simpler and faster approach to
validating and strongly typing\nthe APM Event. This changes what is at
least an `O(n^2)` operation for\nan entire object, to just an `O(n)`
operation per validation, with `n`\nbeing the number of required fields
(which in reality is a small\nnumber).\n\nPotentially, if the checks are
made lazy (when the field is accessed),\nthis could become `O(1)`, but
with the downside that we won't be able to\ncollect all the missing
fields, only the one which the access failed\nfor. With
`accessKnownApmEventFields`, we are avoiding having to process\nan
entire object just to have the correct single/multi values per
field,\nwe only do it for the fields we are accessing and without
needing to\nallocate any new objects/arrays whilst doing so. And the
best part is we\nstill benefit from strong type checking and type
inference around keys,\nso you still get auto-complete in the
IDE.\n\nThe implementation proxies the original object, and then when we
access\nthe fields, it resolves the single or multi-value types, as well
as\nvalidating any required fields during construction. As part of
the\nproxied object, we expose an `unflatten` method which then takes
the\nvalidated object and well, unflattens it while still being
type-checked.\nAs such, usage is as follows:\n\n```ts\nconst event =
accessKnownApmEventFields(hit,
[SERVICE_NAME]);\nconsole.log(event[SERVICE_NAME]); // outputs
`\"node-svc\"` instead of `[\"node-svc\"]` as in the original
object\nconst unflattened =
event.unflatten();\nconsole.log(unflattened.service.name); // outputs
`\"node-svc\"` like above\n```\n\nAs well in this PR is a couple of
tweaks to\n`unflattenKnownApmEventFields` to improve perf there as well,
by using a\n`Set` instead of array for `ALL_FIELDS` (making checks there
go from\n`O(n)` to `O(1)` ), as well as removing `lodash` usage for
Array\nchecking when there is standard JS APIs for this.\n\n## How to
test\n\nThis PR needs to be able to pass CI, but also should not regress
on the\nUI:\n\n- Go to Discover while in an Observability space, select
a traces index\nin either classic or ES|QL mode.\n- Open a trace
overview, the Focused Trace Waterfall should not error\nwhen trying to
render the focused trace.\n- Open a full trace waterfall, that too
should not error when trying to\nrender.\n- In both cases, traces should
look as
expected.","sha":"050b80dd7ceee80b4d5315e48001546e09e9ccc9","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:obs-ux-infra_services","backport:version","v9.3.0","v8.19.7","v9.1.7","v9.2.1"],"title":"[Discover][APM]
Create `accessKnownApmEventFields` for validating unified traces
API","number":241976,"url":"https://github.com/elastic/kibana/pull/241976","mergeCommit":{"message":"[Discover][APM]
Create `accessKnownApmEventFields` for validating unified traces API
(#241976)\n\n## Summary\n\nCloses #240857\n\nThis PR implements a new
validation scheme for validating APM events,\nand applying it to the
Unified Trace Waterfall APIs as an initial\nproving ground.
`accessKnownApmEventFields` replaces\n`unflattenKnownApmEventFields` in
its use for validating the\n`getUnifiedTraceItems` responses, removing a
source of overhead with a\nmuch, much simpler and faster approach to
validating and strongly typing\nthe APM Event. This changes what is at
least an `O(n^2)` operation for\nan entire object, to just an `O(n)`
operation per validation, with `n`\nbeing the number of required fields
(which in reality is a small\nnumber).\n\nPotentially, if the checks are
made lazy (when the field is accessed),\nthis could become `O(1)`, but
with the downside that we won't be able to\ncollect all the missing
fields, only the one which the access failed\nfor. With
`accessKnownApmEventFields`, we are avoiding having to process\nan
entire object just to have the correct single/multi values per
field,\nwe only do it for the fields we are accessing and without
needing to\nallocate any new objects/arrays whilst doing so. And the
best part is we\nstill benefit from strong type checking and type
inference around keys,\nso you still get auto-complete in the
IDE.\n\nThe implementation proxies the original object, and then when we
access\nthe fields, it resolves the single or multi-value types, as well
as\nvalidating any required fields during construction. As part of
the\nproxied object, we expose an `unflatten` method which then takes
the\nvalidated object and well, unflattens it while still being
type-checked.\nAs such, usage is as follows:\n\n```ts\nconst event =
accessKnownApmEventFields(hit,
[SERVICE_NAME]);\nconsole.log(event[SERVICE_NAME]); // outputs
`\"node-svc\"` instead of `[\"node-svc\"]` as in the original
object\nconst unflattened =
event.unflatten();\nconsole.log(unflattened.service.name); // outputs
`\"node-svc\"` like above\n```\n\nAs well in this PR is a couple of
tweaks to\n`unflattenKnownApmEventFields` to improve perf there as well,
by using a\n`Set` instead of array for `ALL_FIELDS` (making checks there
go from\n`O(n)` to `O(1)` ), as well as removing `lodash` usage for
Array\nchecking when there is standard JS APIs for this.\n\n## How to
test\n\nThis PR needs to be able to pass CI, but also should not regress
on the\nUI:\n\n- Go to Discover while in an Observability space, select
a traces index\nin either classic or ES|QL mode.\n- Open a trace
overview, the Focused Trace Waterfall should not error\nwhen trying to
render the focused trace.\n- Open a full trace waterfall, that too
should not error when trying to\nrender.\n- In both cases, traces should
look as
expected.","sha":"050b80dd7ceee80b4d5315e48001546e09e9ccc9"}},"sourceBranch":"main","suggestedTargetBranches":["8.19","9.1"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/241976","number":241976,"mergeCommit":{"message":"[Discover][APM]
Create `accessKnownApmEventFields` for validating unified traces API
(#241976)\n\n## Summary\n\nCloses #240857\n\nThis PR implements a new
validation scheme for validating APM events,\nand applying it to the
Unified Trace Waterfall APIs as an initial\nproving ground.
`accessKnownApmEventFields` replaces\n`unflattenKnownApmEventFields` in
its use for validating the\n`getUnifiedTraceItems` responses, removing a
source of overhead with a\nmuch, much simpler and faster approach to
validating and strongly typing\nthe APM Event. This changes what is at
least an `O(n^2)` operation for\nan entire object, to just an `O(n)`
operation per validation, with `n`\nbeing the number of required fields
(which in reality is a small\nnumber).\n\nPotentially, if the checks are
made lazy (when the field is accessed),\nthis could become `O(1)`, but
with the downside that we won't be able to\ncollect all the missing
fields, only the one which the access failed\nfor. With
`accessKnownApmEventFields`, we are avoiding having to process\nan
entire object just to have the correct single/multi values per
field,\nwe only do it for the fields we are accessing and without
needing to\nallocate any new objects/arrays whilst doing so. And the
best part is we\nstill benefit from strong type checking and type
inference around keys,\nso you still get auto-complete in the
IDE.\n\nThe implementation proxies the original object, and then when we
access\nthe fields, it resolves the single or multi-value types, as well
as\nvalidating any required fields during construction. As part of
the\nproxied object, we expose an `unflatten` method which then takes
the\nvalidated object and well, unflattens it while still being
type-checked.\nAs such, usage is as follows:\n\n```ts\nconst event =
accessKnownApmEventFields(hit,
[SERVICE_NAME]);\nconsole.log(event[SERVICE_NAME]); // outputs
`\"node-svc\"` instead of `[\"node-svc\"]` as in the original
object\nconst unflattened =
event.unflatten();\nconsole.log(unflattened.service.name); // outputs
`\"node-svc\"` like above\n```\n\nAs well in this PR is a couple of
tweaks to\n`unflattenKnownApmEventFields` to improve perf there as well,
by using a\n`Set` instead of array for `ALL_FIELDS` (making checks there
go from\n`O(n)` to `O(1)` ), as well as removing `lodash` usage for
Array\nchecking when there is standard JS APIs for this.\n\n## How to
test\n\nThis PR needs to be able to pass CI, but also should not regress
on the\nUI:\n\n- Go to Discover while in an Observability space, select
a traces index\nin either classic or ES|QL mode.\n- Open a trace
overview, the Focused Trace Waterfall should not error\nwhen trying to
render the focused trace.\n- Open a full trace waterfall, that too
should not error when trying to\nrender.\n- In both cases, traces should
look as
expected.","sha":"050b80dd7ceee80b4d5315e48001546e09e9ccc9"}},{"branch":"8.19","label":"v8.19.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.1","label":"v9.1.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.2","label":"v9.2.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/242443","number":242443,"state":"OPEN"}]}]
BACKPORT-->
---------
Co-authored-by: kibanamachine <[email protected]>
1 parent 80cb77f commit 28e490e
File tree
10 files changed
+326
-110
lines changed- x-pack/solutions/observability/plugins
- apm_data_access/server
- utils
- apm/server/routes
- services
- traces
- transactions/get_span
10 files changed
+326
-110
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
Lines changed: 17 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
161 | 163 | | |
162 | 164 | | |
163 | 165 | | |
164 | 166 | | |
| 167 | + | |
165 | 168 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
179 | 178 | | |
180 | 179 | | |
181 | 180 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
Lines changed: 84 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
Lines changed: 117 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
0 commit comments