@envelop/prometheus 6.4.0-alpha-385b86b.0 → 6.4.0-alpha-8a8cd36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +112 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
## `@envelop/prometheus`
|
|
2
|
+
|
|
3
|
+
This plugin tracks the complete execution flow, and reports metrics using Prometheus tracing (based on `prom-client`).
|
|
4
|
+
|
|
5
|
+
You can opt-in to collect tracing from the following phases:
|
|
6
|
+
|
|
7
|
+
- Sucessfull requests (`requestCount`)
|
|
8
|
+
- Request summary (`requestSummary`)
|
|
9
|
+
- errors (categorized by `phase`)
|
|
10
|
+
- resolvers tracing and runtime
|
|
11
|
+
- deprecated fields usage
|
|
12
|
+
- count of graphql operations
|
|
13
|
+
- `parse` execution time
|
|
14
|
+
- `validate` execution time
|
|
15
|
+
- `contextBuilding` execution time
|
|
16
|
+
- `execute` execution time
|
|
17
|
+
|
|
18
|
+
> You can also customize each phase reporter, and add custom metadata and labels to the metrics.
|
|
19
|
+
|
|
20
|
+
## Getting Started
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
yarn add prom-client @envelop/prometheus
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage Example
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { envelop } from '@envelop/core';
|
|
30
|
+
import { usePrometheus } from '@envelop/prometheus';
|
|
31
|
+
|
|
32
|
+
const getEnveloped = envelop({
|
|
33
|
+
plugins: [
|
|
34
|
+
// ... other plugins ...
|
|
35
|
+
usePrometheus({
|
|
36
|
+
// all optional, and by default, all set to false, please opt-in to the metrics you wish to get
|
|
37
|
+
requestCount: true, // requries `execute` to be true as well
|
|
38
|
+
requestSummary: true, // requries `execute` to be true as well
|
|
39
|
+
parse: true,
|
|
40
|
+
validate: true,
|
|
41
|
+
contextBuilding: true,
|
|
42
|
+
execute: true,
|
|
43
|
+
errors: true,
|
|
44
|
+
resolvers: true, // requires "execute" to be `true` as well
|
|
45
|
+
resolversWhitelist: ['Mutation.*', 'Query.user'], // reports metrics als for these resolvers, leave `undefined` to report all fields
|
|
46
|
+
deprecatedFields: true,
|
|
47
|
+
registry: myRegistry, // If you are using a custom prom-client registry, please set it here
|
|
48
|
+
}),
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
> Note: Tracing resolvers using `resovlers: true` might have a performance impact on your GraphQL runtime. Please consider to test it locally first and then decide if it's needed.
|
|
54
|
+
|
|
55
|
+
### Custom registry
|
|
56
|
+
|
|
57
|
+
You can customize the `prom-client` `Registry` object if you are using a custom one, by passing it along with the configuration object:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { Registry } from 'prom-client';
|
|
61
|
+
|
|
62
|
+
const myRegistry = new Registry();
|
|
63
|
+
|
|
64
|
+
const getEnveloped = envelop({
|
|
65
|
+
plugins: [
|
|
66
|
+
// ... other plugins ...
|
|
67
|
+
usePrometheus({
|
|
68
|
+
// ... config ...
|
|
69
|
+
registry: myRegistry,
|
|
70
|
+
}),
|
|
71
|
+
],
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
> Note: if you are using custom `prom-client` instances, you need to make sure to pass your registry there as well.
|
|
76
|
+
|
|
77
|
+
### Introspection
|
|
78
|
+
|
|
79
|
+
If you wish to disable introspection logging, you can use `skipIntrospection: true` in your config object.
|
|
80
|
+
|
|
81
|
+
### Custom `prom-client` instances
|
|
82
|
+
|
|
83
|
+
Each tracing field supports custom `prom-client` objects, and custom `labels` a metadata, you can create a custom extraction function for every `Histogram` / `Summary` / `Counter`:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { Histogram } from 'prom-client';
|
|
87
|
+
import { envelop } from '@envelop/core';
|
|
88
|
+
import { createHistogram, usePrometheus } from '@envelop/prometheus';
|
|
89
|
+
|
|
90
|
+
const getEnveloped = envelop({
|
|
91
|
+
plugins: [
|
|
92
|
+
// ... other plugins ...
|
|
93
|
+
usePrometheus({
|
|
94
|
+
// all optional, and by default, all set to false, please opt-in to the metrics you wish to get
|
|
95
|
+
parse: createHistogram({
|
|
96
|
+
histogram: new Histogram({
|
|
97
|
+
name: 'my_custom_name',
|
|
98
|
+
help: 'HELP ME',
|
|
99
|
+
labelNames: ['opText'] as const,
|
|
100
|
+
registers: [registry], // make sure to add your custom registry, if you are not using the default one
|
|
101
|
+
}),
|
|
102
|
+
fillLabelsFn: params => {
|
|
103
|
+
// if you wish to fill your `lables` with metadata, you can use the params in order to get access to things like DocumentNode, operationName, operationType, `error` (for error metrics) and `info` (for resolvers metrics)
|
|
104
|
+
return {
|
|
105
|
+
opText: print(params.document),
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
109
|
+
}),
|
|
110
|
+
],
|
|
111
|
+
});
|
|
112
|
+
```
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/prometheus",
|
|
3
|
-
"version": "6.4.0-alpha-
|
|
3
|
+
"version": "6.4.0-alpha-8a8cd36.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "2.4.0-alpha-
|
|
6
|
+
"@envelop/core": "2.4.0-alpha-8a8cd36.0",
|
|
7
7
|
"prom-client": "^13 || ^14.0.0",
|
|
8
8
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
9
9
|
},
|