-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: [plugin/prometheus] allow to skip observation based on context #2317
Open
EmrysMyrddin
wants to merge
6
commits into
main
Choose a base branch
from
feat/plugin-prometheus/context-based-skip
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+958
−407
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
961ae4a
feat: [plugin/prometheus] allow to skip observation based on context
EmrysMyrddin 94c4782
always observe by default
EmrysMyrddin 937e04f
feat: add option for all metrics
EmrysMyrddin 2665870
docs: update the readme with the new API
EmrysMyrddin f124d50
changeset
EmrysMyrddin 27b09e2
update the TSDoc
EmrysMyrddin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- | ||
'@envelop/prometheus': major | ||
--- | ||
|
||
Allow to explicitly control which events and timing should be observe. | ||
|
||
Each metric can now be configured to observe events and timings only for certain GraphQL pipeline | ||
phases, or depending on the request context. | ||
|
||
```ts | ||
import { execute, parse, specifiedRules, subscribe, validate } from 'graphql' | ||
import { envelop, useEngine } from '@envelop/core' | ||
import { usePrometheus } from '@envelop/prometheus' | ||
|
||
const TRACKED_OPERATION_NAMES = [ | ||
// make a list of operation that you want to monitor | ||
] | ||
|
||
const getEnveloped = envelop({ | ||
plugins: [ | ||
useEngine({ parse, validate, specifiedRules, execute, subscribe }), | ||
usePrometheus({ | ||
metrics: { | ||
|
||
// only trace errors of execute and subscribe phases | ||
graphql_envelop_phase_error: ['execute', 'subscribe'] | ||
|
||
// only monitor timing of some operations | ||
graphql_yoga_http_duration: createHistogram({ | ||
registry, | ||
histogram: { | ||
name: 'graphql_yoga_http_duration', | ||
help: 'Time spent on HTTP connection', | ||
labelNames: ['operation_name'] | ||
}, | ||
fillLabelsFn: ({ operationName }, _rawContext) => ({ | ||
operation_name: operationName, | ||
}), | ||
|
||
// Here `shouldObserve` control if the request timing should be observed, based on context | ||
shouldObserve: context => TRACKED_OPERATIONS.includes(context?.params?.operationName), | ||
}) | ||
}, | ||
}) | ||
] | ||
}) | ||
``` | ||
|
||
**Breaking Change**: A metric is enabled using `true` value in metrics options will observe in every | ||
phases available. | ||
|
||
Previously, which phase was observe was depending on which other metric were enabled. For example, | ||
this config would only trace validation error: | ||
|
||
```ts | ||
usePrometheus({ | ||
metrics: { | ||
graphql_envelop_phase_error: true, | ||
graphql_envelop_phase_validate: true, | ||
}, | ||
}) | ||
``` | ||
|
||
This is no longer the case. If you were relying on this behavior, please use an array of string to | ||
restrict observed phases. | ||
|
||
```ts | ||
usePrometheus({ | ||
metrics: { | ||
graphql_envelop_phase_error: ['validate'], | ||
}, | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!
But I think the example should be updated:
because I think the signature is the same as
fillLabelsFn
.