newrelic / newrelic-node-apollo-server-plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Include customAttributes on the Segments/Spans

KGAdamCook opened this issue · comments

Is your feature request related to a problem? Please describe.

I wish I could filter my metric queries (Top 10 Slowest Operations) by specified custom attributes, such as the "apolloclient-graphql-name"

Feature Description

Include custom attributes set via newrelic.addCustomAttributes on the segments and spans

Describe Alternatives

A clear and concise description of any alternative solutions or features you've considered. Are there examples you could link us to?

Additional context

In my codebase I am already calling newrelic.addCustomAttributes({ clientName: req.headers['apollographql-client-name'] }), however this doesn't seem to get added to any Span events that this plugin creates.

Priority

Please help us better understand this feature request by choosing a priority from the following options:
Nice to Have

Thanks @KGAdamCook for this report. We will take a look at this and see what we can do. Can you provide a little more code context about where/when you're adding custom attributes in your code?

When we initialise our ApolloServer we use a custom context function as shown here: https://www.apollographql.com/docs/apollo-server/data/resolvers/#the-context-argument.

Inside of our context function is where I am adding the newrelic.addCustomAttributes({ });

@KGAdamCook thanks for providing more information. It sounds like if we provided some key on context like nrCustomAttrs that can be a function and we can inject into the relevant operation spans/segments. Is that a safe interpretation of your ask? Also, it'd only be on the operation span/segments and not the resolver span/segments correct?

I would have hoped we could just use the already provided API of newrelic.addCustomAttributes(), but sure, if we have to add them another way too that would be fine.

Yeah I had just thought it would be for the operation span/segments.

I would have hoped we could just use the already provided API of newrelic.addCustomAttributes(), but sure, if we have to add them another way too that would be fine.

Yeah I had just thought it would be for the operation span/segments.

We don't intend changing that, it's just that API works different in this context. We can look into more and provide some guidance/solutions.

I don't understand the request here. I created a resolver that does this,

const UserTypeResolver = {
  age: async (id, _, ctx) => {
    newrelic.addCustomAttribute('lol', 'omg')
    const user = await getUser(ctx, id)
    return user.age
  },
  // etc
}

and I am getting the desired attribute showing up in spans,
Screenshot 2023-05-16 at 12 15 10

Although I directly modified the resolver here to add the custom attribute, I could have also put the call somewhere inside the context object that this resolver gets passed, and then have the resolver call it there.

Is there something I am misunderstanding?

Closed by #249

Hi @KGAdamCook this work has been released in 3.1.0 of the plugin. Take a look at the release notes regarding how you would do this