Skip to content

Commit dc6cd57

Browse files
adinauerclaude
andcommitted
fix(opentelemetry): Normalize legacy HTTP target descriptions
Exclude query parameters and fragments when deriving Sentry span descriptions from the legacy http.target attribute. Leave the completed OpenTelemetry attribute unchanged. Refs #5666 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fa2f138 commit dc6cd57

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

‎sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/SpanDescriptionExtractor.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ private OtelSpanInfo descriptionForHttpMethod(
7272
final @Nullable String httpTarget = attributes.get(HttpIncubatingAttributes.HTTP_TARGET);
7373
final @Nullable String httpRoute = attributes.get(HttpAttributes.HTTP_ROUTE);
7474
@Nullable String httpPath = httpRoute;
75-
if (httpPath == null) {
76-
httpPath = httpTarget;
75+
if (httpPath == null && httpTarget != null) {
76+
httpPath = UrlUtils.parse(httpTarget).getUrl();
7777
}
7878
final @NotNull String op = opBuilder.toString();
7979

‎sentry-opentelemetry/sentry-opentelemetry-core/src/test/kotlin/SpanDescriptionExtractorTest.kt‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class SpanDescriptionExtractorTest {
132132
}
133133

134134
@Test
135-
fun `uses HTTP_TARGET for description`() {
135+
fun `uses HTTP_ROUTE over HTTP_TARGET for description`() {
136136
givenSpanKind(SpanKind.SERVER)
137137
givenAttributes(
138138
mapOf(
@@ -150,6 +150,23 @@ class SpanDescriptionExtractorTest {
150150
assertEquals(TransactionNameSource.ROUTE, info.transactionNameSource)
151151
}
152152

153+
@Test
154+
fun `removes query and fragment from HTTP_TARGET description`() {
155+
givenSpanKind(SpanKind.SERVER)
156+
givenAttributes(
157+
mapOf(
158+
HttpAttributes.HTTP_REQUEST_METHOD to "GET",
159+
HttpIncubatingAttributes.HTTP_TARGET to "/checkout?page=1&token=secret#details",
160+
)
161+
)
162+
163+
val info = whenExtractingSpanInfo()
164+
165+
assertEquals("http.server", info.op)
166+
assertEquals("GET /checkout", info.description)
167+
assertEquals(TransactionNameSource.URL, info.transactionNameSource)
168+
}
169+
153170
@Test
154171
fun `uses span name as description fallback`() {
155172
givenSpanKind(SpanKind.SERVER)

0 commit comments

Comments
 (0)