diff --git a/.changeset/cold-seals-play.md b/.changeset/cold-seals-play.md deleted file mode 100644 index 46b82427d..000000000 --- a/.changeset/cold-seals-play.md +++ /dev/null @@ -1,96 +0,0 @@ ---- -'@envelop/prometheus': minor ---- - -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. - -## Example: trace only execution and subscription errors - -```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: { - // Here, an array of phases can be provided to enable the metric only on certain phases. - // In this example, only error happening during the execute and subscribe phases will tracked - graphql_envelop_phase_error: ['execute', 'subscribe'] - } - }), - ], -}) -``` - -## Example: Monitor timing only of a set of operations by name - -```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: { - graphql_yoga_http_duration: createHistogram({ - registry, - histogram: { - name: 'graphql_envelop_request_duration', - help: 'Time spent on HTTP connection', - labelNames: ['operationName'] - }, - fillLabelsFn: ({ operationName }, _rawContext) => ({ operationName, }), - phases: ['execute', 'subscribe'], - - // Here `shouldObserve` control if the request timing should be observed, based on context - shouldObserve: ({ operationName }) => TRACKED_OPERATIONS.includes(operationName), - }) - }, - }) - ] -}) -``` - -## Default Behavior 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'], - }, -}) -``` \ No newline at end of file diff --git a/packages/plugins/prometheus/CHANGELOG.md b/packages/plugins/prometheus/CHANGELOG.md index fc363a71c..be1f09e74 100644 --- a/packages/plugins/prometheus/CHANGELOG.md +++ b/packages/plugins/prometheus/CHANGELOG.md @@ -1,5 +1,104 @@ # @envelop/prometheus +## 11.1.0 + +### Minor Changes + +- [#2326](https://github.com/n1ru4l/envelop/pull/2326) + [`443fc15`](https://github.com/n1ru4l/envelop/commit/443fc150184b40357d064c900de4105f14164c37) + Thanks [@EmrysMyrddin](https://github.com/EmrysMyrddin)! - 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. + + ## Example: trace only execution and subscription errors + + ```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: { + // Here, an array of phases can be provided to enable the metric only on certain phases. + // In this example, only error happening during the execute and subscribe phases will tracked + graphql_envelop_phase_error: ['execute', 'subscribe'] + } + }) + ] + }) + ``` + + ## Example: Monitor timing only of a set of operations by name + + ```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: { + graphql_yoga_http_duration: createHistogram({ + registry, + histogram: { + name: 'graphql_envelop_request_duration', + help: 'Time spent on HTTP connection', + labelNames: ['operationName'] + }, + fillLabelsFn: ({ operationName }, _rawContext) => ({ operationName }), + phases: ['execute', 'subscribe'], + + // Here `shouldObserve` control if the request timing should be observed, based on context + shouldObserve: ({ operationName }) => TRACKED_OPERATIONS.includes(operationName) + }) + } + }) + ] + }) + ``` + + ## Default Behavior 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'] + } + }) + ``` + ## 11.0.0 ### Major Changes diff --git a/packages/plugins/prometheus/package.json b/packages/plugins/prometheus/package.json index e5a63b52d..9be502523 100644 --- a/packages/plugins/prometheus/package.json +++ b/packages/plugins/prometheus/package.json @@ -1,6 +1,6 @@ { "name": "@envelop/prometheus", - "version": "11.0.0", + "version": "11.1.0", "type": "module", "repository": { "type": "git",