Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes;
import io.sentry.SentryOptions;
import io.sentry.protocol.TransactionNameSource;
import io.sentry.util.UrlUtils;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -71,16 +72,14 @@ private OtelSpanInfo descriptionForHttpMethod(
final @Nullable String httpTarget = attributes.get(HttpIncubatingAttributes.HTTP_TARGET);
final @Nullable String httpRoute = attributes.get(HttpAttributes.HTTP_ROUTE);
@Nullable String httpPath = httpRoute;
if (httpPath == null) {
httpPath = httpTarget;
if (httpPath == null && httpTarget != null) {
httpPath = UrlUtils.parse(httpTarget).getUrl();
}
final @NotNull String op = opBuilder.toString();

final @Nullable String urlFull = attributes.get(UrlAttributes.URL_FULL);
if (urlFull != null) {
if (httpPath == null) {
httpPath = urlFull;
}
if (urlFull != null && httpPath == null) {
httpPath = UrlUtils.parse(urlFull).getUrl();
}

final @Nullable String urlPath = attributes.get(UrlAttributes.URL_PATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class SpanDescriptionExtractorTest {
val info = whenExtractingSpanInfo()

assertEquals("http.server", info.op)
assertEquals("GET https://sentry.io/some/path?q=1#top", info.description)
assertEquals("GET https://sentry.io/some/path", info.description)
assertEquals(TransactionNameSource.URL, info.transactionNameSource)
}

Expand All @@ -132,7 +132,7 @@ class SpanDescriptionExtractorTest {
}

@Test
fun `uses HTTP_TARGET for description`() {
fun `uses HTTP_ROUTE over HTTP_TARGET for description`() {
givenSpanKind(SpanKind.SERVER)
givenAttributes(
mapOf(
Expand All @@ -150,6 +150,23 @@ class SpanDescriptionExtractorTest {
assertEquals(TransactionNameSource.ROUTE, info.transactionNameSource)
}

@Test
fun `removes query and fragment from HTTP_TARGET description`() {
givenSpanKind(SpanKind.SERVER)
givenAttributes(
mapOf(
HttpAttributes.HTTP_REQUEST_METHOD to "GET",
HttpIncubatingAttributes.HTTP_TARGET to "/checkout?page=1&token=secret#details",
)
)

val info = whenExtractingSpanInfo()

assertEquals("http.server", info.op)
assertEquals("GET /checkout", info.description)
assertEquals(TransactionNameSource.URL, info.transactionNameSource)
}

@Test
fun `uses span name as description fallback`() {
givenSpanKind(SpanKind.SERVER)
Expand Down
Loading