Skip to content

Commit 0d65ef7

Browse files
authored
Add description to OkHttp spans (#3320)
* added description to OkHttp sub-spans
1 parent 39e8942 commit 0d65ef7

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Features
66

7+
- Add description to OkHttp spans ([#3320](https://github.com/getsentry/sentry-java/pull/3320))
78
- Update normalization of metrics keys, tags and values ([#3332](https://github.com/getsentry/sentry-java/pull/3332))
89
- Enable backpressure management by default ([#3284](https://github.com/getsentry/sentry-java/pull/3284))
910

sentry-okhttp/src/main/java/io/sentry/okhttp/SentryOkHttpEvent.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ internal class SentryOkHttpEvent(private val hub: IHub, private val request: Req
3838
private var clientErrorResponse: Response? = null
3939
private val isReadingResponseBody = AtomicBoolean(false)
4040
private val isEventFinished = AtomicBoolean(false)
41+
private val url: String
42+
private val method: String
4143

4244
init {
4345
val urlDetails = UrlUtils.parse(request.url.toString())
44-
val url = urlDetails.urlOrFallback
46+
url = urlDetails.urlOrFallback
4547
val host: String = request.url.host
4648
val encodedPath: String = request.url.encodedPath
47-
val method: String = request.method
49+
method = request.method
4850

4951
// We start the call span that will contain all the others
5052
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
113115
fun startSpan(event: String) {
114116
// Find the parent of the span being created. E.g. secureConnect is child of connect
115117
val parentSpan = findParentSpan(event)
116-
val span = parentSpan?.startChild("http.client.$event") ?: return
118+
val span = parentSpan?.startChild("http.client.$event", "$method $url") ?: return
117119
if (event == RESPONSE_BODY_EVENT) {
118120
// We save this event is reading the response body, so that it will not be auto-finished
119121
isReadingResponseBody.set(true)

sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpEventListenerTest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,28 +168,35 @@ class SentryOkHttpEventListenerTest {
168168
}
169169
1 -> {
170170
assertEquals("http.client.proxy_select", span.operation)
171+
assertEquals("GET ${request.url}", span.description)
171172
assertNotNull(span.data["proxies"])
172173
}
173174
2 -> {
174175
assertEquals("http.client.dns", span.operation)
176+
assertEquals("GET ${request.url}", span.description)
175177
assertNotNull(span.data["domain_name"])
176178
assertNotNull(span.data["dns_addresses"])
177179
}
178180
3 -> {
179181
assertEquals("http.client.connect", span.operation)
182+
assertEquals("GET ${request.url}", span.description)
180183
}
181184
4 -> {
182185
assertEquals("http.client.connection", span.operation)
186+
assertEquals("GET ${request.url}", span.description)
183187
}
184188
5 -> {
185189
assertEquals("http.client.request_headers", span.operation)
190+
assertEquals("GET ${request.url}", span.description)
186191
}
187192
6 -> {
188193
assertEquals("http.client.response_headers", span.operation)
194+
assertEquals("GET ${request.url}", span.description)
189195
assertEquals(201, span.data[SpanDataConvention.HTTP_STATUS_CODE_KEY])
190196
}
191197
7 -> {
192198
assertEquals("http.client.response_body", span.operation)
199+
assertEquals("GET ${request.url}", span.description)
193200
}
194201
}
195202
}

sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpEventTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class SentryOkHttpEventTest {
158158
assertNotNull(span)
159159
assertTrue(spans.containsKey("span"))
160160
assertEquals("http.client.span", span.operation)
161+
assertEquals("${fixture.mockRequest.method} ${fixture.mockRequest.url}", span.description)
161162
assertFalse(span.isFinished)
162163
}
163164

@@ -196,6 +197,7 @@ class SentryOkHttpEventTest {
196197
sut.finishSpan("span") {
197198
if (called == 0) {
198199
assertEquals("http.client.span", it.operation)
200+
assertEquals("${fixture.mockRequest.method} ${fixture.mockRequest.url}", it.description)
199201
} else {
200202
assertEquals(sut.callRootSpan, it)
201203
}

0 commit comments

Comments
 (0)