Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@

### Fixes

- OpenTelemetry: Align GraphQL span operations and descriptions with Sentry instrumentation by grouping operation spans under `graphql` while retaining names such as `query GreetingQuery` as descriptions ([#6764](https://github.com/getsentry/sentry-java/pull/6764))
- Set Apollo 3, 4, and 5 HTTP spans to `CANCELLED` instead of `INTERNAL_ERROR` when the request is cancelled ([#6284](https://github.com/getsentry/sentry-java/pull/6284))
- Preserve independent Netty read and write timeout events when exception singletons are reused. These exceptions now bypass event deduplication by default, so applications with multiple capture integrations may report the same timeout more than once. Use `SentryOptions.setIgnoredErrorsForDeduplication(...)` or `ignored-errors-for-deduplication` to customize or clear the default exclusions. ([#6465](https://github.com/getsentry/sentry-java/pull/6465))
- Prevent changes to reused tracing options from affecting spans and transactions after creation ([#6417](https://github.com/getsentry/sentry-java/pull/6417))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.opentelemetry.semconv.HttpAttributes;
import io.opentelemetry.semconv.UrlAttributes;
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
import io.opentelemetry.semconv.incubating.GraphqlIncubatingAttributes;
import io.opentelemetry.semconv.incubating.HttpIncubatingAttributes;
import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes;
import io.sentry.SentryOptions;
Expand All @@ -28,6 +29,12 @@ public final class SpanDescriptionExtractor {
return descriptionForMessagingSystem(otelSpan);
}

final @Nullable String graphqlOperationType =
attributes.get(GraphqlIncubatingAttributes.GRAPHQL_OPERATION_TYPE);
if (graphqlOperationType != null) {
return descriptionForGraphqlOperation(otelSpan);
}

final @Nullable String httpMethod = attributes.get(HttpAttributes.HTTP_REQUEST_METHOD);
if (httpMethod != null) {
return descriptionForHttpMethod(otelSpan, httpMethod);
Expand All @@ -45,6 +52,10 @@ public final class SpanDescriptionExtractor {
return new OtelSpanInfo(name, description, TransactionNameSource.CUSTOM);
}

private OtelSpanInfo descriptionForGraphqlOperation(final @NotNull SpanData otelSpan) {
return new OtelSpanInfo("graphql", otelSpan.getName(), TransactionNameSource.TASK);
}

@SuppressWarnings("deprecation")
private OtelSpanInfo descriptionForHttpMethod(
final @NotNull SpanData otelSpan, final @NotNull String httpMethod) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.opentelemetry.sdk.trace.data.SpanData
import io.opentelemetry.semconv.HttpAttributes
import io.opentelemetry.semconv.UrlAttributes
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes
import io.opentelemetry.semconv.incubating.GraphqlIncubatingAttributes
import io.opentelemetry.semconv.incubating.HttpIncubatingAttributes
import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes
import io.sentry.SentryOptions
Expand Down Expand Up @@ -41,6 +42,48 @@ class SpanDescriptionExtractorTest {

private val fixture = Fixture()

@Test
fun `sets op to graphql and preserves query span name as description`() {
givenSpanName("query GreetingQuery")
givenAttributes(mapOf(GraphqlIncubatingAttributes.GRAPHQL_OPERATION_TYPE to "query"))

val info = whenExtractingSpanInfo()

assertEquals("graphql", info.op)
assertEquals("query GreetingQuery", info.description)
assertEquals(TransactionNameSource.TASK, info.transactionNameSource)
}

@Test
fun `sets op to graphql and preserves mutation span name as description`() {
givenSpanName("mutation AddProjectMutation")
givenAttributes(mapOf(GraphqlIncubatingAttributes.GRAPHQL_OPERATION_TYPE to "mutation"))

val info = whenExtractingSpanInfo()

assertEquals("graphql", info.op)
assertEquals("mutation AddProjectMutation", info.description)
assertEquals(TransactionNameSource.TASK, info.transactionNameSource)
}

@Test
fun `graphql mapping wins over http when both attributes present`() {
givenSpanKind(SpanKind.CLIENT)
givenSpanName("query GreetingQuery")
givenAttributes(
mapOf(
GraphqlIncubatingAttributes.GRAPHQL_OPERATION_TYPE to "query",
HttpAttributes.HTTP_REQUEST_METHOD to "POST",
),
)

val info = whenExtractingSpanInfo()

assertEquals("graphql", info.op)
assertEquals("query GreetingQuery", info.description)
assertEquals(TransactionNameSource.TASK, info.transactionNameSource)
}

@Test
fun `sets op to http server for kind SERVER`() {
givenSpanKind(SpanKind.SERVER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import io.sentry.test.transaction
import kotlin.test.Test

/**
* The agent traces each GraphQL operation as one span, with the operation's name as its op and
* description, so the queries are named.
* The agent traces each GraphQL operation as one span, using the GraphQL operation name as its
* description.
*/
class GraphqlIntegrationTest : IntegrationTest() {

Expand Down Expand Up @@ -97,7 +97,7 @@ class GraphqlIntegrationTest : IntegrationTest() {
.transaction()!!

private fun SentryTransaction.hasOperationSpan(operation: String): Boolean =
hasSpanWithOpAndDescription(operation, operation)
hasSpanWithOpAndDescription("graphql", operation)

/** Finds the error for [exceptionMessage], then the transaction it belongs to by trace ID. */
private fun awaitTransactionOfError(exceptionMessage: String): SentryTransaction {
Expand Down
Loading