diff --git a/CHANGELOG.md b/CHANGELOG.md index 3362fa74ea..ffb09d8a43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Features +- Add description to OkHttp spans ([#3320](https://github.com/getsentry/sentry-java/pull/3320)) - Update normalization of metrics keys, tags and values ([#3332](https://github.com/getsentry/sentry-java/pull/3332)) - Enable backpressure management by default ([#3284](https://github.com/getsentry/sentry-java/pull/3284)) diff --git a/sentry-okhttp/src/main/java/io/sentry/okhttp/SentryOkHttpEvent.kt b/sentry-okhttp/src/main/java/io/sentry/okhttp/SentryOkHttpEvent.kt index 00cc26e754..21a3329a14 100644 --- a/sentry-okhttp/src/main/java/io/sentry/okhttp/SentryOkHttpEvent.kt +++ b/sentry-okhttp/src/main/java/io/sentry/okhttp/SentryOkHttpEvent.kt @@ -38,13 +38,15 @@ internal class SentryOkHttpEvent(private val hub: IHub, private val request: Req private var clientErrorResponse: Response? = null private val isReadingResponseBody = AtomicBoolean(false) private val isEventFinished = AtomicBoolean(false) + private val url: String + private val method: String init { val urlDetails = UrlUtils.parse(request.url.toString()) - val url = urlDetails.urlOrFallback + url = urlDetails.urlOrFallback val host: String = request.url.host val encodedPath: String = request.url.encodedPath - val method: String = request.method + method = request.method // We start the call span that will contain all the others val parentSpan = if (Platform.isAndroid()) hub.transaction else hub.span @@ -113,7 +115,7 @@ internal class SentryOkHttpEvent(private val hub: IHub, private val request: Req fun startSpan(event: String) { // Find the parent of the span being created. E.g. secureConnect is child of connect val parentSpan = findParentSpan(event) - val span = parentSpan?.startChild("http.client.$event") ?: return + val span = parentSpan?.startChild("http.client.$event", "$method $url") ?: return if (event == RESPONSE_BODY_EVENT) { // We save this event is reading the response body, so that it will not be auto-finished isReadingResponseBody.set(true) diff --git a/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpEventListenerTest.kt b/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpEventListenerTest.kt index 1d90da70fe..88727c4c0d 100644 --- a/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpEventListenerTest.kt +++ b/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpEventListenerTest.kt @@ -168,28 +168,35 @@ class SentryOkHttpEventListenerTest { } 1 -> { assertEquals("http.client.proxy_select", span.operation) + assertEquals("GET ${request.url}", span.description) assertNotNull(span.data["proxies"]) } 2 -> { assertEquals("http.client.dns", span.operation) + assertEquals("GET ${request.url}", span.description) assertNotNull(span.data["domain_name"]) assertNotNull(span.data["dns_addresses"]) } 3 -> { assertEquals("http.client.connect", span.operation) + assertEquals("GET ${request.url}", span.description) } 4 -> { assertEquals("http.client.connection", span.operation) + assertEquals("GET ${request.url}", span.description) } 5 -> { assertEquals("http.client.request_headers", span.operation) + assertEquals("GET ${request.url}", span.description) } 6 -> { assertEquals("http.client.response_headers", span.operation) + assertEquals("GET ${request.url}", span.description) assertEquals(201, span.data[SpanDataConvention.HTTP_STATUS_CODE_KEY]) } 7 -> { assertEquals("http.client.response_body", span.operation) + assertEquals("GET ${request.url}", span.description) } } } diff --git a/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpEventTest.kt b/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpEventTest.kt index 337f722848..4b41b75c1e 100644 --- a/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpEventTest.kt +++ b/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpEventTest.kt @@ -158,6 +158,7 @@ class SentryOkHttpEventTest { assertNotNull(span) assertTrue(spans.containsKey("span")) assertEquals("http.client.span", span.operation) + assertEquals("${fixture.mockRequest.method} ${fixture.mockRequest.url}", span.description) assertFalse(span.isFinished) } @@ -196,6 +197,7 @@ class SentryOkHttpEventTest { sut.finishSpan("span") { if (called == 0) { assertEquals("http.client.span", it.operation) + assertEquals("${fixture.mockRequest.method} ${fixture.mockRequest.url}", it.description) } else { assertEquals(sut.callRootSpan, it) }