Skip to content

Commit 910071f

Browse files
lbloderadinauer
andauthored
Adapt span op and description for graphql (#2607)
Co-authored-by: Alexander Dinauer <[email protected]>
1 parent 5bebc56 commit 910071f

File tree

8 files changed

+22
-15
lines changed

8 files changed

+22
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- The Spring Boot integration can now be configured to add the `SentryAppender` to specific loggers instead of the `ROOT` logger ([#2173](https://github.com/getsentry/sentry-java/pull/2173))
1111
- You can specify the loggers using `"sentry.logging.loggers[0]=foo.bar` and `"sentry.logging.loggers[1]=baz` in your `application.properties`
1212
- Add capabilities to track Jetpack Compose composition/rendering time ([#2507](https://github.com/getsentry/sentry-java/pull/2507))
13+
- Adapt span op and description for graphql to fit spec ([#2607](https://github.com/getsentry/sentry-java/pull/2607))
1314

1415
### Fixes
1516

sentry-apollo-3/src/main/java/io/sentry/apollo3/SentryApollo3HttpInterceptor.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ class SentryApollo3HttpInterceptor @JvmOverloads constructor(private val hub: IH
9696
val method = request.method
9797

9898
val operationName = operationNameFromHeaders(request)
99-
val operation = operationName ?: "apollo.client"
100-
val operationType = request.valueForHeader(SENTRY_APOLLO_3_OPERATION_TYPE) ?: method
99+
val operationType = request.valueForHeader(SENTRY_APOLLO_3_OPERATION_TYPE)
100+
val operation = if (operationType != null) "http.graphql.$operationType" else "http.graphql"
101101
val operationId = request.valueForHeader("X-APOLLO-OPERATION-ID")
102102
val variables = request.valueForHeader(SENTRY_APOLLO_3_VARIABLES)
103-
val description = "$operationType ${operationName ?: urlDetails.urlOrFallback}"
103+
val description = "${operationType ?: method} ${operationName ?: urlDetails.urlOrFallback}"
104104

105105
return activeSpan.startChild(operation, description).apply {
106106
urlDetails.applyToSpan(this)

sentry-apollo-3/src/test/java/io/sentry/apollo3/SentryApollo3InterceptorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class SentryApollo3InterceptorTest {
258258
private fun assertTransactionDetails(it: SentryTransaction) {
259259
assertEquals(1, it.spans.size)
260260
val httpClientSpan = it.spans.first()
261-
assertEquals("LaunchDetails", httpClientSpan.op)
261+
assertEquals("http.graphql", httpClientSpan.op)
262262
assertTrue { httpClientSpan.description?.startsWith("Post LaunchDetails") == true }
263263
assertNotNull(httpClientSpan.data) {
264264
assertNotNull(it["operationId"])

sentry-apollo-3/src/test/java/io/sentry/apollo3/SentryApollo3InterceptorWithVariablesTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class SentryApollo3InterceptorWithVariablesTest {
145145
private fun assertTransactionDetails(it: SentryTransaction) {
146146
assertEquals(1, it.spans.size)
147147
val httpClientSpan = it.spans.first()
148-
assertEquals("LaunchDetails", httpClientSpan.op)
148+
assertEquals("http.graphql.query", httpClientSpan.op)
149149
assertEquals("query LaunchDetails", httpClientSpan.description)
150150
assertNotNull(httpClientSpan.data) {
151151
assertNotNull(it["operationId"])

sentry-apollo/src/main/java/io/sentry/apollo/SentryApolloInterceptor.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ class SentryApolloInterceptor(
108108
is Subscription -> "subscription"
109109
else -> request.operation.javaClass.simpleName
110110
}
111+
val op = "http.graphql.$operationType"
111112
val description = "$operationType $operation"
112-
return activeSpan.startChild(operation, description)
113+
return activeSpan.startChild(op, description)
113114
}
114115

115116
private fun finish(span: ISpan, request: InterceptorRequest, response: InterceptorResponse? = null) {

sentry-apollo/src/test/java/io/sentry/apollo/SentryApolloInterceptorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class SentryApolloInterceptorTest {
205205
private fun assertTransactionDetails(it: SentryTransaction) {
206206
assertEquals(1, it.spans.size)
207207
val httpClientSpan = it.spans.first()
208-
assertEquals("LaunchDetails", httpClientSpan.op)
208+
assertEquals("http.graphql.query", httpClientSpan.op)
209209
assertEquals("query LaunchDetails", httpClientSpan.description)
210210
assertNotNull(httpClientSpan.data) {
211211
assertNotNull(it["operationId"])

sentry-graphql/src/main/java/io/sentry/graphql/SentryInstrumentation.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public SentryInstrumentation() {
7373
final TracingState tracingState = parameters.getInstrumentationState();
7474
final ISpan transaction = tracingState.getTransaction();
7575
if (transaction != null) {
76-
final ISpan span = transaction.startChild(findDataFetcherTag(parameters));
76+
final ISpan span = createSpan(transaction, parameters);
7777
try {
7878
final Object result = dataFetcher.get(environment);
7979
if (result instanceof CompletableFuture) {
@@ -127,8 +127,8 @@ private void finish(
127127
finish(span, environment, null);
128128
}
129129

130-
private @NotNull String findDataFetcherTag(
131-
final @NotNull InstrumentationFieldFetchParameters parameters) {
130+
private @NotNull ISpan createSpan(
131+
@NotNull ISpan transaction, @NotNull InstrumentationFieldFetchParameters parameters) {
132132
final GraphQLOutputType type = parameters.getExecutionStepInfo().getParent().getType();
133133
GraphQLObjectType parent;
134134
if (type instanceof GraphQLNonNull) {
@@ -137,7 +137,9 @@ private void finish(
137137
parent = (GraphQLObjectType) type;
138138
}
139139

140-
return parent.getName() + "." + parameters.getExecutionStepInfo().getPath().getSegmentName();
140+
return transaction.startChild(
141+
"graphql",
142+
parent.getName() + "." + parameters.getExecutionStepInfo().getPath().getSegmentName());
141143
}
142144

143145
static final class TracingState implements InstrumentationState {

sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationTest.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ class SentryInstrumentationTest {
7575
assertTrue(result.errors.isEmpty())
7676
assertEquals(1, fixture.activeSpan.children.size)
7777
val span = fixture.activeSpan.children.first()
78-
assertEquals("Query.shows", span.operation)
78+
assertEquals("graphql", span.operation)
79+
assertEquals("Query.shows", span.description)
7980
assertTrue(span.isFinished)
8081
assertEquals(SpanStatus.OK, span.status)
8182
}
@@ -89,7 +90,8 @@ class SentryInstrumentationTest {
8990
assertTrue(result.errors.isNotEmpty())
9091
assertEquals(1, fixture.activeSpan.children.size)
9192
val span = fixture.activeSpan.children.first()
92-
assertEquals("Query.shows", span.operation)
93+
assertEquals("graphql", span.operation)
94+
assertEquals("Query.shows", span.description)
9395
assertTrue(span.isFinished)
9496
assertEquals(SpanStatus.INTERNAL_ERROR, span.status)
9597
}
@@ -113,7 +115,8 @@ class SentryInstrumentationTest {
113115
assertTrue(result.errors.isEmpty())
114116
assertEquals(1, fixture.activeSpan.children.size)
115117
val span = fixture.activeSpan.children.first()
116-
assertEquals("Query.shows", span.operation)
118+
assertEquals("graphql", span.operation)
119+
assertEquals("Query.shows", span.description)
117120
assertNotNull(span.isSampled) {
118121
assertFalse(it)
119122
}
@@ -128,7 +131,7 @@ class SentryInstrumentationTest {
128131
assertTrue(result.errors.isEmpty())
129132
assertEquals(1, fixture.activeSpan.children.size)
130133
val span = fixture.activeSpan.children.first()
131-
assertEquals("Query.shows", span.operation)
134+
assertEquals("graphql", span.operation)
132135
assertEquals("changed", span.description)
133136
assertTrue(span.isFinished)
134137
}

0 commit comments

Comments
 (0)