Skip to content

Commit cfee70c

Browse files
committed
fix stripped query string
1 parent df40bff commit cfee70c

2 files changed

Lines changed: 29 additions & 11 deletions

File tree

packages/ember/addon/utils/instrumentEmberAppInstanceForPerformance.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,12 @@ function buildUrlTemplate(path: string, params: Record<string, unknown> = {}): s
102102
}
103103

104104
// Only exported for testing
105-
export function _getRouteUrlAttributes(
106-
url: string,
107-
params: Record<string, unknown> = {},
108-
): Record<string, string> {
105+
export function _getRouteUrlAttributes(url: string, params: Record<string, unknown> = {}): Record<string, string> {
109106
const path = getUrlPathFromEmberLocation(url);
110107

111108
return {
112109
[URL_PATH]: path,
113-
[URL_FULL]: getAbsoluteUrl(path),
110+
[URL_FULL]: getAbsoluteUrl(url || path),
114111
[URL_TEMPLATE]: buildUrlTemplate(path, params),
115112
};
116113
}
@@ -180,8 +177,7 @@ function _instrumentEmberRouter(
180177

181178
activeRootSpan?.end();
182179

183-
const targetUrl =
184-
(transition as TransitionWithIntent).intent?.url ?? _getLocationURL(location);
180+
const targetUrl = (transition as TransitionWithIntent).intent?.url ?? _getLocationURL(location);
185181
const urlAttributes = _getRouteUrlAttributes(targetUrl, transition.to?.params);
186182

187183
activeRootSpan = startBrowserTracingNavigationSpan(client, {

packages/ember/tests/unit/instrument-router-location-test.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import type { EmberRouterMain } from '@sentry/ember/addon/types';
2-
import {
3-
_getLocationURL,
4-
_getRouteUrlAttributes,
5-
} from '@sentry/ember/utils/instrumentEmberAppInstanceForPerformance';
2+
import { _getLocationURL, _getRouteUrlAttributes } from '@sentry/ember/utils/instrumentEmberAppInstanceForPerformance';
63
import { setupTest } from 'ember-qunit';
74
import { module, test } from 'qunit';
85
import type { SentryTestContext } from '../helpers/setup-sentry';
@@ -124,4 +121,29 @@ module('Unit | Utility | instrument-router-location', function (hooks) {
124121
assert.strictEqual(result['url.template'], '/tracing');
125122
assert.ok(result['url.full']?.includes('/tracing'), 'url.full includes the path');
126123
});
124+
125+
test('_getRouteUrlAttributes preserves query string in url.full', function (this: SentryTestContext, assert) {
126+
const result = _getRouteUrlAttributes('/tracing?foo=bar');
127+
128+
assert.strictEqual(result['url.path'], '/tracing');
129+
assert.strictEqual(result['url.template'], '/tracing');
130+
assert.ok(result['url.full']?.includes('?foo=bar'), 'url.full includes the query string');
131+
assert.notOk(result['url.full']?.endsWith('/tracing'), 'url.full is not path-only');
132+
});
133+
134+
test('_getRouteUrlAttributes preserves query string with route params', function (this: SentryTestContext, assert) {
135+
const result = _getRouteUrlAttributes('/users/123?page=2', { user_id: '123' });
136+
137+
assert.strictEqual(result['url.path'], '/users/123');
138+
assert.strictEqual(result['url.template'], '/users/:user_id');
139+
assert.ok(result['url.full']?.includes('/users/123?page=2'), 'url.full includes path and query string');
140+
});
141+
142+
test('_getRouteUrlAttributes preserves query string for hash location', function (this: SentryTestContext, assert) {
143+
const result = _getRouteUrlAttributes('/#/tracing?foo=bar');
144+
145+
assert.strictEqual(result['url.path'], '/tracing');
146+
assert.strictEqual(result['url.template'], '/tracing');
147+
assert.ok(result['url.full']?.includes('?foo=bar'), 'url.full includes the query string');
148+
});
127149
});

0 commit comments

Comments
 (0)