1- import { URL_FULL } from '@sentry/conventions/attributes' ;
1+ import {
2+ HTTP_FRAGMENT ,
3+ HTTP_QUERY ,
4+ HTTP_ROUTE ,
5+ SERVER_ADDRESS ,
6+ URL_DOMAIN ,
7+ URL_FRAGMENT ,
8+ URL_FULL ,
9+ URL_PATH ,
10+ URL_PORT ,
11+ URL_QUERY ,
12+ URL_SCHEME ,
13+ URL_TEMPLATE ,
14+ } from '@sentry/conventions/attributes' ;
215import {
316 SEMANTIC_ATTRIBUTE_HTTP_REQUEST_METHOD ,
417 SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
@@ -165,7 +178,7 @@ export function getHttpSpanDetailsFromUrlObject(
165178
166179 if ( routeName ) {
167180 // This is based on https://opentelemetry.io/docs/specs/semconv/http/http-spans/#name
168- attributes [ kind === 'server' ? 'http.route' : 'url.template' ] = routeName ;
181+ attributes [ kind === 'server' ? HTTP_ROUTE : URL_TEMPLATE ] = routeName ;
169182 attributes [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] = 'route' ;
170183 }
171184
@@ -175,13 +188,19 @@ export function getHttpSpanDetailsFromUrlObject(
175188
176189 if ( urlObject ) {
177190 if ( urlObject . search ) {
178- attributes [ 'url.query' ] = urlObject . search ;
191+ const query = urlObject . search . slice ( 1 ) || undefined ;
192+ attributes [ URL_QUERY ] = query ;
193+ // legacy attribute
194+ attributes [ HTTP_QUERY ] = query ;
179195 }
180196 if ( urlObject . hash ) {
181- attributes [ 'url.fragment' ] = urlObject . hash ;
197+ const fragment = urlObject . hash . slice ( 1 ) || undefined ;
198+ attributes [ URL_FRAGMENT ] = fragment ;
199+ // legacy attribute
200+ attributes [ HTTP_FRAGMENT ] = fragment ;
182201 }
183202 if ( urlObject . pathname ) {
184- attributes [ 'url.path' ] = urlObject . pathname ;
203+ attributes [ URL_PATH ] = urlObject . pathname ;
185204 if ( urlObject . pathname === '/' ) {
186205 attributes [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] = 'route' ;
187206 }
@@ -190,14 +209,15 @@ export function getHttpSpanDetailsFromUrlObject(
190209 if ( ! isURLObjectRelative ( urlObject ) ) {
191210 attributes [ URL_FULL ] = urlObject . href ;
192211 if ( urlObject . port ) {
193- attributes [ 'url.port' ] = urlObject . port ;
212+ attributes [ URL_PORT ] = urlObject . port ;
194213 }
195214 if ( urlObject . protocol ) {
196- attributes [ 'url.scheme' ] = urlObject . protocol ;
215+ attributes [ URL_SCHEME ] = urlObject . protocol ;
197216 }
198217 if ( urlObject . hostname ) {
199- attributes [ kind === 'server' ? 'server.address' : 'url.domain' ] = urlObject . hostname ;
218+ attributes [ kind === 'server' ? SERVER_ADDRESS : URL_DOMAIN ] = urlObject . hostname ;
200219 }
220+ attributes [ 'url' ] = getSanitizedUrlStringFromUrlObject ( urlObject ) ;
201221 }
202222 }
203223
0 commit comments