@@ -24,6 +24,7 @@ import io.sentry.util.Platform
2424import io.sentry.util.PropagationTargetsUtils
2525import io.sentry.util.SpanUtils
2626import io.sentry.util.TracingUtils
27+ import io.sentry.util.UrlUtils
2728import kotlinx.coroutines.withContext
2829
2930/* * Configuration for the Sentry Ktor client plugin. */
@@ -98,20 +99,20 @@ public val SentryKtorClientPlugin: ClientPlugin<SentryKtorClientPluginConfig> =
9899 val requestSpanKey = AttributeKey <ISpan >(" SentryRequestSpan" )
99100
100101 onRequest { request, _ ->
102+ val effectiveScopes = if (forceScopes) scopes else Sentry .getCurrentScopes()
101103 request.attributes.put(
102104 requestStartTimestampKey,
103- ( if (forceScopes) scopes else Sentry .getCurrentScopes()) .options.dateProvider.now(),
105+ effectiveScopes .options.dateProvider.now(),
104106 )
105107
106108 val parentSpan: ISpan ? =
107109 if (forceScopes) scopes.getSpan()
108- else {
109- val currentScopes = Sentry .getCurrentScopes()
110- if (Platform .isAndroid()) currentScopes.transaction else currentScopes.span
111- }
110+ else if (Platform .isAndroid()) effectiveScopes.transaction else effectiveScopes.span
112111
113112 val spanOp = " http.client"
114- val spanDescription = " ${request.method.value.toString()} ${request.url.buildString()} "
113+ val rawUrl = request.url.buildString()
114+ val urlDetails = UrlUtils .parse(rawUrl, effectiveScopes.options.dataCollectionResolver)
115+ val spanDescription = " ${request.method.value.toString()} ${urlDetails.urlOrFallback} "
115116 val span: ISpan ? = parentSpan?.startChild(spanOp, spanDescription)
116117 if (span != null ) {
117118 span.spanContext.origin = TRACE_ORIGIN
@@ -120,13 +121,13 @@ public val SentryKtorClientPlugin: ClientPlugin<SentryKtorClientPluginConfig> =
120121
121122 if (
122123 ! SpanUtils .isIgnored(
123- ( if (forceScopes) scopes else Sentry .getCurrentScopes()) .options.getIgnoredSpanOrigins(),
124+ effectiveScopes .options.getIgnoredSpanOrigins(),
124125 TRACE_ORIGIN ,
125126 )
126127 ) {
127128 TracingUtils .traceIfAllowed(
128- if (forceScopes) scopes else Sentry .getCurrentScopes() ,
129- request.url.buildString() ,
129+ effectiveScopes ,
130+ rawUrl ,
130131 request.headers.getAll(BaggageHeader .BAGGAGE_HEADER ),
131132 span,
132133 )
0 commit comments