newrelic / newrelic-node-apollo-server-plugin

Apache License 2.0
62 stars 29 forks source link

Argument arrays are not collapsed in reported metrics #322

Open karoldembowski opened 1 month ago

karoldembowski commented 1 month ago

Description

I'm not sure if this should be considered a bug or feature request, but given the consequences of this behaviour I'd consider this a bug. At work we noticed that arrays in graphql inputs are reported as separate metric for each array index. This is surprising because it's not the case for arrays of returned fields, which are collapsed into one metric. As a result we've seen some of our queries which can accept thousands of inputs to produce thousands of different metric entries in Metric Explorer. I'm also concerned this might be causing us to hit cardinality metric limits in New Relic.

Example:

query MyQuery {
  books(
    ids: [1, 2, 3], 
    searchCriteria: [{ name: 'test' }, { name: 'test2' }]
  ) {
    ...
  }
}

This query would report metrics:

GraphQL/arg/ApolloServer/Query.books/ids.0
GraphQL/arg/ApolloServer/Query.books/ids.1
GraphQL/arg/ApolloServer/Query.books/ids.2
GraphQL/arg/ApolloServer/Query.books/searchCriteria.0.name
GraphQL/arg/ApolloServer/Query.books/searchCriteria.1.name

Expected Behavior

I'd expect metrics for input arrays to be collapsed similarly to how it's collected for returned field metrics. For the given example above, I'd expect:

GraphQL/arg/ApolloServer/Query.books/ids (reported 3 times)
GraphQL/arg/ApolloServer/Query.books/searchCriteria.name (reported 2 times)

Alternatively it could be configurable, just like opentelemetry intrumentation does with mergeItems option: https://www.npmjs.com/package/@opentelemetry/instrumentation-graphql

Troubleshooting or NR Diag results

Steps to Reproduce

Your Environment

Node version: 20

Additional context

workato-integration[bot] commented 1 month ago

https://new-relic.atlassian.net/browse/NR-313180

bizob2828 commented 1 month ago

This is working as expected. I'm going to migrate this to a feature request for further consideration