graphql-hive / graphql-hive/envelop

Configure context derived labels for all metrics

Open
#2,245 3 comments 1 reaction 0 assignees View on GitHub
kind/enhancement
Dominant language
No language data
Stars
827
Forks
132
PR merge metrics
No merged PRs in 30d

Description

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

Users may wish to apply some labels to all metrics based on the specific request context -- for example, a server that acts as a backend for multiple front-end clients may wish to label metrics according to the client type.

RIght now, the best way that I can see to do this is to provide `createHistogram`/`createSummary`/`createCounter` functions for each metric collected, ex:
```
usePrometheus({
endpoint: false,
requestCount: createCounter({
registry,
counter: {
name: "graphql_request_count",
help: "Number of GraphQL requests",
labelNames: ["operationName", "operationType"],
},
fillLabelsFn: (params, rawContext) => {
return {
operationName: params.operationName,
operationType: params.operationType,
clientType: getClientTypeFromContext(rawContext),
};
},
}),
requestTotalDuration: createHistogram({
registry,
histogram: {
name: "graphql_request_duration_seconds",
help: "Duration of GraphQL requests in seconds",
labelNames: ["operationName", "operationType"],
},
fillLabelsFn: (params, rawContext) => {
return {
operationName: params.operationName,
operationType: params.operationType,
clientType: getClientTypeFromContext(rawContext),
};
},
}),
...
```

**Describe the solution you'd like**

It would be nice if there were a configuration option on the plugin that allowed the user to provide a function that takes the context and returns some labels.

```
contextLabels?: (context: TUserContext) => Record;
```

**Describe alternatives you've considered**

It's possible that I'm missing something that allows one to do this already. If so, apologies.

**Additional context**

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.