Skip to content

Comments

[APM][OTel] Encode service name in the APM URLs#217092

Merged
jennypavlova merged 30 commits intoelastic:mainfrom
jennypavlova:213943-encode-url-path
Apr 16, 2025
Merged

[APM][OTel] Encode service name in the APM URLs#217092
jennypavlova merged 30 commits intoelastic:mainfrom
jennypavlova:213943-encode-url-path

Conversation

@jennypavlova
Copy link
Member

@jennypavlova jennypavlova commented Apr 3, 2025

Closes #213943

Summary

This PR ensures the service name is always encoded in the APM UIs. It's a follow-up of #215031 and aims to find a better solution to the problem:

  • Add the encoding directly to formatRequest as suggested there
  • I saw that there are many places where we use legacy Url builders, so I will try to replace them where possible and use
    apm router link method where the path is encoded (ref)
  • The PR includes the changes to address the issue above:
    • Replaced and removed LegacyAPMLink
    • Refactored useAPMHref to support encoding (and extracted and test the encoding logic)
      • Example usage:
        • Before:
           useAPMHref({
                path: `/services/${serviceName}/.....`,
                persistedFilters,
           });
        • After:
          useAPMHref({
              path: '/services/{serviceName}/.......}',
              pathParams: { serviceName },
              persistedFilters,
         });
    • Used the APM router link method as much as possible

Testing

  • Run node scripts/synthtrace trace_with_service_names_with_slashes.ts --clean --live --uniqueIds --live
  • Go to service inventory and click the links:
apm_links_test.mov

@jennypavlova jennypavlova self-assigned this Apr 3, 2025
return addBasePath(
basePath,
`/app/apm/services/${serviceName}/overview/?rangeFrom=${dateRangeStart}&rangeTo=${dateRangeEnd}`
`/app/apm/services/${encodeURIComponent(
Copy link
Member Author

Choose a reason for hiding this comment

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

This is probably not needed as it's legacy_uptime but changed that and the test anyway

@jennypavlova
Copy link
Member Author

/ci

@jennypavlova
Copy link
Member Author

/ci

@jennypavlova
Copy link
Member Author

/ci

@jennypavlova jennypavlova marked this pull request as ready for review April 7, 2025 17:47
@jennypavlova jennypavlova requested review from a team as code owners April 7, 2025 17:47
@jennypavlova jennypavlova requested review from a team April 7, 2025 17:47
@jennypavlova jennypavlova requested a review from a team as a code owner April 7, 2025 17:47
@jennypavlova jennypavlova added release_note:enhancement backport:prev-minor Team:obs-ux-infra_services - DEPRECATED DEPRECATED - Use Team:obs-presentation. backport:version Backport to applied version labels labels Apr 7, 2025
@jennypavlova jennypavlova enabled auto-merge (squash) April 16, 2025 08:50
@jennypavlova jennypavlova merged commit f816e7b into elastic:main Apr 16, 2025
10 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.18, 8.x, 9.0

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

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Jest Integration Tests #6 / EsqlService can load ES|QL Autocomplete/Validation indices for JOIN command

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
aiAssistantManagementSelection 64 65 +1
apm 1890 1892 +2
inventory 234 235 +1
observabilityAIAssistantApp 440 441 +1
observabilityAiAssistantManagement 387 388 +1
profiling 290 291 +1
streamsApp 442 443 +1
ux 180 181 +1
total +9

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/typed-react-router-config 92 95 +3

Async chunks

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

id before after diff
aiAssistantManagementSelection 73.0KB 73.1KB +67.0B
apm 2.6MB 2.6MB -8.2KB
inventory 191.9KB 192.0KB +66.0B
observabilityAIAssistantApp 251.2KB 251.2KB +67.0B
observabilityAiAssistantManagement 92.0KB 92.1KB +67.0B
observabilityOnboarding 111.4KB 111.5KB +80.0B
profiling 383.9KB 383.9KB +75.0B
streamsApp 407.7KB 407.8KB +75.0B
uptime 503.7KB 503.8KB +20.0B
ux 149.6KB 149.7KB +107.0B
total -7.6KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
apm 35.1KB 35.0KB -23.0B
entityManager 8.3KB 8.3KB +40.0B
inventory 13.5KB 13.6KB +39.0B
observabilityAIAssistant 38.5KB 38.6KB +40.0B
observabilityShared 86.6KB 86.6KB +20.0B
slo 42.5KB 42.5KB +40.0B
streams 6.6KB 6.6KB +40.0B
total +196.0B
Unknown metric groups

API count

id before after diff
@kbn/typed-react-router-config 92 95 +3

History

cc @jennypavlova

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.18 Backport failed because of merge conflicts
8.x Backport failed because of merge conflicts
9.0 Backport failed because of merge conflicts

You might need to backport the following PRs to 9.0:
- [APM][OTel] EDOT error summary fix (#217885)

Manual backport

To create the backport manually run:

node scripts/backport --pr 217092

Questions ?

Please refer to the Backport tool documentation

jennypavlova added a commit to jennypavlova/kibana that referenced this pull request Apr 16, 2025
Closes elastic#213943

## Summary

This PR ensures the service name is always encoded in the APM UIs. It's
a follow-up of elastic#215031 and aims to
find a better solution to the problem:
- Add the encoding directly to `formatRequest` as suggested there
- I saw that there are many places where we use legacy Url builders, so
I will try to replace them where possible and use
apm router link method where the path is encoded
([ref](https://github.com/elastic/kibana/blob/7158e0201bf6becb4f2b821fb693bf6ed6365b54/src/platform/packages/shared/kbn-typed-react-router-config/src/create_router.ts#L184-L185))
- The PR includes the changes to address the issue above:
   - Replaced and removed `LegacyAPMLink`
- Refactored `useAPMHref` to support encoding (and extracted and test
the encoding logic)
     - Example usage:
        - Before:
        ```js
           useAPMHref({
                path: `/services/${serviceName}/.....`,
                persistedFilters,
           });
        ```
        - After:
        ```js
          useAPMHref({
              path: '/services/{serviceName}/.......}',
              pathParams: { serviceName },
              persistedFilters,
         });
        ```
   - Used the APM router link method as much as possible

## Testing
- Run `node scripts/synthtrace trace_with_service_names_with_slashes.ts
--clean --live --uniqueIds --live`
- Go to service inventory and click the links:

https://github.com/user-attachments/assets/fcd4fbfc-4125-4cc8-9b00-53c5f375423f
(cherry picked from commit f816e7b)

# Conflicts:
#	x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/e2e/service_overview/otel_service_overview_and_transactions.cy.ts
#	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 Apr 16, 2025
Closes elastic#213943

## Summary

This PR ensures the service name is always encoded in the APM UIs. It's
a follow-up of elastic#215031 and aims to
find a better solution to the problem:
- Add the encoding directly to `formatRequest` as suggested there
- I saw that there are many places where we use legacy Url builders, so
I will try to replace them where possible and use
apm router link method where the path is encoded
([ref](https://github.com/elastic/kibana/blob/7158e0201bf6becb4f2b821fb693bf6ed6365b54/src/platform/packages/shared/kbn-typed-react-router-config/src/create_router.ts#L184-L185))
- The PR includes the changes to address the issue above:
   - Replaced and removed `LegacyAPMLink`
- Refactored `useAPMHref` to support encoding (and extracted and test
the encoding logic)
     - Example usage:
        - Before:
        ```js
           useAPMHref({
                path: `/services/${serviceName}/.....`,
                persistedFilters,
           });
        ```
        - After:
        ```js
          useAPMHref({
              path: '/services/{serviceName}/.......}',
              pathParams: { serviceName },
              persistedFilters,
         });
        ```
   - Used the APM router link method as much as possible

## Testing
- Run `node scripts/synthtrace trace_with_service_names_with_slashes.ts
--clean --live --uniqueIds --live`
- Go to service inventory and click the links:

https://github.com/user-attachments/assets/fcd4fbfc-4125-4cc8-9b00-53c5f375423f
(cherry picked from commit f816e7b)

# Conflicts:
#	x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/e2e/service_overview/otel_service_overview_and_transactions.cy.ts
#	x-pack/solutions/observability/plugins/apm/public/components/app/service_map/controls.tsx
#	x-pack/solutions/observability/plugins/apm/public/components/app/top_traces_overview/trace_list.tsx
#	x-pack/solutions/observability/plugins/apm/public/components/routing/app_root/apm_header_action_menu/anomaly_detection_setup_link.tsx
#	x-pack/solutions/observability/plugins/apm/public/components/shared/charts/timeline/marker/error_marker.tsx
@jennypavlova
Copy link
Member Author

💚 All backports created successfully

Status Branch Result
9.0
8.x
8.18

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 Apr 16, 2025
Closes elastic#213943

## Summary

This PR ensures the service name is always encoded in the APM UIs. It's
a follow-up of elastic#215031 and aims to
find a better solution to the problem:
- Add the encoding directly to `formatRequest` as suggested there
- I saw that there are many places where we use legacy Url builders, so
I will try to replace them where possible and use
apm router link method where the path is encoded
([ref](https://github.com/elastic/kibana/blob/7158e0201bf6becb4f2b821fb693bf6ed6365b54/src/platform/packages/shared/kbn-typed-react-router-config/src/create_router.ts#L184-L185))
- The PR includes the changes to address the issue above:
   - Replaced and removed `LegacyAPMLink`
- Refactored `useAPMHref` to support encoding (and extracted and test
the encoding logic)
     - Example usage:
        - Before:
        ```js
           useAPMHref({
                path: `/services/${serviceName}/.....`,
                persistedFilters,
           });
        ```
        - After:
        ```js
          useAPMHref({
              path: '/services/{serviceName}/.......}',
              pathParams: { serviceName },
              persistedFilters,
         });
        ```
   - Used the APM router link method as much as possible

## Testing
- Run `node scripts/synthtrace trace_with_service_names_with_slashes.ts
--clean --live --uniqueIds --live`
- Go to service inventory and click the links:

https://github.com/user-attachments/assets/fcd4fbfc-4125-4cc8-9b00-53c5f375423f
(cherry picked from commit f816e7b)

# Conflicts:
#	x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/e2e/service_overview/otel_service_overview_and_transactions.cy.ts
#	x-pack/solutions/observability/plugins/apm/public/components/app/error_group_details/error_sampler/error_sample_detail.tsx
#	x-pack/solutions/observability/plugins/apm/public/components/app/service_map/controls.tsx
#	x-pack/solutions/observability/plugins/apm/public/components/app/top_traces_overview/trace_list.tsx
#	x-pack/solutions/observability/plugins/apm/public/components/routing/app_root/apm_header_action_menu/anomaly_detection_setup_link.tsx
#	x-pack/solutions/observability/plugins/apm/public/components/shared/charts/timeline/marker/error_marker.tsx
jennypavlova added a commit that referenced this pull request Apr 16, 2025
…8477)

# Backport

This will backport the following commits from `main` to `8.18`:
- [[APM][OTel] Encode service name in the APM URLs
(#217092)](#217092)

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

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

<!--BACKPORT
[{"author":{"name":"jennypavlova","email":"dzheni.pavlova@elastic.co"},"sourceCommit":{"committedDate":"2025-04-16T15:52:33Z","message":"[APM][OTel]
Encode service name in the APM URLs (#217092)\n\nCloses #213943\n\n##
Summary\n\nThis PR ensures the service name is always encoded in the APM
UIs. It's\na follow-up of #215031
and aims to\nfind a better solution to the problem:\n- Add the encoding
directly to `formatRequest` as suggested there\n- I saw that there are
many places where we use legacy Url builders, so\nI will try to replace
them where possible and use\napm router link method where the path is
encoded\n([ref](https://github.com/elastic/kibana/blob/7158e0201bf6becb4f2b821fb693bf6ed6365b54/src/platform/packages/shared/kbn-typed-react-router-config/src/create_router.ts#L184-L185))\n-
The PR includes the changes to address the issue above:\n - Replaced and
removed `LegacyAPMLink`\n- Refactored `useAPMHref` to support encoding
(and extracted and test\nthe encoding logic)\n - Example usage: \n -
Before: \n ```js\n useAPMHref({\n path:
`/services/${serviceName}/.....`,\n persistedFilters,\n });\n ```\n -
After:\n ```js\n useAPMHref({\n path:
'/services/{serviceName}/.......}',\n pathParams: { serviceName },\n
persistedFilters,\n });\n ```\n - Used the APM router link method as
much as possible\n\n\n## Testing\n- Run `node scripts/synthtrace
trace_with_service_names_with_slashes.ts\n--clean --live --uniqueIds
--live`\n- Go to service inventory and click the
links:\n\n\nhttps://github.com/user-attachments/assets/fcd4fbfc-4125-4cc8-9b00-53c5f375423f","sha":"f816e7b84f94d9af8d3fffb85dc83512f31c55e9","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","v9.0.0","backport:prev-minor","Team:obs-ux-infra_services","backport:version","v8.18.0","v9.1.0","v8.19.0"],"title":"[APM][OTel]
Encode service name in the APM
URLs","number":217092,"url":"https://github.com/elastic/kibana/pull/217092","mergeCommit":{"message":"[APM][OTel]
Encode service name in the APM URLs (#217092)\n\nCloses #213943\n\n##
Summary\n\nThis PR ensures the service name is always encoded in the APM
UIs. It's\na follow-up of #215031
and aims to\nfind a better solution to the problem:\n- Add the encoding
directly to `formatRequest` as suggested there\n- I saw that there are
many places where we use legacy Url builders, so\nI will try to replace
them where possible and use\napm router link method where the path is
encoded\n([ref](https://github.com/elastic/kibana/blob/7158e0201bf6becb4f2b821fb693bf6ed6365b54/src/platform/packages/shared/kbn-typed-react-router-config/src/create_router.ts#L184-L185))\n-
The PR includes the changes to address the issue above:\n - Replaced and
removed `LegacyAPMLink`\n- Refactored `useAPMHref` to support encoding
(and extracted and test\nthe encoding logic)\n - Example usage: \n -
Before: \n ```js\n useAPMHref({\n path:
`/services/${serviceName}/.....`,\n persistedFilters,\n });\n ```\n -
After:\n ```js\n useAPMHref({\n path:
'/services/{serviceName}/.......}',\n pathParams: { serviceName },\n
persistedFilters,\n });\n ```\n - Used the APM router link method as
much as possible\n\n\n## Testing\n- Run `node scripts/synthtrace
trace_with_service_names_with_slashes.ts\n--clean --live --uniqueIds
--live`\n- Go to service inventory and click the
links:\n\n\nhttps://github.com/user-attachments/assets/fcd4fbfc-4125-4cc8-9b00-53c5f375423f","sha":"f816e7b84f94d9af8d3fffb85dc83512f31c55e9"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217092","number":217092,"mergeCommit":{"message":"[APM][OTel]
Encode service name in the APM URLs (#217092)\n\nCloses #213943\n\n##
Summary\n\nThis PR ensures the service name is always encoded in the APM
UIs. It's\na follow-up of #215031
and aims to\nfind a better solution to the problem:\n- Add the encoding
directly to `formatRequest` as suggested there\n- I saw that there are
many places where we use legacy Url builders, so\nI will try to replace
them where possible and use\napm router link method where the path is
encoded\n([ref](https://github.com/elastic/kibana/blob/7158e0201bf6becb4f2b821fb693bf6ed6365b54/src/platform/packages/shared/kbn-typed-react-router-config/src/create_router.ts#L184-L185))\n-
The PR includes the changes to address the issue above:\n - Replaced and
removed `LegacyAPMLink`\n- Refactored `useAPMHref` to support encoding
(and extracted and test\nthe encoding logic)\n - Example usage: \n -
Before: \n ```js\n useAPMHref({\n path:
`/services/${serviceName}/.....`,\n persistedFilters,\n });\n ```\n -
After:\n ```js\n useAPMHref({\n path:
'/services/{serviceName}/.......}',\n pathParams: { serviceName },\n
persistedFilters,\n });\n ```\n - Used the APM router link method as
much as possible\n\n\n## Testing\n- Run `node scripts/synthtrace
trace_with_service_names_with_slashes.ts\n--clean --live --uniqueIds
--live`\n- Go to service inventory and click the
links:\n\n\nhttps://github.com/user-attachments/assets/fcd4fbfc-4125-4cc8-9b00-53c5f375423f","sha":"f816e7b84f94d9af8d3fffb85dc83512f31c55e9"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
jennypavlova added a commit that referenced this pull request Apr 16, 2025
)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[APM][OTel] Encode service name in the APM URLs
(#217092)](#217092)

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

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

<!--BACKPORT
[{"author":{"name":"jennypavlova","email":"dzheni.pavlova@elastic.co"},"sourceCommit":{"committedDate":"2025-04-16T15:52:33Z","message":"[APM][OTel]
Encode service name in the APM URLs (#217092)\n\nCloses #213943\n\n##
Summary\n\nThis PR ensures the service name is always encoded in the APM
UIs. It's\na follow-up of #215031
and aims to\nfind a better solution to the problem:\n- Add the encoding
directly to `formatRequest` as suggested there\n- I saw that there are
many places where we use legacy Url builders, so\nI will try to replace
them where possible and use\napm router link method where the path is
encoded\n([ref](https://github.com/elastic/kibana/blob/7158e0201bf6becb4f2b821fb693bf6ed6365b54/src/platform/packages/shared/kbn-typed-react-router-config/src/create_router.ts#L184-L185))\n-
The PR includes the changes to address the issue above:\n - Replaced and
removed `LegacyAPMLink`\n- Refactored `useAPMHref` to support encoding
(and extracted and test\nthe encoding logic)\n - Example usage: \n -
Before: \n ```js\n useAPMHref({\n path:
`/services/${serviceName}/.....`,\n persistedFilters,\n });\n ```\n -
After:\n ```js\n useAPMHref({\n path:
'/services/{serviceName}/.......}',\n pathParams: { serviceName },\n
persistedFilters,\n });\n ```\n - Used the APM router link method as
much as possible\n\n\n## Testing\n- Run `node scripts/synthtrace
trace_with_service_names_with_slashes.ts\n--clean --live --uniqueIds
--live`\n- Go to service inventory and click the
links:\n\n\nhttps://github.com/user-attachments/assets/fcd4fbfc-4125-4cc8-9b00-53c5f375423f","sha":"f816e7b84f94d9af8d3fffb85dc83512f31c55e9","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","v9.0.0","backport:prev-minor","Team:obs-ux-infra_services","backport:version","v8.18.0","v9.1.0","v8.19.0"],"title":"[APM][OTel]
Encode service name in the APM
URLs","number":217092,"url":"https://github.com/elastic/kibana/pull/217092","mergeCommit":{"message":"[APM][OTel]
Encode service name in the APM URLs (#217092)\n\nCloses #213943\n\n##
Summary\n\nThis PR ensures the service name is always encoded in the APM
UIs. It's\na follow-up of #215031
and aims to\nfind a better solution to the problem:\n- Add the encoding
directly to `formatRequest` as suggested there\n- I saw that there are
many places where we use legacy Url builders, so\nI will try to replace
them where possible and use\napm router link method where the path is
encoded\n([ref](https://github.com/elastic/kibana/blob/7158e0201bf6becb4f2b821fb693bf6ed6365b54/src/platform/packages/shared/kbn-typed-react-router-config/src/create_router.ts#L184-L185))\n-
The PR includes the changes to address the issue above:\n - Replaced and
removed `LegacyAPMLink`\n- Refactored `useAPMHref` to support encoding
(and extracted and test\nthe encoding logic)\n - Example usage: \n -
Before: \n ```js\n useAPMHref({\n path:
`/services/${serviceName}/.....`,\n persistedFilters,\n });\n ```\n -
After:\n ```js\n useAPMHref({\n path:
'/services/{serviceName}/.......}',\n pathParams: { serviceName },\n
persistedFilters,\n });\n ```\n - Used the APM router link method as
much as possible\n\n\n## Testing\n- Run `node scripts/synthtrace
trace_with_service_names_with_slashes.ts\n--clean --live --uniqueIds
--live`\n- Go to service inventory and click the
links:\n\n\nhttps://github.com/user-attachments/assets/fcd4fbfc-4125-4cc8-9b00-53c5f375423f","sha":"f816e7b84f94d9af8d3fffb85dc83512f31c55e9"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217092","number":217092,"mergeCommit":{"message":"[APM][OTel]
Encode service name in the APM URLs (#217092)\n\nCloses #213943\n\n##
Summary\n\nThis PR ensures the service name is always encoded in the APM
UIs. It's\na follow-up of #215031
and aims to\nfind a better solution to the problem:\n- Add the encoding
directly to `formatRequest` as suggested there\n- I saw that there are
many places where we use legacy Url builders, so\nI will try to replace
them where possible and use\napm router link method where the path is
encoded\n([ref](https://github.com/elastic/kibana/blob/7158e0201bf6becb4f2b821fb693bf6ed6365b54/src/platform/packages/shared/kbn-typed-react-router-config/src/create_router.ts#L184-L185))\n-
The PR includes the changes to address the issue above:\n - Replaced and
removed `LegacyAPMLink`\n- Refactored `useAPMHref` to support encoding
(and extracted and test\nthe encoding logic)\n - Example usage: \n -
Before: \n ```js\n useAPMHref({\n path:
`/services/${serviceName}/.....`,\n persistedFilters,\n });\n ```\n -
After:\n ```js\n useAPMHref({\n path:
'/services/{serviceName}/.......}',\n pathParams: { serviceName },\n
persistedFilters,\n });\n ```\n - Used the APM router link method as
much as possible\n\n\n## Testing\n- Run `node scripts/synthtrace
trace_with_service_names_with_slashes.ts\n--clean --live --uniqueIds
--live`\n- Go to service inventory and click the
links:\n\n\nhttps://github.com/user-attachments/assets/fcd4fbfc-4125-4cc8-9b00-53c5f375423f","sha":"f816e7b84f94d9af8d3fffb85dc83512f31c55e9"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request Apr 17, 2025
Closes elastic#213943

## Summary

This PR ensures the service name is always encoded in the APM UIs. It's
a follow-up of elastic#215031 and aims to
find a better solution to the problem:
- Add the encoding directly to `formatRequest` as suggested there
- I saw that there are many places where we use legacy Url builders, so
I will try to replace them where possible and use
apm router link method where the path is encoded
([ref](https://github.com/elastic/kibana/blob/7158e0201bf6becb4f2b821fb693bf6ed6365b54/src/platform/packages/shared/kbn-typed-react-router-config/src/create_router.ts#L184-L185))
- The PR includes the changes to address the issue above:
   - Replaced and removed `LegacyAPMLink`
- Refactored `useAPMHref` to support encoding (and extracted and test
the encoding logic)
     - Example usage: 
        - Before: 
        ```js
           useAPMHref({
                path: `/services/${serviceName}/.....`,
                persistedFilters,
           });
        ```
        - After:
        ```js
          useAPMHref({
              path: '/services/{serviceName}/.......}',
              pathParams: { serviceName },
              persistedFilters,
         });
        ```
   - Used the APM router link method as much as possible


## Testing
- Run `node scripts/synthtrace trace_with_service_names_with_slashes.ts
--clean --live --uniqueIds --live`
- Go to service inventory and click the links:


https://github.com/user-attachments/assets/fcd4fbfc-4125-4cc8-9b00-53c5f375423f
jennypavlova added a commit that referenced this pull request Apr 17, 2025
)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[APM][OTel] Encode service name in the APM URLs
(#217092)](#217092)

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

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

<!--BACKPORT
[{"author":{"name":"jennypavlova","email":"dzheni.pavlova@elastic.co"},"sourceCommit":{"committedDate":"2025-04-16T15:52:33Z","message":"[APM][OTel]
Encode service name in the APM URLs (#217092)\n\nCloses #213943\n\n##
Summary\n\nThis PR ensures the service name is always encoded in the APM
UIs. It's\na follow-up of #215031
and aims to\nfind a better solution to the problem:\n- Add the encoding
directly to `formatRequest` as suggested there\n- I saw that there are
many places where we use legacy Url builders, so\nI will try to replace
them where possible and use\napm router link method where the path is
encoded\n([ref](https://github.com/elastic/kibana/blob/7158e0201bf6becb4f2b821fb693bf6ed6365b54/src/platform/packages/shared/kbn-typed-react-router-config/src/create_router.ts#L184-L185))\n-
The PR includes the changes to address the issue above:\n - Replaced and
removed `LegacyAPMLink`\n- Refactored `useAPMHref` to support encoding
(and extracted and test\nthe encoding logic)\n - Example usage: \n -
Before: \n ```js\n useAPMHref({\n path:
`/services/${serviceName}/.....`,\n persistedFilters,\n });\n ```\n -
After:\n ```js\n useAPMHref({\n path:
'/services/{serviceName}/.......}',\n pathParams: { serviceName },\n
persistedFilters,\n });\n ```\n - Used the APM router link method as
much as possible\n\n\n## Testing\n- Run `node scripts/synthtrace
trace_with_service_names_with_slashes.ts\n--clean --live --uniqueIds
--live`\n- Go to service inventory and click the
links:\n\n\nhttps://github.com/user-attachments/assets/fcd4fbfc-4125-4cc8-9b00-53c5f375423f","sha":"f816e7b84f94d9af8d3fffb85dc83512f31c55e9","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","v9.0.0","backport:prev-minor","Team:obs-ux-infra_services","backport:version","v8.18.0","v9.1.0","v8.19.0"],"title":"[APM][OTel]
Encode service name in the APM
URLs","number":217092,"url":"https://github.com/elastic/kibana/pull/217092","mergeCommit":{"message":"[APM][OTel]
Encode service name in the APM URLs (#217092)\n\nCloses #213943\n\n##
Summary\n\nThis PR ensures the service name is always encoded in the APM
UIs. It's\na follow-up of #215031
and aims to\nfind a better solution to the problem:\n- Add the encoding
directly to `formatRequest` as suggested there\n- I saw that there are
many places where we use legacy Url builders, so\nI will try to replace
them where possible and use\napm router link method where the path is
encoded\n([ref](https://github.com/elastic/kibana/blob/7158e0201bf6becb4f2b821fb693bf6ed6365b54/src/platform/packages/shared/kbn-typed-react-router-config/src/create_router.ts#L184-L185))\n-
The PR includes the changes to address the issue above:\n - Replaced and
removed `LegacyAPMLink`\n- Refactored `useAPMHref` to support encoding
(and extracted and test\nthe encoding logic)\n - Example usage: \n -
Before: \n ```js\n useAPMHref({\n path:
`/services/${serviceName}/.....`,\n persistedFilters,\n });\n ```\n -
After:\n ```js\n useAPMHref({\n path:
'/services/{serviceName}/.......}',\n pathParams: { serviceName },\n
persistedFilters,\n });\n ```\n - Used the APM router link method as
much as possible\n\n\n## Testing\n- Run `node scripts/synthtrace
trace_with_service_names_with_slashes.ts\n--clean --live --uniqueIds
--live`\n- Go to service inventory and click the
links:\n\n\nhttps://github.com/user-attachments/assets/fcd4fbfc-4125-4cc8-9b00-53c5f375423f","sha":"f816e7b84f94d9af8d3fffb85dc83512f31c55e9"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217092","number":217092,"mergeCommit":{"message":"[APM][OTel]
Encode service name in the APM URLs (#217092)\n\nCloses #213943\n\n##
Summary\n\nThis PR ensures the service name is always encoded in the APM
UIs. It's\na follow-up of #215031
and aims to\nfind a better solution to the problem:\n- Add the encoding
directly to `formatRequest` as suggested there\n- I saw that there are
many places where we use legacy Url builders, so\nI will try to replace
them where possible and use\napm router link method where the path is
encoded\n([ref](https://github.com/elastic/kibana/blob/7158e0201bf6becb4f2b821fb693bf6ed6365b54/src/platform/packages/shared/kbn-typed-react-router-config/src/create_router.ts#L184-L185))\n-
The PR includes the changes to address the issue above:\n - Replaced and
removed `LegacyAPMLink`\n- Refactored `useAPMHref` to support encoding
(and extracted and test\nthe encoding logic)\n - Example usage: \n -
Before: \n ```js\n useAPMHref({\n path:
`/services/${serviceName}/.....`,\n persistedFilters,\n });\n ```\n -
After:\n ```js\n useAPMHref({\n path:
'/services/{serviceName}/.......}',\n pathParams: { serviceName },\n
persistedFilters,\n });\n ```\n - Used the APM router link method as
much as possible\n\n\n## Testing\n- Run `node scripts/synthtrace
trace_with_service_names_with_slashes.ts\n--clean --live --uniqueIds
--live`\n- Go to service inventory and click the
links:\n\n\nhttps://github.com/user-attachments/assets/fcd4fbfc-4125-4cc8-9b00-53c5f375423f","sha":"f816e7b84f94d9af8d3fffb85dc83512f31c55e9"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request May 29, 2025
Closes elastic#213943

## Summary

This PR ensures the service name is always encoded in the APM UIs. It's
a follow-up of elastic#215031 and aims to
find a better solution to the problem:
- Add the encoding directly to `formatRequest` as suggested there
- I saw that there are many places where we use legacy Url builders, so
I will try to replace them where possible and use
apm router link method where the path is encoded
([ref](https://github.com/elastic/kibana/blob/7158e0201bf6becb4f2b821fb693bf6ed6365b54/src/platform/packages/shared/kbn-typed-react-router-config/src/create_router.ts#L184-L185))
- The PR includes the changes to address the issue above:
   - Replaced and removed `LegacyAPMLink`
- Refactored `useAPMHref` to support encoding (and extracted and test
the encoding logic)
     - Example usage: 
        - Before: 
        ```js
           useAPMHref({
                path: `/services/${serviceName}/.....`,
                persistedFilters,
           });
        ```
        - After:
        ```js
          useAPMHref({
              path: '/services/{serviceName}/.......}',
              pathParams: { serviceName },
              persistedFilters,
         });
        ```
   - Used the APM router link method as much as possible


## Testing
- Run `node scripts/synthtrace trace_with_service_names_with_slashes.ts
--clean --live --uniqueIds --live`
- Go to service inventory and click the links:


https://github.com/user-attachments/assets/fcd4fbfc-4125-4cc8-9b00-53c5f375423f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[APM][OTel] The service name should be encoded when used in an URL

7 participants