@sentry/ember 10.64.0 → 10.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,11 +5,22 @@ import type {
5
5
  startBrowserTracingNavigationSpan as startBrowserTracingNavigationSpanType,
6
6
  startBrowserTracingPageLoadSpan as startBrowserTracingPageLoadSpanType,
7
7
  } from '@sentry/browser';
8
- import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, startInactiveSpan } from '@sentry/browser';
8
+ import {
9
+ getAbsoluteUrl,
10
+ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
11
+ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
12
+ startInactiveSpan,
13
+ } from '@sentry/browser';
9
14
  import type { Client, Span } from '@sentry/core';
10
15
  import type { EmberRouterMain } from '../types';
11
16
  import { getBackburner } from './performance';
12
17
 
18
+ const URL_FULL = 'url.full';
19
+ const URL_PATH = 'url.path';
20
+ const URL_TEMPLATE = 'url.template';
21
+
22
+ type TransitionWithIntent = Transition & { intent?: { url?: string } };
23
+
13
24
  export function instrumentEmberAppInstanceForPerformance(
14
25
  client: Client,
15
26
  appInstance: ApplicationInstance,
@@ -22,6 +33,7 @@ export function instrumentEmberAppInstanceForPerformance(
22
33
  let routerService = appInstance.lookup('service:router') as RouterService & {
23
34
  externalRouter?: RouterService;
24
35
  _hasMountedSentryPerformanceRouting?: boolean;
36
+ currentURL?: string;
25
37
  };
26
38
 
27
39
  if (routerService.externalRouter) {
@@ -60,6 +72,52 @@ function getTransitionInformation(
60
72
  };
61
73
  }
62
74
 
75
+ function getUrlPathFromEmberLocation(url: string): string {
76
+ if (!url) {
77
+ return '/';
78
+ }
79
+
80
+ const withoutQuery = url.split('?')[0] ?? url;
81
+
82
+ if (withoutQuery.includes('#')) {
83
+ const hashPart = withoutQuery.substring(withoutQuery.indexOf('#') + 1);
84
+ return hashPart.startsWith('/') ? hashPart : `/${hashPart}`;
85
+ }
86
+
87
+ return withoutQuery.startsWith('/') ? withoutQuery : `/${withoutQuery}`;
88
+ }
89
+
90
+ function buildUrlTemplate(path: string, params: Record<string, unknown> = {}): string {
91
+ let template = path;
92
+
93
+ const paramEntries = Object.entries(params)
94
+ .filter((entry): entry is [string, string] => typeof entry[1] === 'string' && entry[1].length > 0)
95
+ .sort(([, a], [, b]) => b.length - a.length);
96
+
97
+ for (const [key, value] of paramEntries) {
98
+ template = template.replace(`/${value}`, `/:${key}`);
99
+ }
100
+
101
+ return template;
102
+ }
103
+
104
+ // Only exported for testing
105
+ export function _getRouteUrlAttributes(
106
+ url: string,
107
+ params: Record<string, unknown> = {},
108
+ fullUrl: string = url,
109
+ ): Record<string, string> {
110
+ const path = getUrlPathFromEmberLocation(url);
111
+
112
+ // `url.full` is derived from the unstripped URL so that hash-location apps keep their `#/...`
113
+ // fragment (e.g. `https://host/#/tracing`), which would otherwise be lost by `getUrlPathFromEmberLocation`.
114
+ return {
115
+ [URL_PATH]: path,
116
+ [URL_FULL]: getAbsoluteUrl(fullUrl),
117
+ [URL_TEMPLATE]: buildUrlTemplate(path, params),
118
+ };
119
+ }
120
+
63
121
  // Only exported for testing
64
122
  export function _getLocationURL(location: EmberRouterMain['location']): string {
65
123
  if (!location?.getURL || !location?.formatURL) {
@@ -76,7 +134,7 @@ export function _getLocationURL(location: EmberRouterMain['location']): string {
76
134
 
77
135
  function _instrumentEmberRouter(
78
136
  client: Client,
79
- routerService: RouterService,
137
+ routerService: RouterService & { currentURL?: string },
80
138
  routerMain: EmberRouterMain,
81
139
  config: { disableRunloopPerformance?: boolean; instrumentPageLoad?: boolean; instrumentNavigation?: boolean },
82
140
  startBrowserTracingPageLoadSpan: typeof startBrowserTracingPageLoadSpanType,
@@ -96,6 +154,7 @@ function _instrumentEmberRouter(
96
154
  attributes: {
97
155
  [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
98
156
  [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.ember',
157
+ ..._getRouteUrlAttributes(url, routeInfo.params),
99
158
  url,
100
159
  toRoute: routeInfo.name,
101
160
  },
@@ -124,11 +183,19 @@ function _instrumentEmberRouter(
124
183
 
125
184
  activeRootSpan?.end();
126
185
 
186
+ // Only `intent.url` reliably reflects the *destination* URL at `routeWillChange` time. The
187
+ // router's location still points at the current (pre-transition) route here, so falling back to
188
+ // it would tag the navigation span with the previous route's `url.*` attributes. When we don't
189
+ // have a trustworthy target URL, we omit them and let `routeDidChange` set them from `currentURL`.
190
+ const targetUrl = (transition as TransitionWithIntent).intent?.url;
191
+ const urlAttributes = targetUrl ? _getRouteUrlAttributes(targetUrl, transition.to?.params) : {};
192
+
127
193
  activeRootSpan = startBrowserTracingNavigationSpan(client, {
128
194
  name: `route:${toRoute}`,
129
195
  attributes: {
130
196
  [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
131
197
  [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.ember',
198
+ ...urlAttributes,
132
199
  fromRoute,
133
200
  toRoute,
134
201
  },
@@ -150,6 +217,15 @@ function _instrumentEmberRouter(
150
217
  }
151
218
  transitionSpan.end();
152
219
 
220
+ const url = routerService.currentURL ?? _getLocationURL(location);
221
+ if (url) {
222
+ const routeInfo = routerService.recognize(url);
223
+ // `currentURL` is the normalized route path and never includes the hash fragment, so we source
224
+ // `url.full` from the location URL (which preserves `#/...` for hash-location apps) when available.
225
+ const fullUrl = _getLocationURL(location) || url;
226
+ activeRootSpan.setAttributes(_getRouteUrlAttributes(url, routeInfo.params ?? transition.to?.params, fullUrl));
227
+ }
228
+
153
229
  if (disableRunloopPerformance) {
154
230
  activeRootSpan.end();
155
231
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/ember",
3
- "version": "10.64.0",
3
+ "version": "10.66.0",
4
4
  "description": "Official Sentry SDK for Ember.js",
5
5
  "repository": "git://github.com/getsentry/sentry-javascript.git",
6
6
  "homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/ember",
@@ -32,8 +32,8 @@
32
32
  "dependencies": {
33
33
  "@babel/core": "^7.29.6",
34
34
  "@embroider/macros": "^1.16.0",
35
- "@sentry/browser": "10.64.0",
36
- "@sentry/core": "10.64.0",
35
+ "@sentry/browser": "10.66.0",
36
+ "@sentry/core": "10.66.0",
37
37
  "ember-auto-import": "^2.7.2",
38
38
  "ember-cli-babel": "^8.2.0",
39
39
  "ember-cli-htmlbars": "^6.1.1",
@@ -7,4 +7,5 @@ export declare function instrumentEmberAppInstanceForPerformance(client: Client,
7
7
  instrumentPageLoad?: boolean;
8
8
  instrumentNavigation?: boolean;
9
9
  }, startBrowserTracingPageLoadSpan: typeof startBrowserTracingPageLoadSpanType, startBrowserTracingNavigationSpan: typeof startBrowserTracingNavigationSpanType): void;
10
+ export declare function _getRouteUrlAttributes(url: string, params?: Record<string, unknown>, fullUrl?: string): Record<string, string>;
10
11
  export declare function _getLocationURL(location: EmberRouterMain['location']): string;