[APM] Fix Otel missing fields undefined errors#254271
Conversation
…ot-read-properties-of-undefined-reading-environment-otel-missing-serviceenvironment
|
Pinging @elastic/obs-presentation-team (Team:obs-presentation) |
💚 Build Succeeded
Metrics [docs]Async chunks
History
|
| /* | ||
| * 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. | ||
| */ | ||
|
|
There was a problem hiding this comment.
Duplicate copywright
| /* | |
| * 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. | |
| */ |
| /* | ||
| * 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. | ||
| */ | ||
|
|
There was a problem hiding this comment.
Duplicate copywright
| /* | |
| * 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. | |
| */ |
smith
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
| const logMessage = error.error.log?.message; | |
| const excMessage = error?.error?.exception?.[0]?.message || error?.error?.message; |
There was a problem hiding this comment.
Good catch, thanks! fixed ✅
cauemarcondes
left a comment
There was a problem hiding this comment.
Synthtrace chages LGTM
|
Starting backport for target branches: 8.19, 9.2, 9.3 https://github.com/elastic/kibana/actions/runs/22345992671 |
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
…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) ...
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
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
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. 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: # 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
# 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-->
# 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-->
) # 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-->
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>
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>
Closes #254222
Summary
This PR fixes uncaught errors when APM data has missing
serviceorservice.environment(e.g. OpenTelemetry or incomplete documents). The UI was readingerror.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:
ENVIRONMENT_NOT_DEFINED/getEnvironmentLabelwhere service or environment may be missingerror/service, safe access toerror.error)configService?.nameandconfigService?.environmentHow to test
serviceor noservice.environment(e.g. OTel or incomplete documents): If using synthtrace I added a scenario:node scripts/synthtrace missing_service_environment --from=now-1h --to=now+1hservice_env_checks.mov