Skip to content

[Discover][APM] Check for undefined data from useFetcher in TraceWaterfallEmbeddable#240843

Merged
iblancof merged 5 commits intoelastic:mainfrom
iblancof:238405-discovertraces-cannot-read-properties-of-undefined-reading-map
Oct 29, 2025
Merged

[Discover][APM] Check for undefined data from useFetcher in TraceWaterfallEmbeddable#240843
iblancof merged 5 commits intoelastic:mainfrom
iblancof:238405-discovertraces-cannot-read-properties-of-undefined-reading-map

Conversation

@iblancof
Copy link
Contributor

@iblancof iblancof commented Oct 27, 2025

Summary

Closes #238405

Since we upgraded the error handling strategy to catch Fatal React Errors, we’ve started seeing TypeError: Cannot read properties of undefined (reading 'map') in versions 8.19.x and 9.1.x.

Screenshot 2025-10-27 at 16 03 48

After reviewing the error stack, we found that this occurs because traceItems is occasionally arrive as undefined. Although TS enforces that it should always be defined, a potential API malfunction may cause this scenario.

To prevent users from encountering an uncontrolled error, this PR adds a check for undefined for data coming from the useFetcher (more details in this comment).

This ensures that the UI behaves safely even if traceItems is unexpectedly undefined.

Before After
Screen Recording 2025-10-27 at 15 33 39 Screenshot 2025-10-28 at 14 26 04

I also took the chance to update the UI, so the error message is more visible:

Before After
Screenshot 2025-10-28 at 14 26 04 Screenshot 2025-10-28 at 14 24 51

The same error has been now added to the TraceWaterfallEmbeddable:
Screenshot 2025-10-28 at 14 27 31

@iblancof iblancof self-assigned this Oct 27, 2025
@iblancof iblancof requested a review from a team October 27, 2025 15:13
@iblancof iblancof added bug Fixes for quality problems that affect the customer experience release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-infra_services - DEPRECATED DEPRECATED - Use Team:obs-presentation. backport:version Backport to applied version labels v9.2.0 v9.3.0 v8.19.7 v9.1.7 labels Oct 27, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services)

const { duration, traceWaterfall, maxDepth, rootItem, legends, colorBy, traceState } =
useTraceWaterfall({
traceItems,
traceItems: traceItems || [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better if we could investigate why the API is returning undefined and fix it there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specially as you mentioned that TS is not expecting it to be undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @cauemarcondes, thanks for the feedback!

Looking at this from a different angle, I realized where the critical point was.

It’s not that TS didn’t expect undefined, but that we were bypassing it in TraceWaterfallEmbeddable with traceItems={data?.traceItems!}, assuming data (and traceItems) would always be there.

When I checked FocusedWaterfallEmbeddable, I saw it does a proper check for data before rendering, so I added the same here to keep things consistent.

if (isPending(status)) {
return <Loading />;
}
if (data === undefined) {
return (
<EuiText>
{i18n.translate(
'xpack.apm.focusedTraceWaterfallEmbeddable.traceWaterfallCouldNotTextLabel',
{ defaultMessage: 'Trace waterfall could not be loaded' }
)}
</EuiText>
);
}
return <FocusedTraceWaterfall items={data} isEmbeddable />;

We need this because useFetcher can return undefined for data.

Was it an API problem on our side?
No, it wasn’t.

Looking at the code, we show <Loading /> if the useFetcher status is isPending (loading or not_initiated). But if the status is failure, the code just continues running, which can result in data being undefined according to how useFetcher works.

setResult({
data: undefined,
status: FETCH_STATUS.FAILURE,
error: e,
});

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #16 / Core Analysis - Entity Store @ess @skipInServerlessMKI Entity Store APIs get and list "before all" hook in "get and list"
  • [job] [logs] FTR Configs #73 / serverless observability UI Dataset Quality Dataset quality details navigate to dataset details should navigate to details page from a main page

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
apm 2.8MB 2.8MB +4.0B

History

cc @iblancof

Copy link
Contributor

@cauemarcondes cauemarcondes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@iblancof iblancof merged commit 7d2975b into elastic:main Oct 29, 2025
13 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19, 9.1, 9.2

https://github.com/elastic/kibana/actions/runs/18902197083

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 29, 2025
…fall (elastic#240843)

## Summary

Closes elastic#238405

Since we upgraded the error handling strategy to catch Fatal React
Errors, we’ve started seeing `TypeError: Cannot read properties of
undefined (reading 'map')` in versions 8.19.x and 9.1.x.

<img width="809" height="121" alt="Screenshot 2025-10-27 at 16 03 48"
src="https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8"
/>

After reviewing the error stack, we found that this occurs because
`traceItems` is occasionally arrive as `undefined`. Although TS enforces
that it should always be defined, a potential API malfunction may cause
this scenario.

To prevent users from encountering an uncontrolled error, this PR adds a
check for `undefined` for `data` coming from the `useFetcher` (more
details in [this
comment](elastic#240843 (comment))).

This ensures that the UI behaves safely even if `traceItems` is
unexpectedly `undefined`.

|Before|After|
|-|-|
|![Screen Recording 2025-10-27 at 15 33
39](https://github.com/user-attachments/assets/6753ed8c-1e37-4117-8ba0-112d996e2066)|<img
width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04"
src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064"
/>|

I also took the chance to update the UI, so the error message is more
visible:
|Before|After|
|-|-|
|<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04"
src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064"
/>|<img width="1405" height="966" alt="Screenshot 2025-10-28 at 14 24
51"
src="https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20"
/>|

The same error has been now added to the `TraceWaterfallEmbeddable`:
<img width="1387" height="135" alt="Screenshot 2025-10-28 at 14 27 31"
src="https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf"
/>

(cherry picked from commit 7d2975b)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
8.19 Backport failed because of merge conflicts
9.1 Backport failed because of merge conflicts
9.2

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 240843

Questions ?

Please refer to the Backport tool documentation

@iblancof
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
9.1
8.19

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

@iblancof iblancof changed the title [Discover][APM] Add fallback to traceItems when calling useTraceWaterfall [Discover][APM] Check for undefined data from useFetcher in TraceWaterfallEmbeddable Oct 29, 2025
iblancof added a commit to iblancof/kibana that referenced this pull request Oct 29, 2025
…fall (elastic#240843)

## Summary

Closes elastic#238405

Since we upgraded the error handling strategy to catch Fatal React
Errors, we’ve started seeing `TypeError: Cannot read properties of
undefined (reading 'map')` in versions 8.19.x and 9.1.x.

<img width="809" height="121" alt="Screenshot 2025-10-27 at 16 03 48"
src="https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8"
/>

After reviewing the error stack, we found that this occurs because
`traceItems` is occasionally arrive as `undefined`. Although TS enforces
that it should always be defined, a potential API malfunction may cause
this scenario.

To prevent users from encountering an uncontrolled error, this PR adds a
check for `undefined` for `data` coming from the `useFetcher` (more
details in [this
comment](elastic#240843 (comment))).

This ensures that the UI behaves safely even if `traceItems` is
unexpectedly `undefined`.

|Before|After|
|-|-|
|![Screen Recording 2025-10-27 at 15 33
39](https://github.com/user-attachments/assets/6753ed8c-1e37-4117-8ba0-112d996e2066)|<img
width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04"
src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064"
/>|

I also took the chance to update the UI, so the error message is more
visible:
|Before|After|
|-|-|
|<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04"
src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064"
/>|<img width="1405" height="966" alt="Screenshot 2025-10-28 at 14 24
51"
src="https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20"
/>|

The same error has been now added to the `TraceWaterfallEmbeddable`:
<img width="1387" height="135" alt="Screenshot 2025-10-28 at 14 27 31"
src="https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf"
/>

(cherry picked from commit 7d2975b)

# Conflicts:
#	x-pack/solutions/observability/plugins/apm/public/embeddable/trace_waterfall/trace_waterfall_embeddable.tsx
kibanamachine added a commit that referenced this pull request Oct 29, 2025
…eWaterfall (#240843) (#241079)

# Backport

This will backport the following commits from `main` to `9.2`:
- [[Discover][APM] Add fallback to traceItems when calling
useTraceWaterfall
(#240843)](#240843)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Irene
Blanco","email":"irene.blanco@elastic.co"},"sourceCommit":{"committedDate":"2025-10-29T08:51:15Z","message":"[Discover][APM]
Add fallback to traceItems when calling useTraceWaterfall
(#240843)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the
error handling strategy to catch Fatal React\nErrors, we’ve started
seeing `TypeError: Cannot read properties of\nundefined (reading 'map')`
in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\"
alt=\"Screenshot 2025-10-27 at 16 03
48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter
reviewing the error stack, we found that this occurs
because\n`traceItems` is occasionally arrive as `undefined`. Although TS
enforces\nthat it should always be defined, a potential API malfunction
may cause\nthis scenario.\n\nTo prevent users from encountering an
uncontrolled error, this PR adds a\ncheck for `undefined` for `data`
coming from the `useFetcher` (more\ndetails in
[this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis
ensures that the UI behaves safely even if `traceItems` is\nunexpectedly
`undefined`.\n\n|Before|After|\n|-|-|\n|![Screen Recording 2025-10-27 at
15
33\n39](https://github.com/user-attachments/assets/6753ed8c-1e37-4117-8ba0-112d996e2066)|<img\nwidth=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI
also took the chance to update the UI, so the error message is
more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img
width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14
24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe
same error has been now added to the `TraceWaterfallEmbeddable`:\n<img
width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27
31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","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]
Add fallback to traceItems when calling useTraceWaterfall
","number":240843,"url":"https://github.com/elastic/kibana/pull/240843","mergeCommit":{"message":"[Discover][APM]
Add fallback to traceItems when calling useTraceWaterfall
(#240843)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the
error handling strategy to catch Fatal React\nErrors, we’ve started
seeing `TypeError: Cannot read properties of\nundefined (reading 'map')`
in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\"
alt=\"Screenshot 2025-10-27 at 16 03
48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter
reviewing the error stack, we found that this occurs
because\n`traceItems` is occasionally arrive as `undefined`. Although TS
enforces\nthat it should always be defined, a potential API malfunction
may cause\nthis scenario.\n\nTo prevent users from encountering an
uncontrolled error, this PR adds a\ncheck for `undefined` for `data`
coming from the `useFetcher` (more\ndetails in
[this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis
ensures that the UI behaves safely even if `traceItems` is\nunexpectedly
`undefined`.\n\n|Before|After|\n|-|-|\n|![Screen Recording 2025-10-27 at
15
33\n39](https://github.com/user-attachments/assets/6753ed8c-1e37-4117-8ba0-112d996e2066)|<img\nwidth=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI
also took the chance to update the UI, so the error message is
more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img
width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14
24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe
same error has been now added to the `TraceWaterfallEmbeddable`:\n<img
width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27
31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1"}},"sourceBranch":"main","suggestedTargetBranches":["8.19","9.1","9.2"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/240843","number":240843,"mergeCommit":{"message":"[Discover][APM]
Add fallback to traceItems when calling useTraceWaterfall
(#240843)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the
error handling strategy to catch Fatal React\nErrors, we’ve started
seeing `TypeError: Cannot read properties of\nundefined (reading 'map')`
in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\"
alt=\"Screenshot 2025-10-27 at 16 03
48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter
reviewing the error stack, we found that this occurs
because\n`traceItems` is occasionally arrive as `undefined`. Although TS
enforces\nthat it should always be defined, a potential API malfunction
may cause\nthis scenario.\n\nTo prevent users from encountering an
uncontrolled error, this PR adds a\ncheck for `undefined` for `data`
coming from the `useFetcher` (more\ndetails in
[this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis
ensures that the UI behaves safely even if `traceItems` is\nunexpectedly
`undefined`.\n\n|Before|After|\n|-|-|\n|![Screen Recording 2025-10-27 at
15
33\n39](https://github.com/user-attachments/assets/6753ed8c-1e37-4117-8ba0-112d996e2066)|<img\nwidth=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI
also took the chance to update the UI, so the error message is
more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img
width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14
24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe
same error has been now added to the `TraceWaterfallEmbeddable`:\n<img
width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27
31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1"}},{"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,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Irene Blanco <irene.blanco@elastic.co>
tkajtoch pushed a commit to tkajtoch/kibana that referenced this pull request Oct 29, 2025
…fall (elastic#240843)

## Summary

Closes elastic#238405

Since we upgraded the error handling strategy to catch Fatal React
Errors, we’ve started seeing `TypeError: Cannot read properties of
undefined (reading 'map')` in versions 8.19.x and 9.1.x.

<img width="809" height="121" alt="Screenshot 2025-10-27 at 16 03 48"
src="https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8"
/>

After reviewing the error stack, we found that this occurs because
`traceItems` is occasionally arrive as `undefined`. Although TS enforces
that it should always be defined, a potential API malfunction may cause
this scenario.

To prevent users from encountering an uncontrolled error, this PR adds a
check for `undefined` for `data` coming from the `useFetcher` (more
details in [this
comment](elastic#240843 (comment))).

This ensures that the UI behaves safely even if `traceItems` is
unexpectedly `undefined`.

|Before|After|
|-|-|
|![Screen Recording 2025-10-27 at 15 33
39](https://github.com/user-attachments/assets/6753ed8c-1e37-4117-8ba0-112d996e2066)|<img
width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04"
src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064"
/>|

I also took the chance to update the UI, so the error message is more
visible:
|Before|After|
|-|-|
|<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04"
src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064"
/>|<img width="1405" height="966" alt="Screenshot 2025-10-28 at 14 24
51"
src="https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20"
/>|

The same error has been now added to the `TraceWaterfallEmbeddable`:
<img width="1387" height="135" alt="Screenshot 2025-10-28 at 14 27 31"
src="https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf"
/>
iblancof added a commit that referenced this pull request Oct 29, 2025
…ceWaterfallEmbeddable (#240843) (#241095)

# Backport

This will backport the following commits from `main` to `9.1`:
- [[Discover][APM] Add fallback to traceItems when calling
useTraceWaterfall
(#240843)](#240843)

<!--- Backport version: 10.1.0 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Irene
Blanco","email":"irene.blanco@elastic.co"},"sourceCommit":{"committedDate":"2025-10-29T08:51:15Z","message":"[Discover][APM]
Add fallback to traceItems when calling useTraceWaterfall
(#240843)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the
error handling strategy to catch Fatal React\nErrors, we’ve started
seeing `TypeError: Cannot read properties of\nundefined (reading 'map')`
in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\"
alt=\"Screenshot 2025-10-27 at 16 03
48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter
reviewing the error stack, we found that this occurs
because\n`traceItems` is occasionally arrive as `undefined`. Although TS
enforces\nthat it should always be defined, a potential API malfunction
may cause\nthis scenario.\n\nTo prevent users from encountering an
uncontrolled error, this PR adds a\ncheck for `undefined` for `data`
coming from the `useFetcher` (more\ndetails in
[this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis
ensures that the UI behaves safely even if `traceItems` is\nunexpectedly
`undefined`.\n\n|Before|After|\n|-|-|\n|![Screen Recording 2025-10-27 at
15
33\n39](https://github.com/user-attachments/assets/6753ed8c-1e37-4117-8ba0-112d996e2066)|<img\nwidth=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI
also took the chance to update the UI, so the error message is
more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img
width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14
24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe
same error has been now added to the `TraceWaterfallEmbeddable`:\n<img
width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27
31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","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]
Add fallback to traceItems when calling useTraceWaterfall
","number":240843,"url":"https://github.com/elastic/kibana/pull/240843","mergeCommit":{"message":"[Discover][APM]
Add fallback to traceItems when calling useTraceWaterfall
(#240843)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the
error handling strategy to catch Fatal React\nErrors, we’ve started
seeing `TypeError: Cannot read properties of\nundefined (reading 'map')`
in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\"
alt=\"Screenshot 2025-10-27 at 16 03
48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter
reviewing the error stack, we found that this occurs
because\n`traceItems` is occasionally arrive as `undefined`. Although TS
enforces\nthat it should always be defined, a potential API malfunction
may cause\nthis scenario.\n\nTo prevent users from encountering an
uncontrolled error, this PR adds a\ncheck for `undefined` for `data`
coming from the `useFetcher` (more\ndetails in
[this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis
ensures that the UI behaves safely even if `traceItems` is\nunexpectedly
`undefined`.\n\n|Before|After|\n|-|-|\n|![Screen Recording 2025-10-27 at
15
33\n39](https://github.com/user-attachments/assets/6753ed8c-1e37-4117-8ba0-112d996e2066)|<img\nwidth=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI
also took the chance to update the UI, so the error message is
more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img
width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14
24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe
same error has been now added to the `TraceWaterfallEmbeddable`:\n<img
width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27
31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1"}},"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/240843","number":240843,"mergeCommit":{"message":"[Discover][APM]
Add fallback to traceItems when calling useTraceWaterfall
(#240843)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the
error handling strategy to catch Fatal React\nErrors, we’ve started
seeing `TypeError: Cannot read properties of\nundefined (reading 'map')`
in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\"
alt=\"Screenshot 2025-10-27 at 16 03
48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter
reviewing the error stack, we found that this occurs
because\n`traceItems` is occasionally arrive as `undefined`. Although TS
enforces\nthat it should always be defined, a potential API malfunction
may cause\nthis scenario.\n\nTo prevent users from encountering an
uncontrolled error, this PR adds a\ncheck for `undefined` for `data`
coming from the `useFetcher` (more\ndetails in
[this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis
ensures that the UI behaves safely even if `traceItems` is\nunexpectedly
`undefined`.\n\n|Before|After|\n|-|-|\n|![Screen Recording 2025-10-27 at
15
33\n39](https://github.com/user-attachments/assets/6753ed8c-1e37-4117-8ba0-112d996e2066)|<img\nwidth=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI
also took the chance to update the UI, so the error message is
more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img
width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14
24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe
same error has been now added to the `TraceWaterfallEmbeddable`:\n<img
width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27
31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1"}},{"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/241079","number":241079,"state":"OPEN"}]}]
BACKPORT-->
iblancof added a commit that referenced this pull request Oct 29, 2025
…aceWaterfallEmbeddable (#240843) (#241099)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[Discover][APM] Add fallback to traceItems when calling
useTraceWaterfall
(#240843)](#240843)

<!--- Backport version: 10.1.0 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Irene
Blanco","email":"irene.blanco@elastic.co"},"sourceCommit":{"committedDate":"2025-10-29T08:51:15Z","message":"[Discover][APM]
Add fallback to traceItems when calling useTraceWaterfall
(#240843)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the
error handling strategy to catch Fatal React\nErrors, we’ve started
seeing `TypeError: Cannot read properties of\nundefined (reading 'map')`
in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\"
alt=\"Screenshot 2025-10-27 at 16 03
48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter
reviewing the error stack, we found that this occurs
because\n`traceItems` is occasionally arrive as `undefined`. Although TS
enforces\nthat it should always be defined, a potential API malfunction
may cause\nthis scenario.\n\nTo prevent users from encountering an
uncontrolled error, this PR adds a\ncheck for `undefined` for `data`
coming from the `useFetcher` (more\ndetails in
[this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis
ensures that the UI behaves safely even if `traceItems` is\nunexpectedly
`undefined`.\n\n|Before|After|\n|-|-|\n|![Screen Recording 2025-10-27 at
15
33\n39](https://github.com/user-attachments/assets/6753ed8c-1e37-4117-8ba0-112d996e2066)|<img\nwidth=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI
also took the chance to update the UI, so the error message is
more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img
width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14
24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe
same error has been now added to the `TraceWaterfallEmbeddable`:\n<img
width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27
31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","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]
Add fallback to traceItems when calling useTraceWaterfall
","number":240843,"url":"https://github.com/elastic/kibana/pull/240843","mergeCommit":{"message":"[Discover][APM]
Add fallback to traceItems when calling useTraceWaterfall
(#240843)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the
error handling strategy to catch Fatal React\nErrors, we’ve started
seeing `TypeError: Cannot read properties of\nundefined (reading 'map')`
in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\"
alt=\"Screenshot 2025-10-27 at 16 03
48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter
reviewing the error stack, we found that this occurs
because\n`traceItems` is occasionally arrive as `undefined`. Although TS
enforces\nthat it should always be defined, a potential API malfunction
may cause\nthis scenario.\n\nTo prevent users from encountering an
uncontrolled error, this PR adds a\ncheck for `undefined` for `data`
coming from the `useFetcher` (more\ndetails in
[this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis
ensures that the UI behaves safely even if `traceItems` is\nunexpectedly
`undefined`.\n\n|Before|After|\n|-|-|\n|![Screen Recording 2025-10-27 at
15
33\n39](https://github.com/user-attachments/assets/6753ed8c-1e37-4117-8ba0-112d996e2066)|<img\nwidth=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI
also took the chance to update the UI, so the error message is
more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img
width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14
24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe
same error has been now added to the `TraceWaterfallEmbeddable`:\n<img
width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27
31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1"}},"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/240843","number":240843,"mergeCommit":{"message":"[Discover][APM]
Add fallback to traceItems when calling useTraceWaterfall
(#240843)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the
error handling strategy to catch Fatal React\nErrors, we’ve started
seeing `TypeError: Cannot read properties of\nundefined (reading 'map')`
in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\"
alt=\"Screenshot 2025-10-27 at 16 03
48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter
reviewing the error stack, we found that this occurs
because\n`traceItems` is occasionally arrive as `undefined`. Although TS
enforces\nthat it should always be defined, a potential API malfunction
may cause\nthis scenario.\n\nTo prevent users from encountering an
uncontrolled error, this PR adds a\ncheck for `undefined` for `data`
coming from the `useFetcher` (more\ndetails in
[this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis
ensures that the UI behaves safely even if `traceItems` is\nunexpectedly
`undefined`.\n\n|Before|After|\n|-|-|\n|![Screen Recording 2025-10-27 at
15
33\n39](https://github.com/user-attachments/assets/6753ed8c-1e37-4117-8ba0-112d996e2066)|<img\nwidth=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI
also took the chance to update the UI, so the error message is
more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\"
height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26
04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img
width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14
24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe
same error has been now added to the `TraceWaterfallEmbeddable`:\n<img
width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27
31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1"}},{"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/241079","number":241079,"state":"OPEN"}]}]
BACKPORT-->
qn895 pushed a commit to qn895/kibana that referenced this pull request Oct 30, 2025
…fall (elastic#240843)

## Summary

Closes elastic#238405

Since we upgraded the error handling strategy to catch Fatal React
Errors, we’ve started seeing `TypeError: Cannot read properties of
undefined (reading 'map')` in versions 8.19.x and 9.1.x.

<img width="809" height="121" alt="Screenshot 2025-10-27 at 16 03 48"
src="https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8"
/>

After reviewing the error stack, we found that this occurs because
`traceItems` is occasionally arrive as `undefined`. Although TS enforces
that it should always be defined, a potential API malfunction may cause
this scenario.

To prevent users from encountering an uncontrolled error, this PR adds a
check for `undefined` for `data` coming from the `useFetcher` (more
details in [this
comment](elastic#240843 (comment))).

This ensures that the UI behaves safely even if `traceItems` is
unexpectedly `undefined`.

|Before|After|
|-|-|
|![Screen Recording 2025-10-27 at 15 33
39](https://github.com/user-attachments/assets/6753ed8c-1e37-4117-8ba0-112d996e2066)|<img
width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04"
src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064"
/>|

I also took the chance to update the UI, so the error message is more
visible:
|Before|After|
|-|-|
|<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04"
src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064"
/>|<img width="1405" height="966" alt="Screenshot 2025-10-28 at 14 24
51"
src="https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20"
/>|

The same error has been now added to the `TraceWaterfallEmbeddable`:
<img width="1387" height="135" alt="Screenshot 2025-10-28 at 14 27 31"
src="https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf"
/>
ana-davydova pushed a commit to ana-davydova/kibana that referenced this pull request Nov 3, 2025
…fall (elastic#240843)

## Summary

Closes elastic#238405

Since we upgraded the error handling strategy to catch Fatal React
Errors, we’ve started seeing `TypeError: Cannot read properties of
undefined (reading 'map')` in versions 8.19.x and 9.1.x.

<img width="809" height="121" alt="Screenshot 2025-10-27 at 16 03 48"
src="https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8"
/>

After reviewing the error stack, we found that this occurs because
`traceItems` is occasionally arrive as `undefined`. Although TS enforces
that it should always be defined, a potential API malfunction may cause
this scenario.

To prevent users from encountering an uncontrolled error, this PR adds a
check for `undefined` for `data` coming from the `useFetcher` (more
details in [this
comment](elastic#240843 (comment))).

This ensures that the UI behaves safely even if `traceItems` is
unexpectedly `undefined`.

|Before|After|
|-|-|
|![Screen Recording 2025-10-27 at 15 33
39](https://github.com/user-attachments/assets/6753ed8c-1e37-4117-8ba0-112d996e2066)|<img
width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04"
src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064"
/>|

I also took the chance to update the UI, so the error message is more
visible:
|Before|After|
|-|-|
|<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04"
src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064"
/>|<img width="1405" height="966" alt="Screenshot 2025-10-28 at 14 24
51"
src="https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20"
/>|

The same error has been now added to the `TraceWaterfallEmbeddable`:
<img width="1387" height="135" alt="Screenshot 2025-10-28 at 14 27 31"
src="https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf"
/>
albertoblaz pushed a commit to albertoblaz/kibana that referenced this pull request Nov 4, 2025
…fall (elastic#240843)

## Summary

Closes elastic#238405

Since we upgraded the error handling strategy to catch Fatal React
Errors, we’ve started seeing `TypeError: Cannot read properties of
undefined (reading 'map')` in versions 8.19.x and 9.1.x.

<img width="809" height="121" alt="Screenshot 2025-10-27 at 16 03 48"
src="https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8"
/>

After reviewing the error stack, we found that this occurs because
`traceItems` is occasionally arrive as `undefined`. Although TS enforces
that it should always be defined, a potential API malfunction may cause
this scenario.

To prevent users from encountering an uncontrolled error, this PR adds a
check for `undefined` for `data` coming from the `useFetcher` (more
details in [this
comment](elastic#240843 (comment))).

This ensures that the UI behaves safely even if `traceItems` is
unexpectedly `undefined`.

|Before|After|
|-|-|
|![Screen Recording 2025-10-27 at 15 33
39](https://github.com/user-attachments/assets/6753ed8c-1e37-4117-8ba0-112d996e2066)|<img
width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04"
src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064"
/>|

I also took the chance to update the UI, so the error message is more
visible:
|Before|After|
|-|-|
|<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04"
src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064"
/>|<img width="1405" height="966" alt="Screenshot 2025-10-28 at 14 24
51"
src="https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20"
/>|

The same error has been now added to the `TraceWaterfallEmbeddable`:
<img width="1387" height="135" alt="Screenshot 2025-10-28 at 14 27 31"
src="https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf"
/>
@iblancof iblancof deleted the 238405-discovertraces-cannot-read-properties-of-undefined-reading-map branch March 13, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels bug Fixes for quality problems that affect the customer experience release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-infra_services - DEPRECATED DEPRECATED - Use Team:obs-presentation. v8.19.7 v9.1.7 v9.2.1 v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Discover][Traces] Cannot read properties of undefined (reading 'map')

4 participants