Skip to content

[APM] Fix Otel missing fields undefined errors#254271

Merged
jennypavlova merged 6 commits intoelastic:mainfrom
jennypavlova:254222-apm-cannot-read-properties-of-undefined-reading-environment-otel-missing-serviceenvironment
Feb 24, 2026
Merged

[APM] Fix Otel missing fields undefined errors#254271
jennypavlova merged 6 commits intoelastic:mainfrom
jennypavlova:254222-apm-cannot-read-properties-of-undefined-reading-environment-otel-missing-serviceenvironment

Conversation

@jennypavlova
Copy link
Copy Markdown
Member

@jennypavlova jennypavlova commented Feb 20, 2026

Closes #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:
    image
  • 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:
image
service_env_checks.mov

@jennypavlova jennypavlova self-assigned this Feb 20, 2026
@jennypavlova jennypavlova marked this pull request as ready for review February 23, 2026 10:37
@jennypavlova jennypavlova requested review from a team as code owners February 23, 2026 10:37
@jennypavlova jennypavlova added release_note:skip Skip the PR/issue when compiling release notes backport:all-open Backport to all branches that could still receive a release Team:obs-presentation Focus: APM UI, Infra UI, Hosts UI, Universal Profiling, Obs Overview and left Navigation labels Feb 23, 2026
@elasticmachine
Copy link
Copy Markdown
Contributor

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

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

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.7MB 2.7MB +1.7KB

History

cc @jennypavlova

Comment on lines +8 to +13
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use it except in compliance with the Elastic License 2.0.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Duplicate copywright

Suggested change
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use it except in compliance with the Elastic License 2.0.
*/

Comment on lines +8 to +13
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use it except in compliance with the Elastic License 2.0.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Duplicate copywright

Suggested change
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use it except in compliance with the Elastic License 2.0.
*/

Copy link
Copy Markdown
Contributor

@smith smith left a comment

Choose a reason for hiding this comment

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

Verified the fix on an OTel service (flagd) with no service.environment — error sample detail page renders correctly, shows "Not defined" badge, no crash. Nice synthtrace scenario too.

};
}
export function SampleSummary({ error }: Props) {
const logMessage = error.error.log?.message;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: ?.[0].message will throw if exception is an empty array — ?.[0] returns undefined, then .message throws. Should be ?.[0]?.message. Pre-existing issue (the original code had the same pattern), but since you're already touching this line it's a good time to fix it.

Suggested change
const logMessage = error.error.log?.message;
const excMessage = error?.error?.exception?.[0]?.message || error?.error?.message;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch, thanks! fixed ✅

Copy link
Copy Markdown
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.

Synthtrace chages LGTM

@jennypavlova jennypavlova merged commit f0e605f into elastic:main Feb 24, 2026
17 checks passed
@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 8.19, 9.2, 9.3

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

@kibanamachine
Copy link
Copy Markdown
Contributor

💔 All backports failed

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

Manual backport

To create the backport manually run:

node scripts/backport --pr 254271

Questions ?

Please refer to the Backport tool documentation

mbondyra added a commit to rgodfrey-elastic/kibana that referenced this pull request Feb 24, 2026
…ps-config-rebase

* commit 'f135f030951237c5e9b0251931441aee3121b31d': (163 commits)
  [CPS] Support data view requests and do not sanitize project_routing in data plugin/resolve indices  (elastic#253654)
  [One Workflow] Execute workflow from historical (elastic#253396)
  [streams][background tasks] gracefully handle non existing stream (elastic#254683)
  [Lens API] Waffle/Mosaic get green as a default color (elastic#254304)
  [Security Solution] Remove prebuilt rules customization callout on Rule Management page (elastic#254386)
  [Workflows] support passing attachments to run_agent step (elastic#251291)
  [One Discover][Logs UX] Update OpenTelemetry Semantic Conventions (elastic#254367)
  [kbn-es] Add --docker flag to yarn es snapshot (elastic#254306)
  [Workplace AI] Remove Data Source Config (elastic#254521)
  [Entity Store v2] Add CRUD API (elastic#252052)
  [CI] Increase type checking machine (elastic#254676)
  [main] Sync bundled packages with Package Storage (elastic#254232)
  Skip flaky test elastic#254625 (elastic#254662)
  Upgrade `@elastic/elasticsearch` to 9.3.1 (elastic#253660)
  [One Workflow] Migrate http step to new connector (elastic#249004)
  [Entity Store] Store EUID Scripts (elastic#254515)
  [APM] Fix Otel missing fields undefined errors (elastic#254271)
  [Console] Add support for documentation links on Serverless (elastic#254489)
  Create edit ILM flow (elastic#253393)
  [Agent Builder] Mid term: minimal recommended model set elastic#12875 (elastic#254560)
  ...
jennypavlova added a commit to jennypavlova/kibana that referenced this pull request Feb 24, 2026
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 added a commit to jennypavlova/kibana that referenced this pull request Feb 24, 2026
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:
#	src/platform/packages/shared/kbn-apm-synthtrace/src/scenarios/missing_service_environment.ts
#	x-pack/solutions/observability/plugins/apm/public/components/app/error_group_details/error_sampler/error_sample_detail.tsx
@jennypavlova
Copy link
Copy Markdown
Member Author

💚 All backports created successfully

Status Branch Result
9.3
9.2
8.19

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

Questions ?

Please refer to the Backport tool documentation

jennypavlova added a commit to jennypavlova/kibana that referenced this pull request Feb 24, 2026
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:
#	src/platform/packages/shared/kbn-apm-synthtrace/src/scenarios/missing_service_environment.ts
#	x-pack/solutions/observability/plugins/apm/public/components/app/error_group_details/error_sampler/error_sample_detail.tsx
jennypavlova added a commit that referenced this pull request Feb 24, 2026
# Backport

This will backport the following commits from `main` to `9.2`:
- [[APM] Fix Otel missing fields undefined errors
(#254271)](#254271)

<!--- Backport version: 10.2.0 -->

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

<!--BACKPORT
[{"author":{"name":"jennypavlova","email":"dzheni.pavlova@elastic.co"},"sourceCommit":{"committedDate":"2026-02-24T10:04:27Z","message":"[APM]
Fix Otel missing fields undefined errors (#254271)\n\nCloses
#254222\n\n## Summary\n\nThis PR fixes uncaught errors when APM data has
missing `service` or\n`service.environment` (e.g. OpenTelemetry or
incomplete documents). The\nUI was reading
`error.service.environment`,\n`transaction.service.environment`, and
similar properties without\noptional chaining, causing \"Cannot read
properties of undefined (reading\n'environment')\" and error boundary
crashes.\n\nThis PR:\n\n- Adds optional chaining and fallbacks to
`ENVIRONMENT_NOT_DEFINED` /\n`getEnvironmentLabel` where service or
environment may be missing\n- Updates **error group details**: error
sample detail, contextual\ninsight, and sample summary (optional
`error`/`service`, safe access to\n`error.error`)\n- Updates
**transaction/span flyouts**: transaction flyout, view full\ntrace link,
span flyout sticky properties\n- Updates **agent configuration link**:
safe access to\n`configService?.name` and
`configService?.environment`\n\n## How to test\n\n- Use APM with data
that has no `service` or no `service.environment`\n(e.g. OTel or
incomplete documents): If using synthtrace I added a\nscenario:\n- Run
`node scripts/synthtrace missing_service_environment
--from=now-1h\n--to=now+1h`\n- Confirm that the service.environment is
not in the document and there\nis no error in the flyout:\n<img
width=\"3446\" height=\"1962\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/04867ef0-f89b-4601-b0bf-381a795ab2a6\"\n/>\n-
Open error group details and an error sample, transaction flyout,
span\nflyout, or a view that uses agent config service\n- Confirm the UI
no longer crashes and shows \"Not defined\" (or\nequivalent) for missing
environment where appropriate:\n<img width=\"3456\" height=\"1994\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/21fb7684-2c40-4eb5-b83d-063d9b2437be\"\n/>\n\n\nhttps://github.com/user-attachments/assets/19c46cb3-ff2e-4938-8cf3-2316f7a1a4ae\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"f0e605f119e7adfbae1969e32dfe77ce104baa52","branchLabelMapping":{"^v9.4.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:all-open","v9.4.0","Team:obs-presentation"],"title":"[APM]
Fix Otel missing fields undefined
errors","number":254271,"url":"https://github.com/elastic/kibana/pull/254271","mergeCommit":{"message":"[APM]
Fix Otel missing fields undefined errors (#254271)\n\nCloses
#254222\n\n## Summary\n\nThis PR fixes uncaught errors when APM data has
missing `service` or\n`service.environment` (e.g. OpenTelemetry or
incomplete documents). The\nUI was reading
`error.service.environment`,\n`transaction.service.environment`, and
similar properties without\noptional chaining, causing \"Cannot read
properties of undefined (reading\n'environment')\" and error boundary
crashes.\n\nThis PR:\n\n- Adds optional chaining and fallbacks to
`ENVIRONMENT_NOT_DEFINED` /\n`getEnvironmentLabel` where service or
environment may be missing\n- Updates **error group details**: error
sample detail, contextual\ninsight, and sample summary (optional
`error`/`service`, safe access to\n`error.error`)\n- Updates
**transaction/span flyouts**: transaction flyout, view full\ntrace link,
span flyout sticky properties\n- Updates **agent configuration link**:
safe access to\n`configService?.name` and
`configService?.environment`\n\n## How to test\n\n- Use APM with data
that has no `service` or no `service.environment`\n(e.g. OTel or
incomplete documents): If using synthtrace I added a\nscenario:\n- Run
`node scripts/synthtrace missing_service_environment
--from=now-1h\n--to=now+1h`\n- Confirm that the service.environment is
not in the document and there\nis no error in the flyout:\n<img
width=\"3446\" height=\"1962\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/04867ef0-f89b-4601-b0bf-381a795ab2a6\"\n/>\n-
Open error group details and an error sample, transaction flyout,
span\nflyout, or a view that uses agent config service\n- Confirm the UI
no longer crashes and shows \"Not defined\" (or\nequivalent) for missing
environment where appropriate:\n<img width=\"3456\" height=\"1994\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/21fb7684-2c40-4eb5-b83d-063d9b2437be\"\n/>\n\n\nhttps://github.com/user-attachments/assets/19c46cb3-ff2e-4938-8cf3-2316f7a1a4ae\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"f0e605f119e7adfbae1969e32dfe77ce104baa52"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.4.0","branchLabelMappingKey":"^v9.4.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/254271","number":254271,"mergeCommit":{"message":"[APM]
Fix Otel missing fields undefined errors (#254271)\n\nCloses
#254222\n\n## Summary\n\nThis PR fixes uncaught errors when APM data has
missing `service` or\n`service.environment` (e.g. OpenTelemetry or
incomplete documents). The\nUI was reading
`error.service.environment`,\n`transaction.service.environment`, and
similar properties without\noptional chaining, causing \"Cannot read
properties of undefined (reading\n'environment')\" and error boundary
crashes.\n\nThis PR:\n\n- Adds optional chaining and fallbacks to
`ENVIRONMENT_NOT_DEFINED` /\n`getEnvironmentLabel` where service or
environment may be missing\n- Updates **error group details**: error
sample detail, contextual\ninsight, and sample summary (optional
`error`/`service`, safe access to\n`error.error`)\n- Updates
**transaction/span flyouts**: transaction flyout, view full\ntrace link,
span flyout sticky properties\n- Updates **agent configuration link**:
safe access to\n`configService?.name` and
`configService?.environment`\n\n## How to test\n\n- Use APM with data
that has no `service` or no `service.environment`\n(e.g. OTel or
incomplete documents): If using synthtrace I added a\nscenario:\n- Run
`node scripts/synthtrace missing_service_environment
--from=now-1h\n--to=now+1h`\n- Confirm that the service.environment is
not in the document and there\nis no error in the flyout:\n<img
width=\"3446\" height=\"1962\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/04867ef0-f89b-4601-b0bf-381a795ab2a6\"\n/>\n-
Open error group details and an error sample, transaction flyout,
span\nflyout, or a view that uses agent config service\n- Confirm the UI
no longer crashes and shows \"Not defined\" (or\nequivalent) for missing
environment where appropriate:\n<img width=\"3456\" height=\"1994\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/21fb7684-2c40-4eb5-b83d-063d9b2437be\"\n/>\n\n\nhttps://github.com/user-attachments/assets/19c46cb3-ff2e-4938-8cf3-2316f7a1a4ae\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"f0e605f119e7adfbae1969e32dfe77ce104baa52"}}]}]
BACKPORT-->
jennypavlova added a commit that referenced this pull request Feb 24, 2026
# Backport

This will backport the following commits from `main` to `9.3`:
- [[APM] Fix Otel missing fields undefined errors
(#254271)](#254271)

<!--- Backport version: 10.2.0 -->

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

<!--BACKPORT
[{"author":{"name":"jennypavlova","email":"dzheni.pavlova@elastic.co"},"sourceCommit":{"committedDate":"2026-02-24T10:04:27Z","message":"[APM]
Fix Otel missing fields undefined errors (#254271)\n\nCloses
#254222\n\n## Summary\n\nThis PR fixes uncaught errors when APM data has
missing `service` or\n`service.environment` (e.g. OpenTelemetry or
incomplete documents). The\nUI was reading
`error.service.environment`,\n`transaction.service.environment`, and
similar properties without\noptional chaining, causing \"Cannot read
properties of undefined (reading\n'environment')\" and error boundary
crashes.\n\nThis PR:\n\n- Adds optional chaining and fallbacks to
`ENVIRONMENT_NOT_DEFINED` /\n`getEnvironmentLabel` where service or
environment may be missing\n- Updates **error group details**: error
sample detail, contextual\ninsight, and sample summary (optional
`error`/`service`, safe access to\n`error.error`)\n- Updates
**transaction/span flyouts**: transaction flyout, view full\ntrace link,
span flyout sticky properties\n- Updates **agent configuration link**:
safe access to\n`configService?.name` and
`configService?.environment`\n\n## How to test\n\n- Use APM with data
that has no `service` or no `service.environment`\n(e.g. OTel or
incomplete documents): If using synthtrace I added a\nscenario:\n- Run
`node scripts/synthtrace missing_service_environment
--from=now-1h\n--to=now+1h`\n- Confirm that the service.environment is
not in the document and there\nis no error in the flyout:\n<img
width=\"3446\" height=\"1962\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/04867ef0-f89b-4601-b0bf-381a795ab2a6\"\n/>\n-
Open error group details and an error sample, transaction flyout,
span\nflyout, or a view that uses agent config service\n- Confirm the UI
no longer crashes and shows \"Not defined\" (or\nequivalent) for missing
environment where appropriate:\n<img width=\"3456\" height=\"1994\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/21fb7684-2c40-4eb5-b83d-063d9b2437be\"\n/>\n\n\nhttps://github.com/user-attachments/assets/19c46cb3-ff2e-4938-8cf3-2316f7a1a4ae\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"f0e605f119e7adfbae1969e32dfe77ce104baa52","branchLabelMapping":{"^v9.4.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:all-open","v9.4.0","Team:obs-presentation"],"title":"[APM]
Fix Otel missing fields undefined
errors","number":254271,"url":"https://github.com/elastic/kibana/pull/254271","mergeCommit":{"message":"[APM]
Fix Otel missing fields undefined errors (#254271)\n\nCloses
#254222\n\n## Summary\n\nThis PR fixes uncaught errors when APM data has
missing `service` or\n`service.environment` (e.g. OpenTelemetry or
incomplete documents). The\nUI was reading
`error.service.environment`,\n`transaction.service.environment`, and
similar properties without\noptional chaining, causing \"Cannot read
properties of undefined (reading\n'environment')\" and error boundary
crashes.\n\nThis PR:\n\n- Adds optional chaining and fallbacks to
`ENVIRONMENT_NOT_DEFINED` /\n`getEnvironmentLabel` where service or
environment may be missing\n- Updates **error group details**: error
sample detail, contextual\ninsight, and sample summary (optional
`error`/`service`, safe access to\n`error.error`)\n- Updates
**transaction/span flyouts**: transaction flyout, view full\ntrace link,
span flyout sticky properties\n- Updates **agent configuration link**:
safe access to\n`configService?.name` and
`configService?.environment`\n\n## How to test\n\n- Use APM with data
that has no `service` or no `service.environment`\n(e.g. OTel or
incomplete documents): If using synthtrace I added a\nscenario:\n- Run
`node scripts/synthtrace missing_service_environment
--from=now-1h\n--to=now+1h`\n- Confirm that the service.environment is
not in the document and there\nis no error in the flyout:\n<img
width=\"3446\" height=\"1962\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/04867ef0-f89b-4601-b0bf-381a795ab2a6\"\n/>\n-
Open error group details and an error sample, transaction flyout,
span\nflyout, or a view that uses agent config service\n- Confirm the UI
no longer crashes and shows \"Not defined\" (or\nequivalent) for missing
environment where appropriate:\n<img width=\"3456\" height=\"1994\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/21fb7684-2c40-4eb5-b83d-063d9b2437be\"\n/>\n\n\nhttps://github.com/user-attachments/assets/19c46cb3-ff2e-4938-8cf3-2316f7a1a4ae\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"f0e605f119e7adfbae1969e32dfe77ce104baa52"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.4.0","branchLabelMappingKey":"^v9.4.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/254271","number":254271,"mergeCommit":{"message":"[APM]
Fix Otel missing fields undefined errors (#254271)\n\nCloses
#254222\n\n## Summary\n\nThis PR fixes uncaught errors when APM data has
missing `service` or\n`service.environment` (e.g. OpenTelemetry or
incomplete documents). The\nUI was reading
`error.service.environment`,\n`transaction.service.environment`, and
similar properties without\noptional chaining, causing \"Cannot read
properties of undefined (reading\n'environment')\" and error boundary
crashes.\n\nThis PR:\n\n- Adds optional chaining and fallbacks to
`ENVIRONMENT_NOT_DEFINED` /\n`getEnvironmentLabel` where service or
environment may be missing\n- Updates **error group details**: error
sample detail, contextual\ninsight, and sample summary (optional
`error`/`service`, safe access to\n`error.error`)\n- Updates
**transaction/span flyouts**: transaction flyout, view full\ntrace link,
span flyout sticky properties\n- Updates **agent configuration link**:
safe access to\n`configService?.name` and
`configService?.environment`\n\n## How to test\n\n- Use APM with data
that has no `service` or no `service.environment`\n(e.g. OTel or
incomplete documents): If using synthtrace I added a\nscenario:\n- Run
`node scripts/synthtrace missing_service_environment
--from=now-1h\n--to=now+1h`\n- Confirm that the service.environment is
not in the document and there\nis no error in the flyout:\n<img
width=\"3446\" height=\"1962\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/04867ef0-f89b-4601-b0bf-381a795ab2a6\"\n/>\n-
Open error group details and an error sample, transaction flyout,
span\nflyout, or a view that uses agent config service\n- Confirm the UI
no longer crashes and shows \"Not defined\" (or\nequivalent) for missing
environment where appropriate:\n<img width=\"3456\" height=\"1994\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/21fb7684-2c40-4eb5-b83d-063d9b2437be\"\n/>\n\n\nhttps://github.com/user-attachments/assets/19c46cb3-ff2e-4938-8cf3-2316f7a1a4ae\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"f0e605f119e7adfbae1969e32dfe77ce104baa52"}}]}]
BACKPORT-->
jennypavlova added a commit that referenced this pull request Feb 24, 2026
)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[APM] Fix Otel missing fields undefined errors
(#254271)](#254271)

<!--- Backport version: 10.2.0 -->

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

<!--BACKPORT
[{"author":{"name":"jennypavlova","email":"dzheni.pavlova@elastic.co"},"sourceCommit":{"committedDate":"2026-02-24T10:04:27Z","message":"[APM]
Fix Otel missing fields undefined errors (#254271)\n\nCloses
#254222\n\n## Summary\n\nThis PR fixes uncaught errors when APM data has
missing `service` or\n`service.environment` (e.g. OpenTelemetry or
incomplete documents). The\nUI was reading
`error.service.environment`,\n`transaction.service.environment`, and
similar properties without\noptional chaining, causing \"Cannot read
properties of undefined (reading\n'environment')\" and error boundary
crashes.\n\nThis PR:\n\n- Adds optional chaining and fallbacks to
`ENVIRONMENT_NOT_DEFINED` /\n`getEnvironmentLabel` where service or
environment may be missing\n- Updates **error group details**: error
sample detail, contextual\ninsight, and sample summary (optional
`error`/`service`, safe access to\n`error.error`)\n- Updates
**transaction/span flyouts**: transaction flyout, view full\ntrace link,
span flyout sticky properties\n- Updates **agent configuration link**:
safe access to\n`configService?.name` and
`configService?.environment`\n\n## How to test\n\n- Use APM with data
that has no `service` or no `service.environment`\n(e.g. OTel or
incomplete documents): If using synthtrace I added a\nscenario:\n- Run
`node scripts/synthtrace missing_service_environment
--from=now-1h\n--to=now+1h`\n- Confirm that the service.environment is
not in the document and there\nis no error in the flyout:\n<img
width=\"3446\" height=\"1962\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/04867ef0-f89b-4601-b0bf-381a795ab2a6\"\n/>\n-
Open error group details and an error sample, transaction flyout,
span\nflyout, or a view that uses agent config service\n- Confirm the UI
no longer crashes and shows \"Not defined\" (or\nequivalent) for missing
environment where appropriate:\n<img width=\"3456\" height=\"1994\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/21fb7684-2c40-4eb5-b83d-063d9b2437be\"\n/>\n\n\nhttps://github.com/user-attachments/assets/19c46cb3-ff2e-4938-8cf3-2316f7a1a4ae\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"f0e605f119e7adfbae1969e32dfe77ce104baa52","branchLabelMapping":{"^v9.4.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:all-open","v9.4.0","Team:obs-presentation"],"title":"[APM]
Fix Otel missing fields undefined
errors","number":254271,"url":"https://github.com/elastic/kibana/pull/254271","mergeCommit":{"message":"[APM]
Fix Otel missing fields undefined errors (#254271)\n\nCloses
#254222\n\n## Summary\n\nThis PR fixes uncaught errors when APM data has
missing `service` or\n`service.environment` (e.g. OpenTelemetry or
incomplete documents). The\nUI was reading
`error.service.environment`,\n`transaction.service.environment`, and
similar properties without\noptional chaining, causing \"Cannot read
properties of undefined (reading\n'environment')\" and error boundary
crashes.\n\nThis PR:\n\n- Adds optional chaining and fallbacks to
`ENVIRONMENT_NOT_DEFINED` /\n`getEnvironmentLabel` where service or
environment may be missing\n- Updates **error group details**: error
sample detail, contextual\ninsight, and sample summary (optional
`error`/`service`, safe access to\n`error.error`)\n- Updates
**transaction/span flyouts**: transaction flyout, view full\ntrace link,
span flyout sticky properties\n- Updates **agent configuration link**:
safe access to\n`configService?.name` and
`configService?.environment`\n\n## How to test\n\n- Use APM with data
that has no `service` or no `service.environment`\n(e.g. OTel or
incomplete documents): If using synthtrace I added a\nscenario:\n- Run
`node scripts/synthtrace missing_service_environment
--from=now-1h\n--to=now+1h`\n- Confirm that the service.environment is
not in the document and there\nis no error in the flyout:\n<img
width=\"3446\" height=\"1962\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/04867ef0-f89b-4601-b0bf-381a795ab2a6\"\n/>\n-
Open error group details and an error sample, transaction flyout,
span\nflyout, or a view that uses agent config service\n- Confirm the UI
no longer crashes and shows \"Not defined\" (or\nequivalent) for missing
environment where appropriate:\n<img width=\"3456\" height=\"1994\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/21fb7684-2c40-4eb5-b83d-063d9b2437be\"\n/>\n\n\nhttps://github.com/user-attachments/assets/19c46cb3-ff2e-4938-8cf3-2316f7a1a4ae\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"f0e605f119e7adfbae1969e32dfe77ce104baa52"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.4.0","branchLabelMappingKey":"^v9.4.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/254271","number":254271,"mergeCommit":{"message":"[APM]
Fix Otel missing fields undefined errors (#254271)\n\nCloses
#254222\n\n## Summary\n\nThis PR fixes uncaught errors when APM data has
missing `service` or\n`service.environment` (e.g. OpenTelemetry or
incomplete documents). The\nUI was reading
`error.service.environment`,\n`transaction.service.environment`, and
similar properties without\noptional chaining, causing \"Cannot read
properties of undefined (reading\n'environment')\" and error boundary
crashes.\n\nThis PR:\n\n- Adds optional chaining and fallbacks to
`ENVIRONMENT_NOT_DEFINED` /\n`getEnvironmentLabel` where service or
environment may be missing\n- Updates **error group details**: error
sample detail, contextual\ninsight, and sample summary (optional
`error`/`service`, safe access to\n`error.error`)\n- Updates
**transaction/span flyouts**: transaction flyout, view full\ntrace link,
span flyout sticky properties\n- Updates **agent configuration link**:
safe access to\n`configService?.name` and
`configService?.environment`\n\n## How to test\n\n- Use APM with data
that has no `service` or no `service.environment`\n(e.g. OTel or
incomplete documents): If using synthtrace I added a\nscenario:\n- Run
`node scripts/synthtrace missing_service_environment
--from=now-1h\n--to=now+1h`\n- Confirm that the service.environment is
not in the document and there\nis no error in the flyout:\n<img
width=\"3446\" height=\"1962\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/04867ef0-f89b-4601-b0bf-381a795ab2a6\"\n/>\n-
Open error group details and an error sample, transaction flyout,
span\nflyout, or a view that uses agent config service\n- Confirm the UI
no longer crashes and shows \"Not defined\" (or\nequivalent) for missing
environment where appropriate:\n<img width=\"3456\" height=\"1994\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/21fb7684-2c40-4eb5-b83d-063d9b2437be\"\n/>\n\n\nhttps://github.com/user-attachments/assets/19c46cb3-ff2e-4938-8cf3-2316f7a1a4ae\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"f0e605f119e7adfbae1969e32dfe77ce104baa52"}}]}]
BACKPORT-->
nreese pushed a commit to nreese/kibana that referenced this pull request Feb 25, 2026
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>
qn895 pushed a commit to qn895/kibana that referenced this pull request Mar 11, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:all-open Backport to all branches that could still receive a release release_note:skip Skip the PR/issue when compiling release notes Team:obs-presentation Focus: APM UI, Infra UI, Hosts UI, Universal Profiling, Obs Overview and left Navigation v8.19.12 v9.2.6 v9.3.1 v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[APM] Cannot read properties of undefined (reading 'environment') (OTel / missing service.environment)

6 participants