@envelop/prometheus 6.6.0 → 6.6.1-alpha-20220901205925-b1fd44a9
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 +16 -0
- package/cjs/index.js +32 -35
- package/cjs/utils.js +1 -2
- package/esm/index.js +32 -35
- package/esm/utils.js +1 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -26,10 +26,15 @@ yarn add prom-client @envelop/prometheus
|
|
|
26
26
|
## Usage Example
|
|
27
27
|
|
|
28
28
|
```ts
|
|
29
|
+
import { parse, validate, execute, subscribe } from 'graphql'
|
|
29
30
|
import { envelop } from '@envelop/core'
|
|
30
31
|
import { usePrometheus } from '@envelop/prometheus'
|
|
31
32
|
|
|
32
33
|
const getEnveloped = envelop({
|
|
34
|
+
parse,
|
|
35
|
+
validate,
|
|
36
|
+
execute,
|
|
37
|
+
subscribe,
|
|
33
38
|
plugins: [
|
|
34
39
|
// ... other plugins ...
|
|
35
40
|
usePrometheus({
|
|
@@ -57,11 +62,17 @@ const getEnveloped = envelop({
|
|
|
57
62
|
You can customize the `prom-client` `Registry` object if you are using a custom one, by passing it along with the configuration object:
|
|
58
63
|
|
|
59
64
|
```ts
|
|
65
|
+
import { parse, validate, execute, subscribe } from 'graphql'
|
|
66
|
+
import { envelop } from '@envelop/core'
|
|
60
67
|
import { Registry } from 'prom-client'
|
|
61
68
|
|
|
62
69
|
const myRegistry = new Registry()
|
|
63
70
|
|
|
64
71
|
const getEnveloped = envelop({
|
|
72
|
+
parse,
|
|
73
|
+
validate,
|
|
74
|
+
execute,
|
|
75
|
+
subscribe,
|
|
65
76
|
plugins: [
|
|
66
77
|
// ... other plugins ...
|
|
67
78
|
usePrometheus({
|
|
@@ -83,11 +94,16 @@ If you wish to disable introspection logging, you can use `skipIntrospection: tr
|
|
|
83
94
|
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
95
|
|
|
85
96
|
```ts
|
|
97
|
+
import { parse, validate, execute, subscribe } from 'graphql'
|
|
86
98
|
import { Histogram } from 'prom-client'
|
|
87
99
|
import { envelop } from '@envelop/core'
|
|
88
100
|
import { createHistogram, usePrometheus } from '@envelop/prometheus'
|
|
89
101
|
|
|
90
102
|
const getEnveloped = envelop({
|
|
103
|
+
parse,
|
|
104
|
+
validate,
|
|
105
|
+
execute,
|
|
106
|
+
subscribe,
|
|
91
107
|
plugins: [
|
|
92
108
|
// ... other plugins ...
|
|
93
109
|
usePrometheus({
|
package/cjs/index.js
CHANGED
|
@@ -27,16 +27,13 @@ const usePrometheus = (config = {}) => {
|
|
|
27
27
|
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName', 'returnType'],
|
|
28
28
|
registers: [config.registry || prom_client_1.register],
|
|
29
29
|
}),
|
|
30
|
-
fillLabelsFn: params => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
returnType: (_c = params.info) === null || _c === void 0 ? void 0 : _c.returnType.toString(),
|
|
38
|
-
});
|
|
39
|
-
},
|
|
30
|
+
fillLabelsFn: params => ({
|
|
31
|
+
operationName: params.operationName,
|
|
32
|
+
operationType: params.operationType,
|
|
33
|
+
fieldName: params.info?.fieldName,
|
|
34
|
+
typeName: params.info?.parentType.name,
|
|
35
|
+
returnType: params.info?.returnType.toString(),
|
|
36
|
+
}),
|
|
40
37
|
})
|
|
41
38
|
: undefined;
|
|
42
39
|
const requestTotalHistogram = typeof config.requestTotalDuration === 'object'
|
|
@@ -81,15 +78,12 @@ const usePrometheus = (config = {}) => {
|
|
|
81
78
|
labelNames: ['operationType', 'operationName', 'path', 'phase'],
|
|
82
79
|
registers: [config.registry || prom_client_1.register],
|
|
83
80
|
}),
|
|
84
|
-
fillLabelsFn: params => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
phase: params.errorPhase,
|
|
91
|
-
});
|
|
92
|
-
},
|
|
81
|
+
fillLabelsFn: params => ({
|
|
82
|
+
operationName: params.operationName,
|
|
83
|
+
operationType: params.operationType,
|
|
84
|
+
path: params.error?.path?.join('.'),
|
|
85
|
+
phase: params.errorPhase,
|
|
86
|
+
}),
|
|
93
87
|
})
|
|
94
88
|
: undefined;
|
|
95
89
|
const reqCounter = typeof config.requestCount === 'object'
|
|
@@ -118,15 +112,12 @@ const usePrometheus = (config = {}) => {
|
|
|
118
112
|
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName'],
|
|
119
113
|
registers: [config.registry || prom_client_1.register],
|
|
120
114
|
}),
|
|
121
|
-
fillLabelsFn: params => {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
typeName: (_b = params.deprecationInfo) === null || _b === void 0 ? void 0 : _b.typeName,
|
|
128
|
-
});
|
|
129
|
-
},
|
|
115
|
+
fillLabelsFn: params => ({
|
|
116
|
+
operationName: params.operationName,
|
|
117
|
+
operationType: params.operationType,
|
|
118
|
+
fieldName: params.deprecationInfo?.fieldName,
|
|
119
|
+
typeName: params.deprecationInfo?.typeName,
|
|
120
|
+
}),
|
|
130
121
|
})
|
|
131
122
|
: undefined;
|
|
132
123
|
const onParse = ({ context, extendContext, params }) => {
|
|
@@ -141,7 +132,7 @@ const usePrometheus = (config = {}) => {
|
|
|
141
132
|
extendContext({
|
|
142
133
|
[promPluginContext]: internalContext,
|
|
143
134
|
});
|
|
144
|
-
parseHistogram
|
|
135
|
+
parseHistogram?.histogram.observe(parseHistogram.fillLabelsFn(internalContext, context), totalTime);
|
|
145
136
|
if (deprecationCounter && typeInfo) {
|
|
146
137
|
const deprecatedFields = (0, utils_js_1.extractDeprecatedFields)(internalContext.document, typeInfo);
|
|
147
138
|
if (deprecatedFields.length > 0) {
|
|
@@ -158,9 +149,11 @@ const usePrometheus = (config = {}) => {
|
|
|
158
149
|
}
|
|
159
150
|
else {
|
|
160
151
|
// means that we got a parse error, report it
|
|
161
|
-
errorsCounter
|
|
152
|
+
errorsCounter?.counter
|
|
153
|
+
.labels({
|
|
162
154
|
phase: 'parse',
|
|
163
|
-
})
|
|
155
|
+
})
|
|
156
|
+
.inc();
|
|
164
157
|
}
|
|
165
158
|
};
|
|
166
159
|
};
|
|
@@ -175,10 +168,12 @@ const usePrometheus = (config = {}) => {
|
|
|
175
168
|
const labels = validateHistogram.fillLabelsFn(context[promPluginContext], context);
|
|
176
169
|
validateHistogram.histogram.observe(labels, totalTime);
|
|
177
170
|
if (!valid) {
|
|
178
|
-
errorsCounter
|
|
171
|
+
errorsCounter?.counter
|
|
172
|
+
.labels({
|
|
179
173
|
...labels,
|
|
180
174
|
phase: 'validate',
|
|
181
|
-
})
|
|
175
|
+
})
|
|
176
|
+
.inc();
|
|
182
177
|
}
|
|
183
178
|
};
|
|
184
179
|
}
|
|
@@ -201,12 +196,14 @@ const usePrometheus = (config = {}) => {
|
|
|
201
196
|
return undefined;
|
|
202
197
|
}
|
|
203
198
|
const startTime = Date.now();
|
|
204
|
-
reqCounter
|
|
199
|
+
reqCounter?.counter
|
|
200
|
+
.labels(reqCounter.fillLabelsFn(args.contextValue[promPluginContext], args.contextValue))
|
|
201
|
+
.inc();
|
|
205
202
|
const result = {
|
|
206
203
|
onExecuteDone: ({ result }) => {
|
|
207
204
|
const totalTime = (Date.now() - startTime) / 1000;
|
|
208
205
|
executeHistogram.histogram.observe(executeHistogram.fillLabelsFn(args.contextValue[promPluginContext], args.contextValue), totalTime);
|
|
209
|
-
requestTotalHistogram
|
|
206
|
+
requestTotalHistogram?.histogram.observe(requestTotalHistogram.fillLabelsFn(args.contextValue[promPluginContext], args.contextValue), totalTime);
|
|
210
207
|
if (requestSummary && args.contextValue[promPluginExecutionStartTimeSymbol]) {
|
|
211
208
|
const summaryTime = (Date.now() - args.contextValue[promPluginExecutionStartTimeSymbol]) / 1000;
|
|
212
209
|
requestSummary.summary.observe(requestSummary.fillLabelsFn(args.contextValue[promPluginContext], args.contextValue), summaryTime);
|
package/cjs/utils.js
CHANGED
|
@@ -17,7 +17,6 @@ function getOperation(document) {
|
|
|
17
17
|
return document.definitions[0];
|
|
18
18
|
}
|
|
19
19
|
function createInternalContext(parseResult) {
|
|
20
|
-
var _a;
|
|
21
20
|
if (parseResult === null) {
|
|
22
21
|
return null;
|
|
23
22
|
}
|
|
@@ -27,7 +26,7 @@ function createInternalContext(parseResult) {
|
|
|
27
26
|
const operation = getOperation(parseResult);
|
|
28
27
|
return {
|
|
29
28
|
document: parseResult,
|
|
30
|
-
operationName:
|
|
29
|
+
operationName: operation.name?.value || 'Anonymous',
|
|
31
30
|
operationType: operation.operation,
|
|
32
31
|
};
|
|
33
32
|
}
|
package/esm/index.js
CHANGED
|
@@ -22,16 +22,13 @@ export const usePrometheus = (config = {}) => {
|
|
|
22
22
|
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName', 'returnType'],
|
|
23
23
|
registers: [config.registry || defaultRegistry],
|
|
24
24
|
}),
|
|
25
|
-
fillLabelsFn: params => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
returnType: (_c = params.info) === null || _c === void 0 ? void 0 : _c.returnType.toString(),
|
|
33
|
-
});
|
|
34
|
-
},
|
|
25
|
+
fillLabelsFn: params => ({
|
|
26
|
+
operationName: params.operationName,
|
|
27
|
+
operationType: params.operationType,
|
|
28
|
+
fieldName: params.info?.fieldName,
|
|
29
|
+
typeName: params.info?.parentType.name,
|
|
30
|
+
returnType: params.info?.returnType.toString(),
|
|
31
|
+
}),
|
|
35
32
|
})
|
|
36
33
|
: undefined;
|
|
37
34
|
const requestTotalHistogram = typeof config.requestTotalDuration === 'object'
|
|
@@ -76,15 +73,12 @@ export const usePrometheus = (config = {}) => {
|
|
|
76
73
|
labelNames: ['operationType', 'operationName', 'path', 'phase'],
|
|
77
74
|
registers: [config.registry || defaultRegistry],
|
|
78
75
|
}),
|
|
79
|
-
fillLabelsFn: params => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
phase: params.errorPhase,
|
|
86
|
-
});
|
|
87
|
-
},
|
|
76
|
+
fillLabelsFn: params => ({
|
|
77
|
+
operationName: params.operationName,
|
|
78
|
+
operationType: params.operationType,
|
|
79
|
+
path: params.error?.path?.join('.'),
|
|
80
|
+
phase: params.errorPhase,
|
|
81
|
+
}),
|
|
88
82
|
})
|
|
89
83
|
: undefined;
|
|
90
84
|
const reqCounter = typeof config.requestCount === 'object'
|
|
@@ -113,15 +107,12 @@ export const usePrometheus = (config = {}) => {
|
|
|
113
107
|
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName'],
|
|
114
108
|
registers: [config.registry || defaultRegistry],
|
|
115
109
|
}),
|
|
116
|
-
fillLabelsFn: params => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
typeName: (_b = params.deprecationInfo) === null || _b === void 0 ? void 0 : _b.typeName,
|
|
123
|
-
});
|
|
124
|
-
},
|
|
110
|
+
fillLabelsFn: params => ({
|
|
111
|
+
operationName: params.operationName,
|
|
112
|
+
operationType: params.operationType,
|
|
113
|
+
fieldName: params.deprecationInfo?.fieldName,
|
|
114
|
+
typeName: params.deprecationInfo?.typeName,
|
|
115
|
+
}),
|
|
125
116
|
})
|
|
126
117
|
: undefined;
|
|
127
118
|
const onParse = ({ context, extendContext, params }) => {
|
|
@@ -136,7 +127,7 @@ export const usePrometheus = (config = {}) => {
|
|
|
136
127
|
extendContext({
|
|
137
128
|
[promPluginContext]: internalContext,
|
|
138
129
|
});
|
|
139
|
-
parseHistogram
|
|
130
|
+
parseHistogram?.histogram.observe(parseHistogram.fillLabelsFn(internalContext, context), totalTime);
|
|
140
131
|
if (deprecationCounter && typeInfo) {
|
|
141
132
|
const deprecatedFields = extractDeprecatedFields(internalContext.document, typeInfo);
|
|
142
133
|
if (deprecatedFields.length > 0) {
|
|
@@ -153,9 +144,11 @@ export const usePrometheus = (config = {}) => {
|
|
|
153
144
|
}
|
|
154
145
|
else {
|
|
155
146
|
// means that we got a parse error, report it
|
|
156
|
-
errorsCounter
|
|
147
|
+
errorsCounter?.counter
|
|
148
|
+
.labels({
|
|
157
149
|
phase: 'parse',
|
|
158
|
-
})
|
|
150
|
+
})
|
|
151
|
+
.inc();
|
|
159
152
|
}
|
|
160
153
|
};
|
|
161
154
|
};
|
|
@@ -170,10 +163,12 @@ export const usePrometheus = (config = {}) => {
|
|
|
170
163
|
const labels = validateHistogram.fillLabelsFn(context[promPluginContext], context);
|
|
171
164
|
validateHistogram.histogram.observe(labels, totalTime);
|
|
172
165
|
if (!valid) {
|
|
173
|
-
errorsCounter
|
|
166
|
+
errorsCounter?.counter
|
|
167
|
+
.labels({
|
|
174
168
|
...labels,
|
|
175
169
|
phase: 'validate',
|
|
176
|
-
})
|
|
170
|
+
})
|
|
171
|
+
.inc();
|
|
177
172
|
}
|
|
178
173
|
};
|
|
179
174
|
}
|
|
@@ -196,12 +191,14 @@ export const usePrometheus = (config = {}) => {
|
|
|
196
191
|
return undefined;
|
|
197
192
|
}
|
|
198
193
|
const startTime = Date.now();
|
|
199
|
-
reqCounter
|
|
194
|
+
reqCounter?.counter
|
|
195
|
+
.labels(reqCounter.fillLabelsFn(args.contextValue[promPluginContext], args.contextValue))
|
|
196
|
+
.inc();
|
|
200
197
|
const result = {
|
|
201
198
|
onExecuteDone: ({ result }) => {
|
|
202
199
|
const totalTime = (Date.now() - startTime) / 1000;
|
|
203
200
|
executeHistogram.histogram.observe(executeHistogram.fillLabelsFn(args.contextValue[promPluginContext], args.contextValue), totalTime);
|
|
204
|
-
requestTotalHistogram
|
|
201
|
+
requestTotalHistogram?.histogram.observe(requestTotalHistogram.fillLabelsFn(args.contextValue[promPluginContext], args.contextValue), totalTime);
|
|
205
202
|
if (requestSummary && args.contextValue[promPluginExecutionStartTimeSymbol]) {
|
|
206
203
|
const summaryTime = (Date.now() - args.contextValue[promPluginExecutionStartTimeSymbol]) / 1000;
|
|
207
204
|
requestSummary.summary.observe(requestSummary.fillLabelsFn(args.contextValue[promPluginContext], args.contextValue), summaryTime);
|
package/esm/utils.js
CHANGED
|
@@ -13,7 +13,6 @@ function getOperation(document) {
|
|
|
13
13
|
return document.definitions[0];
|
|
14
14
|
}
|
|
15
15
|
export function createInternalContext(parseResult) {
|
|
16
|
-
var _a;
|
|
17
16
|
if (parseResult === null) {
|
|
18
17
|
return null;
|
|
19
18
|
}
|
|
@@ -23,7 +22,7 @@ export function createInternalContext(parseResult) {
|
|
|
23
22
|
const operation = getOperation(parseResult);
|
|
24
23
|
return {
|
|
25
24
|
document: parseResult,
|
|
26
|
-
operationName:
|
|
25
|
+
operationName: operation.name?.value || 'Anonymous',
|
|
27
26
|
operationType: operation.operation,
|
|
28
27
|
};
|
|
29
28
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/prometheus",
|
|
3
|
-
"version": "6.6.
|
|
3
|
+
"version": "6.6.1-alpha-20220901205925-b1fd44a9",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "
|
|
6
|
+
"@envelop/core": "2.6.1-alpha-20220901205925-b1fd44a9",
|
|
7
7
|
"prom-client": "^13 || ^14.0.0",
|
|
8
8
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
9
9
|
},
|