-
-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Add graphql-java
instrumentation.
#1777
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1777 +/- ##
============================================
- Coverage 75.75% 75.73% -0.03%
- Complexity 2180 2193 +13
============================================
Files 216 218 +2
Lines 7739 7794 +55
Branches 824 828 +4
============================================
+ Hits 5863 5903 +40
- Misses 1476 1488 +12
- Partials 400 403 +3
Continue to review full report at Codecov.
|
sentry-graphql-java/src/main/java/io/sentry/graphql/java/SentryDataFetcherExceptionHandler.java
Outdated
Show resolved
Hide resolved
sentry-graphql-java/src/main/java/io/sentry/graphql/java/SentryDataFetcherExceptionHandler.java
Outdated
Show resolved
Hide resolved
...graphql-java/src/test/kotlin/io/sentry/graphql/java/SentryDataFetcherExceptionHandlerTest.kt
Outdated
Show resolved
Hide resolved
sentry-graphql-java/src/test/kotlin/io/sentry/graphql/java/SentryInstrumentationTest.kt
Outdated
Show resolved
Hide resolved
...ntry-samples-netflix-dgs/src/main/java/io/sentry/samples/netflix/dgs/graphql/types/Show.java
Show resolved
Hide resolved
@@ -0,0 +1,36 @@ | |||
package io.sentry.graphql.java; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to have the .java
in the name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still called sentry-graphql-java
, should we rename it to sentry-graphql
? we only add the android
suffix to Android modules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the library we integrate with is called graphql-java
- i do think it should stay as the module name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bruno-garcia are u fine with it? I recall you didn't want to add such sufixes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it must match in all cases the package name. The proposal from manoel sounds better to me unless folks have strong options not to take that route
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with or without fine with me, I'd rather keep it without -java if I'd have to vote.
@romtsn ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same maybe call it sentry-graphql-server
? :D fine with everything
...sentry-samples-netflix-dgs/src/main/java/io/sentry/samples/netflix/dgs/ShowsDatafetcher.java
Outdated
Show resolved
Hide resolved
- do not finish parent span - handle exceptions thrown by data fetchers - set parent span status if any of child spans fails
Few improvements to instrumentation:
So now, if any of the child spans fails - meaning that there are errors present in GraphQL response, we set the parent span status - which in most cases will be a transaction - to |
sentry-graphql-java/src/main/java/io/sentry/graphql/SentryInstrumentation.java
Outdated
Show resolved
Hide resolved
sentry-graphql-java/src/main/java/io/sentry/graphql/SentryInstrumentation.java
Outdated
Show resolved
Hide resolved
sentry-graphql-java/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java
Outdated
Show resolved
Hide resolved
sentry-graphql-java/src/main/java/io/sentry/graphql/SentryInstrumentation.java
Outdated
Show resolved
Hide resolved
…rumentation.java Co-authored-by: Manoel Aranda Neto <[email protected]>
…rumentation.java Co-authored-by: Manoel Aranda Neto <[email protected]>
missing the craft configuration, release-registry and docs later on :) the module name is still with |
sentry-graphql-java/src/main/java/io/sentry/graphql/SentryInstrumentation.java
Show resolved
Hide resolved
sentry-graphql-java/src/main/java/io/sentry/graphql/SentryInstrumentation.java
Outdated
Show resolved
Hide resolved
let's discuss https://github.com/getsentry/sentry-java/pull/1777/files#r742653695 today and approve/merge, nothing but this comment blocks me to approve, merge and release, thanks for doing this @maciejwalkowiak @romtsn wanna have a look? |
sentry-graphql-java/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java
Outdated
Show resolved
Hide resolved
sentry-graphql-java/src/main/java/io/sentry/graphql/SentryInstrumentation.java
Show resolved
Hide resolved
sentry-graphql-java/src/main/java/io/sentry/graphql/SentryInstrumentation.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
final ISpan transaction = tracingState.getTransaction(); | ||
if (transaction != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to use the SentryInstrumentation
in our spring-graphql application (using Spring Boot), but the transaction here is always null
. Is it necessary to manually start a transaction? Or how can I get this to work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see the Docs PR getsentry/sentry-docs#4385
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I didn't see that PR yet. But unfortunately it doesn't solve the issue; performance tracing is set up, but apparently a transaction isn't started before graphql execution.
For now I think I've mitigated it by adding a WebInterceptor
(a spring-graphql concept), that starts a transaction;
class SentryWebInterceptor : WebInterceptor {
override fun intercept(webInput: WebInput, chain: WebInterceptorChain): Mono<WebOutput> {
val span = Sentry.getSpan() ?: Sentry.startTransaction("GraphQL", webInput.operationName ?: "none", true)
return chain.next(webInput).doFinally {
span.finish()
}
}
}
According to the PR description "the transaction name is POST /graphql
", but this doesn't seem to be defined explicitly, so could it be that the assumption is made that the the http/network layer already starts the transaction, but that somehow with spring-graphql this doesn't happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the graphql integration only creates spans if there's an active transaction, so ideally you'd use it along with an integration that has the ability to create a transaction, eg https://docs.sentry.io/platforms/java/guides/spring-boot/performance/instrumentation/automatic-instrumentation/
or just create a transaction yourself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just found that out too, but unfortunately there's no auto instrumentation available for applications using webflux, so I guess I have to implement what's in SentryTracingFilter
, but then reactive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, #1807
no priorities for now, but if you feel adding support via PR, happy to guide :)
📜 Description
Add
graphql-java
instrumentation.SentryDataFetcherExceptionHandler
reports exception to Sentry and invokes a delegateSample usage with Netflix DGS:
SentryInstrumentation
creates spans around data fetchers. Since there can be more than a single query executed within a single HTTP request, the transaction name isPOST /graphql
and resolving each query/field is reported as separate span.It is advised to turn on
sentry.max-request-body-size
reporting, to get a complete GraphQL query in request parameters.💡 Motivation and Context
Fixes #1755
Both Netflix DGS and Spring GraphQL are based on graphql-java. Changes introduced in this PR will work for both solutions as well as using
graphql-java
directly.💚 How did you test it?
Unit tests.
📝 Checklist
🔮 Next steps
Optionally, once Spring GraphQL project reaches GA, add corresponding sample.