Hello! I just wanted to ask a questions regarding ...
# support
a
Hello! I just wanted to ask a questions regarding instrumentation for Apollo GraphQL. How would we get the .execute traces to display the SQL query string or any specific information regarding the GraphQL query that was made? Thanks ahead of time!
p
@Allan Li have you had a look at this - https://signoz.io/blog/monitoring-graphql/
a
Thank you, I have set up signoz with my project. How can we access the data from the
responseHook
field of the
GraphQLInstrumentation
module from
@opentelemetry/instrumentation
as shown in the example from the Signoz traces UI? Can we somehow modify the status of the span according to the `responseHook`(for example if
responseHook
shows an error that was caught, then the color of the span in the UI will change color)? Or would we have to query for the
errors
field in
responseHook
periodically and set up some type of alert system? Thanks again.
@Pranay
Nevermind I have figured it out 👍
p
cool
If you can share how you solved it here also, would be helpful for other folks also who face similar issue
a
Sure, while integrating the
GraphQLInstrumentation
module from
@opentelemetry/instrucmentataions-graphql
library, we see that the
responseHook
field provides two variables we can work with:
span
and
data
. The
data
object will return the response of your GraphQL operation. The
errors
field in
data
will not be empty if there is something wrong with your operation. Given this information we can edit the
span
object (which corresponds to the actual span opentelemetry will send to SigNoz) by adding custom attributes or attach exception to reflect that an error has occurred. To make the error spans for visible we can use
span.setStatus(SpanStatusCode.ERROR)
to indicate that something is wrong with the span, and SigNoz will mark this span as red or we can easily query for it. We can attach the error message from
data.errors
to some attribute with
span.setAttribute()
, which will make the value visible on the attributes sidebar on the SigNoz traces UI.
p
thanks for sharing this @Allan Li
j
hi @Allan Li could you make an example of how do I have put in the responseHook? (in the ??? place).
Copy code
getNodeAutoInstrumentations(),
      new GraphQLInstrumentation({
        allowValues: true,
        responseHook: ???
      }),],