Skip to content

[9.3] [APM] Fix Otel missing fields undefined errors (#254271)#254748

Merged
jennypavlova merged 2 commits intoelastic:9.3from
jennypavlova:backport/9.3/pr-254271
Feb 24, 2026
Merged

[9.3] [APM] Fix Otel missing fields undefined errors (#254271)#254748
jennypavlova merged 2 commits intoelastic:9.3from
jennypavlova:backport/9.3/pr-254271

Conversation

@jennypavlova
Copy link
Copy Markdown
Member

Backport

This will backport the following commits from main to 9.3:

Questions ?

Please refer to the Backport tool documentation

Closes elastic#254222

## Summary

This PR fixes uncaught errors when APM data has missing `service` or
`service.environment` (e.g. OpenTelemetry or incomplete documents). The
UI was reading `error.service.environment`,
`transaction.service.environment`, and similar properties without
optional chaining, causing "Cannot read properties of undefined (reading
'environment')" and error boundary crashes.

This PR:

- Adds optional chaining and fallbacks to `ENVIRONMENT_NOT_DEFINED` /
`getEnvironmentLabel` where service or environment may be missing
- Updates **error group details**: error sample detail, contextual
insight, and sample summary (optional `error`/`service`, safe access to
`error.error`)
- Updates **transaction/span flyouts**: transaction flyout, view full
trace link, span flyout sticky properties
- Updates **agent configuration link**: safe access to
`configService?.name` and `configService?.environment`

## How to test

- Use APM with data that has no `service` or no `service.environment`
(e.g. OTel or incomplete documents): If using synthtrace I added a
scenario:
- Run `node scripts/synthtrace missing_service_environment --from=now-1h
--to=now+1h`
- Confirm that the service.environment is not in the document and there
is no error in the flyout:
<img width="3446" height="1962" alt="image"
src="https://github.com/user-attachments/assets/04867ef0-f89b-4601-b0bf-381a795ab2a6"
/>
- Open error group details and an error sample, transaction flyout, span
flyout, or a view that uses agent config service
- Confirm the UI no longer crashes and shows "Not defined" (or
equivalent) for missing environment where appropriate:
<img width="3456" height="1994" alt="image"
src="https://github.com/user-attachments/assets/21fb7684-2c40-4eb5-b83d-063d9b2437be"
/>

https://github.com/user-attachments/assets/19c46cb3-ff2e-4938-8cf3-2316f7a1a4ae

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit f0e605f)

# Conflicts:
#	x-pack/solutions/observability/plugins/apm/public/components/app/error_group_details/error_sampler/error_sample_detail.tsx
@jennypavlova jennypavlova added the backport This PR is a backport of another PR label Feb 24, 2026
@jennypavlova jennypavlova enabled auto-merge (squash) February 24, 2026 14:54
@botelastic botelastic Bot added the Team:obs-presentation Focus: APM UI, Infra UI, Hosts UI, Universal Profiling, Obs Overview and left Navigation label Feb 24, 2026
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/obs-presentation-team (Team:obs-presentation)

…hared/links/apm/agent_configuration_links.test.ts
@jennypavlova jennypavlova merged commit 038f36d into elastic:9.3 Feb 24, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR Team:obs-presentation Focus: APM UI, Infra UI, Hosts UI, Universal Profiling, Obs Overview and left Navigation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants