Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

adding tracing instrumentation #52

Closed
flarepass opened this issue Jan 17, 2018 · 12 comments
Closed

adding tracing instrumentation #52

flarepass opened this issue Jan 17, 2018 · 12 comments

Comments

@flarepass
Copy link

Hi, correct me if I'm wrong.
With the graphql-spring-boot-starter, it will handle the bean creation for these object : GraphQL ,GraphQLSchema, SchemaParser, etc.
and I'm interested with the tracing instrumentation (http://graphql-java.readthedocs.io/en/v6/instrumentation.html) which add TracingInstrumentation to the GraphQL object
I tried to add the tracing instrumentation to my GraphQL object but there's no change to my response
here is how I try to add the TracingInstrumentation object to my GraphQL object
`
@SpringBootApplication
public class DemographqlApplication {

public static void main(String[] args) {
    SpringApplication.run(DemographqlApplication.class, args);
}

@Bean
public GraphQL graphQL(GraphQLSchema graphQLSchema) {
    return GraphQL.newGraphQL(graphQLSchema)
            .instrumentation(new TracingInstrumentation())
            .build();
}

}`

Am I missing something here ?

Thank you

@apottere
Copy link
Collaborator

The GraphQL object is request-scoped, so it's created on every request. You'll need to implement a https://github.com/graphql-java/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/InstrumentationProvider.java bean that returns the tracing instrumentation.

@flarepass
Copy link
Author

Hi @apottere,
Thank you for your response, but I have create an implementation of the InstrumentProvider :
public class GraphQLInstrumentationProvider implements InstrumentationProvider { @Override public Instrumentation getInstrumentation() { return new TracingInstrumentation(); } }

and I also provide the bean,
@Bean InstrumentationProvider instrumentationProvider() { return new GraphQLInstrumentationProvider(); }

I'll try to include some detail of my sample code :

my schema only contain

type Query { allLinks: [Link] } type Link { id: ID! url: String! description: String }

my request :
{ allLinks{ id } }
my response :
{ "data": { "allLinks": [ { "id": "1" } ] } }

Is there anything else that i missed ?

@apottere
Copy link
Collaborator

No, that should work. Is it injecting the InstrumentationProvider into your servlet?

@flarepass
Copy link
Author

Hi @apottere ,

I think it suppose to provide the InstrumentationProvider bean to the servlet, but as i see in the documentation, http://graphql-java.readthedocs.io/en/v6/instrumentation.html

The instrumentation should be set into the GraphQL object, that's why at first i tried to create the bean for GraphQL object, but since the GraphQL object is request-scoped, i'm not sure how to add it.

@apottere
Copy link
Collaborator

The GraphQL object is created by the servlet when it gets a request.

@flarepass
Copy link
Author

Hi @apottere,

I'm still unable to provide the TracingInstrumentation to the GraphQL object.
I have created my implementation and provide the Bean.

could you give me example of how to injecting the Instrumentatio Provider?
or Is it possible to keep this issue open so I can get insight from some people that has tried this before?

Thank you

@apottere
Copy link
Collaborator

Sorry, I was mistaken - you can just add your instrumentation as a bean and it should be picked up:

@Bean
Instrumentation instrumentation() {
    return new TracingInstrumentation();
}

@flarepass
Copy link
Author

hi @apottere ,

Did that work for you ?
Since i have tried it, i also have tried provided the TracingInstrumentation as bean before, but there is no change at all.

@apottere
Copy link
Collaborator

Yes, I tried it in an example project and hit a breakpoint in the TracingInstrumentation

@flarepass
Copy link
Author

Hi @apottere

Yes, I also tried to debug and hit a breakpoint at GraphQLWebAutoConfiguration which the Tracing Instrumentation has been added to GraphQLServlet bean.
Yet there is no change to my Json Response, there is no extra tracing data under extensions.
Thank you 👍

@flarepass
Copy link
Author

Fixed,
It's because of older version of version of graphql-java-servlet as pointed by eric taix at Stackoverflow 😅
Thank you

@kwang1
Copy link

kwang1 commented May 14, 2019

Sorry, I was mistaken - you can just add your instrumentation as a bean and it should be picked up:

@Bean
Instrumentation instrumentation() {
    return new TracingInstrumentation();
}

Hi @apottere , can this be found in any documentation? are there any detailed documents about which beans can be injected to Spring?

Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants