graphql-hive / graphql-hive/envelop
Configure context derived labels for all metrics
- 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.