@envelop/prometheus 10.0.0 → 11.0.0-alpha-20240726211739-58c6a26f
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/cjs/index.js +58 -142
- package/cjs/utils.js +52 -11
- package/esm/index.js +59 -143
- package/esm/utils.js +49 -10
- package/package.json +1 -1
- package/typings/config.d.cts +24 -20
- package/typings/config.d.ts +24 -20
- package/typings/index.d.cts +1 -1
- package/typings/index.d.ts +1 -1
- package/typings/utils.d.cts +4 -4
- package/typings/utils.d.ts +4 -4
- package/cjs/metrics.js +0 -1
- package/esm/metrics.js +0 -1
- package/typings/metrics.d.cts +0 -0
- package/typings/metrics.d.ts +0 -0
package/cjs/index.js
CHANGED
|
@@ -12,149 +12,65 @@ Object.defineProperty(exports, "createHistogram", { enumerable: true, get: funct
|
|
|
12
12
|
Object.defineProperty(exports, "createSummary", { enumerable: true, get: function () { return utils_js_1.createSummary; } });
|
|
13
13
|
exports.fillLabelsFnParamsMap = new WeakMap();
|
|
14
14
|
exports.execStartTimeMap = new WeakMap();
|
|
15
|
-
const usePrometheus = (config
|
|
15
|
+
const usePrometheus = (config) => {
|
|
16
16
|
let typeInfo = null;
|
|
17
|
-
|
|
18
|
-
const parseHistogram = (0, utils_js_1.getHistogramFromConfig)(config, '
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
: '
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
:
|
|
73
|
-
|
|
74
|
-
registry,
|
|
75
|
-
summary: {
|
|
76
|
-
name: typeof config.requestSummary === 'string'
|
|
77
|
-
? config.requestSummary
|
|
78
|
-
: 'graphql_envelop_request_time_summary',
|
|
79
|
-
help: 'Summary to measure the time to complete GraphQL operations',
|
|
80
|
-
labelNames: ['operationType', 'operationName'].filter(label => (0, utils_js_1.labelExists)(config, label)),
|
|
81
|
-
},
|
|
82
|
-
fillLabelsFn: params => (0, utils_js_1.filterFillParamsFnParams)(config, {
|
|
83
|
-
operationName: params.operationName,
|
|
84
|
-
operationType: params.operationType,
|
|
85
|
-
}),
|
|
86
|
-
})
|
|
87
|
-
: undefined;
|
|
88
|
-
const errorsCounter = typeof config.errors === 'object'
|
|
89
|
-
? config.errors
|
|
90
|
-
: config.errors === true || typeof config.errors === 'string'
|
|
91
|
-
? (0, utils_js_1.createCounter)({
|
|
92
|
-
registry,
|
|
93
|
-
counter: {
|
|
94
|
-
name: typeof config.errors === 'string' ? config.errors : 'graphql_envelop_error_result',
|
|
95
|
-
help: 'Counts the amount of errors reported from all phases',
|
|
96
|
-
labelNames: ['operationType', 'operationName', 'path', 'phase'].filter(label => (0, utils_js_1.labelExists)(config, label)),
|
|
97
|
-
},
|
|
98
|
-
fillLabelsFn: params => (0, utils_js_1.filterFillParamsFnParams)(config, {
|
|
99
|
-
operationName: params.operationName,
|
|
100
|
-
operationType: params.operationType,
|
|
101
|
-
path: params.error?.path?.join('.'),
|
|
102
|
-
phase: params.errorPhase,
|
|
103
|
-
}),
|
|
104
|
-
})
|
|
105
|
-
: undefined;
|
|
106
|
-
const reqCounter = typeof config.requestCount === 'object'
|
|
107
|
-
? config.requestCount
|
|
108
|
-
: config.requestCount === true || typeof config.requestCount === 'string'
|
|
109
|
-
? (0, utils_js_1.createCounter)({
|
|
110
|
-
registry,
|
|
111
|
-
counter: {
|
|
112
|
-
name: typeof config.requestCount === 'string'
|
|
113
|
-
? config.requestCount
|
|
114
|
-
: 'graphql_envelop_request',
|
|
115
|
-
help: 'Counts the amount of GraphQL requests executed through Envelop',
|
|
116
|
-
labelNames: ['operationType', 'operationName'].filter(label => (0, utils_js_1.labelExists)(config, label)),
|
|
117
|
-
},
|
|
118
|
-
fillLabelsFn: params => (0, utils_js_1.filterFillParamsFnParams)(config, {
|
|
119
|
-
operationName: params.operationName,
|
|
120
|
-
operationType: params.operationType,
|
|
121
|
-
}),
|
|
122
|
-
})
|
|
123
|
-
: undefined;
|
|
124
|
-
const deprecationCounter = typeof config.deprecatedFields === 'object'
|
|
125
|
-
? config.deprecatedFields
|
|
126
|
-
: config.deprecatedFields === true || typeof config.deprecatedFields === 'string'
|
|
127
|
-
? (0, utils_js_1.createCounter)({
|
|
128
|
-
registry,
|
|
129
|
-
counter: {
|
|
130
|
-
name: typeof config.deprecatedFields === 'string'
|
|
131
|
-
? config.deprecatedFields
|
|
132
|
-
: 'graphql_envelop_deprecated_field',
|
|
133
|
-
help: 'Counts the amount of deprecated fields used in selection sets',
|
|
134
|
-
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName'].filter(label => (0, utils_js_1.labelExists)(config, label)),
|
|
135
|
-
},
|
|
136
|
-
fillLabelsFn: params => (0, utils_js_1.filterFillParamsFnParams)(config, {
|
|
137
|
-
operationName: params.operationName,
|
|
138
|
-
operationType: params.operationType,
|
|
139
|
-
fieldName: params.deprecationInfo?.fieldName,
|
|
140
|
-
typeName: params.deprecationInfo?.typeName,
|
|
141
|
-
}),
|
|
142
|
-
})
|
|
143
|
-
: undefined;
|
|
144
|
-
const schemaChangeCounter = typeof config.schemaChangeCount === 'object'
|
|
145
|
-
? config.schemaChangeCount
|
|
146
|
-
: config.schemaChangeCount === true || typeof config.schemaChangeCount === 'string'
|
|
147
|
-
? (0, utils_js_1.createCounter)({
|
|
148
|
-
registry,
|
|
149
|
-
counter: {
|
|
150
|
-
name: typeof config.schemaChangeCount === 'string'
|
|
151
|
-
? config.schemaChangeCount
|
|
152
|
-
: 'graphql_envelop_schema_change',
|
|
153
|
-
help: 'Counts the amount of schema changes',
|
|
154
|
-
},
|
|
155
|
-
fillLabelsFn: () => ({}),
|
|
156
|
-
})
|
|
157
|
-
: undefined;
|
|
17
|
+
config.registry = (0, utils_js_1.instrumentRegistry)(config.registry || prom_client_1.register);
|
|
18
|
+
const parseHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_phase_parse', {
|
|
19
|
+
help: 'Time spent on running GraphQL "parse" function',
|
|
20
|
+
});
|
|
21
|
+
const validateHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_phase_validate', {
|
|
22
|
+
help: 'Time spent on running GraphQL "validate" function',
|
|
23
|
+
});
|
|
24
|
+
const contextBuildingHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_phase_context', {
|
|
25
|
+
help: 'Time spent on building the GraphQL context',
|
|
26
|
+
});
|
|
27
|
+
const executeHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_phase_execute', {
|
|
28
|
+
help: 'Time spent on running the GraphQL "execute" function',
|
|
29
|
+
});
|
|
30
|
+
const subscribeHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_phase_subscribe', {
|
|
31
|
+
help: 'Time spent on running the GraphQL "subscribe" function',
|
|
32
|
+
});
|
|
33
|
+
const resolversHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_execute_resolver', {
|
|
34
|
+
help: 'Time spent on running the GraphQL resolvers',
|
|
35
|
+
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName', 'returnType'].filter(label => (0, utils_js_1.labelExists)(config, label)),
|
|
36
|
+
}, params => (0, utils_js_1.filterFillParamsFnParams)(config, {
|
|
37
|
+
operationName: params.operationName,
|
|
38
|
+
operationType: params.operationType,
|
|
39
|
+
fieldName: params.info?.fieldName,
|
|
40
|
+
typeName: params.info?.parentType.name,
|
|
41
|
+
returnType: params.info?.returnType.toString(),
|
|
42
|
+
}));
|
|
43
|
+
const requestTotalHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_request_duration', {
|
|
44
|
+
help: 'Time spent on running the GraphQL operation from parse to execute',
|
|
45
|
+
});
|
|
46
|
+
const requestSummary = (0, utils_js_1.getSummaryFromConfig)(config, 'graphql_envelop_request_time_summary', {
|
|
47
|
+
help: 'Summary to measure the time to complete GraphQL operations',
|
|
48
|
+
});
|
|
49
|
+
const errorsCounter = (0, utils_js_1.getCounterFromConfig)(config, 'graphql_envelop_error_result', {
|
|
50
|
+
help: 'Counts the amount of errors reported from all phases',
|
|
51
|
+
labelNames: ['operationType', 'operationName', 'path', 'phase'].filter(label => (0, utils_js_1.labelExists)(config, label)),
|
|
52
|
+
}, params => (0, utils_js_1.filterFillParamsFnParams)(config, {
|
|
53
|
+
operationName: params.operationName,
|
|
54
|
+
operationType: params.operationType,
|
|
55
|
+
path: params.error?.path?.join('.'),
|
|
56
|
+
phase: params.errorPhase,
|
|
57
|
+
}));
|
|
58
|
+
const reqCounter = (0, utils_js_1.getCounterFromConfig)(config, 'graphql_envelop_request', {
|
|
59
|
+
help: 'Counts the amount of GraphQL requests executed through Envelop',
|
|
60
|
+
});
|
|
61
|
+
const deprecationCounter = (0, utils_js_1.getCounterFromConfig)(config, 'graphql_envelop_deprecated_field', {
|
|
62
|
+
help: 'Counts the amount of deprecated fields used in selection sets',
|
|
63
|
+
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName'].filter(label => (0, utils_js_1.labelExists)(config, label)),
|
|
64
|
+
}, params => (0, utils_js_1.filterFillParamsFnParams)(config, {
|
|
65
|
+
operationName: params.operationName,
|
|
66
|
+
operationType: params.operationType,
|
|
67
|
+
fieldName: params.deprecationInfo?.fieldName,
|
|
68
|
+
typeName: params.deprecationInfo?.typeName,
|
|
69
|
+
}));
|
|
70
|
+
const schemaChangeCounter = (0, utils_js_1.getCounterFromConfig)(config, 'graphql_envelop_schema_change', {
|
|
71
|
+
help: 'Counts the amount of schema changes',
|
|
72
|
+
labelNames: [],
|
|
73
|
+
}, () => ({}));
|
|
158
74
|
const onParse = ({ context, params }) => {
|
|
159
75
|
if (config.skipIntrospection && (0, core_1.isIntrospectionOperationString)(params.source)) {
|
|
160
76
|
return;
|
package/cjs/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.instrumentRegistry = exports.filterFillParamsFnParams = exports.labelExists = exports.extractDeprecatedFields = exports.getHistogramFromConfig = exports.createCounter = exports.registerCounter = exports.createSummary = exports.registerSummary = exports.createHistogram = exports.registerHistogram = exports.createFillLabelFnParams = exports.shouldTraceFieldResolver = void 0;
|
|
3
|
+
exports.instrumentRegistry = exports.filterFillParamsFnParams = exports.labelExists = exports.extractDeprecatedFields = exports.getCounterFromConfig = exports.getSummaryFromConfig = exports.getHistogramFromConfig = exports.createCounter = exports.registerCounter = exports.createSummary = exports.registerSummary = exports.createHistogram = exports.registerHistogram = exports.createFillLabelFnParams = exports.shouldTraceFieldResolver = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
const prom_client_1 = require("prom-client");
|
|
6
6
|
const histograms = new WeakMap();
|
|
@@ -92,25 +92,66 @@ function createCounter(options) {
|
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
94
|
exports.createCounter = createCounter;
|
|
95
|
-
function getHistogramFromConfig(config, phase,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
function getHistogramFromConfig(config, phase, histogram, fillLabelsFn = params => filterFillParamsFnParams(config, {
|
|
96
|
+
operationName: params.operationName,
|
|
97
|
+
operationType: params.operationType,
|
|
98
|
+
})) {
|
|
99
|
+
const metric = config.metrics[phase];
|
|
100
|
+
return typeof metric === 'object'
|
|
101
|
+
? metric
|
|
102
|
+
: metric === true
|
|
99
103
|
? createHistogram({
|
|
100
104
|
registry: config.registry || prom_client_1.register,
|
|
101
105
|
histogram: {
|
|
102
|
-
name,
|
|
103
|
-
help,
|
|
106
|
+
name: typeof metric === 'string' ? metric : phase,
|
|
104
107
|
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
|
|
108
|
+
...histogram,
|
|
105
109
|
},
|
|
106
|
-
fillLabelsFn
|
|
107
|
-
operationName: params.operationName,
|
|
108
|
-
operationType: params.operationType,
|
|
109
|
-
}),
|
|
110
|
+
fillLabelsFn,
|
|
110
111
|
})
|
|
111
112
|
: undefined;
|
|
112
113
|
}
|
|
113
114
|
exports.getHistogramFromConfig = getHistogramFromConfig;
|
|
115
|
+
function getSummaryFromConfig(config, phase, summary, fillLabelsFn = params => filterFillParamsFnParams(config, {
|
|
116
|
+
operationName: params.operationName,
|
|
117
|
+
operationType: params.operationType,
|
|
118
|
+
})) {
|
|
119
|
+
const metric = config.metrics[phase];
|
|
120
|
+
return typeof metric === 'object'
|
|
121
|
+
? metric
|
|
122
|
+
: metric === true
|
|
123
|
+
? createSummary({
|
|
124
|
+
registry: config.registry || prom_client_1.register,
|
|
125
|
+
summary: {
|
|
126
|
+
name: typeof metric === 'string' ? metric : phase,
|
|
127
|
+
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
|
|
128
|
+
...summary,
|
|
129
|
+
},
|
|
130
|
+
fillLabelsFn,
|
|
131
|
+
})
|
|
132
|
+
: undefined;
|
|
133
|
+
}
|
|
134
|
+
exports.getSummaryFromConfig = getSummaryFromConfig;
|
|
135
|
+
function getCounterFromConfig(config, phase, counter, fillLabelsFn = params => filterFillParamsFnParams(config, {
|
|
136
|
+
operationName: params.operationName,
|
|
137
|
+
operationType: params.operationType,
|
|
138
|
+
})) {
|
|
139
|
+
const metric = config.metrics[phase];
|
|
140
|
+
return typeof metric === 'object'
|
|
141
|
+
? metric
|
|
142
|
+
: metric === true
|
|
143
|
+
? createCounter({
|
|
144
|
+
registry: config.registry || prom_client_1.register,
|
|
145
|
+
counter: {
|
|
146
|
+
name: typeof metric === 'string' ? metric : phase,
|
|
147
|
+
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
|
|
148
|
+
...counter,
|
|
149
|
+
},
|
|
150
|
+
fillLabelsFn,
|
|
151
|
+
})
|
|
152
|
+
: undefined;
|
|
153
|
+
}
|
|
154
|
+
exports.getCounterFromConfig = getCounterFromConfig;
|
|
114
155
|
function extractDeprecatedFields(node, typeInfo) {
|
|
115
156
|
const found = [];
|
|
116
157
|
(0, graphql_1.visit)(node, (0, graphql_1.visitWithTypeInfo)(typeInfo, {
|
package/esm/index.js
CHANGED
|
@@ -3,153 +3,69 @@ import { TypeInfo } from 'graphql';
|
|
|
3
3
|
import { register as defaultRegistry } from 'prom-client';
|
|
4
4
|
import { isAsyncIterable, isIntrospectionOperationString, } from '@envelop/core';
|
|
5
5
|
import { useOnResolve } from '@envelop/on-resolve';
|
|
6
|
-
import { createCounter, createFillLabelFnParams, createHistogram, createSummary, extractDeprecatedFields, filterFillParamsFnParams, getHistogramFromConfig, instrumentRegistry, labelExists, shouldTraceFieldResolver, } from './utils.js';
|
|
6
|
+
import { createCounter, createFillLabelFnParams, createHistogram, createSummary, extractDeprecatedFields, filterFillParamsFnParams, getCounterFromConfig, getHistogramFromConfig, getSummaryFromConfig, instrumentRegistry, labelExists, shouldTraceFieldResolver, } from './utils.js';
|
|
7
7
|
export { createCounter, createHistogram, createSummary, };
|
|
8
8
|
export const fillLabelsFnParamsMap = new WeakMap();
|
|
9
9
|
export const execStartTimeMap = new WeakMap();
|
|
10
|
-
export const usePrometheus = (config
|
|
10
|
+
export const usePrometheus = (config) => {
|
|
11
11
|
let typeInfo = null;
|
|
12
|
-
|
|
13
|
-
const parseHistogram = getHistogramFromConfig(config, '
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
: '
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
:
|
|
68
|
-
|
|
69
|
-
registry,
|
|
70
|
-
summary: {
|
|
71
|
-
name: typeof config.requestSummary === 'string'
|
|
72
|
-
? config.requestSummary
|
|
73
|
-
: 'graphql_envelop_request_time_summary',
|
|
74
|
-
help: 'Summary to measure the time to complete GraphQL operations',
|
|
75
|
-
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
|
|
76
|
-
},
|
|
77
|
-
fillLabelsFn: params => filterFillParamsFnParams(config, {
|
|
78
|
-
operationName: params.operationName,
|
|
79
|
-
operationType: params.operationType,
|
|
80
|
-
}),
|
|
81
|
-
})
|
|
82
|
-
: undefined;
|
|
83
|
-
const errorsCounter = typeof config.errors === 'object'
|
|
84
|
-
? config.errors
|
|
85
|
-
: config.errors === true || typeof config.errors === 'string'
|
|
86
|
-
? createCounter({
|
|
87
|
-
registry,
|
|
88
|
-
counter: {
|
|
89
|
-
name: typeof config.errors === 'string' ? config.errors : 'graphql_envelop_error_result',
|
|
90
|
-
help: 'Counts the amount of errors reported from all phases',
|
|
91
|
-
labelNames: ['operationType', 'operationName', 'path', 'phase'].filter(label => labelExists(config, label)),
|
|
92
|
-
},
|
|
93
|
-
fillLabelsFn: params => filterFillParamsFnParams(config, {
|
|
94
|
-
operationName: params.operationName,
|
|
95
|
-
operationType: params.operationType,
|
|
96
|
-
path: params.error?.path?.join('.'),
|
|
97
|
-
phase: params.errorPhase,
|
|
98
|
-
}),
|
|
99
|
-
})
|
|
100
|
-
: undefined;
|
|
101
|
-
const reqCounter = typeof config.requestCount === 'object'
|
|
102
|
-
? config.requestCount
|
|
103
|
-
: config.requestCount === true || typeof config.requestCount === 'string'
|
|
104
|
-
? createCounter({
|
|
105
|
-
registry,
|
|
106
|
-
counter: {
|
|
107
|
-
name: typeof config.requestCount === 'string'
|
|
108
|
-
? config.requestCount
|
|
109
|
-
: 'graphql_envelop_request',
|
|
110
|
-
help: 'Counts the amount of GraphQL requests executed through Envelop',
|
|
111
|
-
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
|
|
112
|
-
},
|
|
113
|
-
fillLabelsFn: params => filterFillParamsFnParams(config, {
|
|
114
|
-
operationName: params.operationName,
|
|
115
|
-
operationType: params.operationType,
|
|
116
|
-
}),
|
|
117
|
-
})
|
|
118
|
-
: undefined;
|
|
119
|
-
const deprecationCounter = typeof config.deprecatedFields === 'object'
|
|
120
|
-
? config.deprecatedFields
|
|
121
|
-
: config.deprecatedFields === true || typeof config.deprecatedFields === 'string'
|
|
122
|
-
? createCounter({
|
|
123
|
-
registry,
|
|
124
|
-
counter: {
|
|
125
|
-
name: typeof config.deprecatedFields === 'string'
|
|
126
|
-
? config.deprecatedFields
|
|
127
|
-
: 'graphql_envelop_deprecated_field',
|
|
128
|
-
help: 'Counts the amount of deprecated fields used in selection sets',
|
|
129
|
-
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName'].filter(label => labelExists(config, label)),
|
|
130
|
-
},
|
|
131
|
-
fillLabelsFn: params => filterFillParamsFnParams(config, {
|
|
132
|
-
operationName: params.operationName,
|
|
133
|
-
operationType: params.operationType,
|
|
134
|
-
fieldName: params.deprecationInfo?.fieldName,
|
|
135
|
-
typeName: params.deprecationInfo?.typeName,
|
|
136
|
-
}),
|
|
137
|
-
})
|
|
138
|
-
: undefined;
|
|
139
|
-
const schemaChangeCounter = typeof config.schemaChangeCount === 'object'
|
|
140
|
-
? config.schemaChangeCount
|
|
141
|
-
: config.schemaChangeCount === true || typeof config.schemaChangeCount === 'string'
|
|
142
|
-
? createCounter({
|
|
143
|
-
registry,
|
|
144
|
-
counter: {
|
|
145
|
-
name: typeof config.schemaChangeCount === 'string'
|
|
146
|
-
? config.schemaChangeCount
|
|
147
|
-
: 'graphql_envelop_schema_change',
|
|
148
|
-
help: 'Counts the amount of schema changes',
|
|
149
|
-
},
|
|
150
|
-
fillLabelsFn: () => ({}),
|
|
151
|
-
})
|
|
152
|
-
: undefined;
|
|
12
|
+
config.registry = instrumentRegistry(config.registry || defaultRegistry);
|
|
13
|
+
const parseHistogram = getHistogramFromConfig(config, 'graphql_envelop_phase_parse', {
|
|
14
|
+
help: 'Time spent on running GraphQL "parse" function',
|
|
15
|
+
});
|
|
16
|
+
const validateHistogram = getHistogramFromConfig(config, 'graphql_envelop_phase_validate', {
|
|
17
|
+
help: 'Time spent on running GraphQL "validate" function',
|
|
18
|
+
});
|
|
19
|
+
const contextBuildingHistogram = getHistogramFromConfig(config, 'graphql_envelop_phase_context', {
|
|
20
|
+
help: 'Time spent on building the GraphQL context',
|
|
21
|
+
});
|
|
22
|
+
const executeHistogram = getHistogramFromConfig(config, 'graphql_envelop_phase_execute', {
|
|
23
|
+
help: 'Time spent on running the GraphQL "execute" function',
|
|
24
|
+
});
|
|
25
|
+
const subscribeHistogram = getHistogramFromConfig(config, 'graphql_envelop_phase_subscribe', {
|
|
26
|
+
help: 'Time spent on running the GraphQL "subscribe" function',
|
|
27
|
+
});
|
|
28
|
+
const resolversHistogram = getHistogramFromConfig(config, 'graphql_envelop_execute_resolver', {
|
|
29
|
+
help: 'Time spent on running the GraphQL resolvers',
|
|
30
|
+
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName', 'returnType'].filter(label => labelExists(config, label)),
|
|
31
|
+
}, params => filterFillParamsFnParams(config, {
|
|
32
|
+
operationName: params.operationName,
|
|
33
|
+
operationType: params.operationType,
|
|
34
|
+
fieldName: params.info?.fieldName,
|
|
35
|
+
typeName: params.info?.parentType.name,
|
|
36
|
+
returnType: params.info?.returnType.toString(),
|
|
37
|
+
}));
|
|
38
|
+
const requestTotalHistogram = getHistogramFromConfig(config, 'graphql_envelop_request_duration', {
|
|
39
|
+
help: 'Time spent on running the GraphQL operation from parse to execute',
|
|
40
|
+
});
|
|
41
|
+
const requestSummary = getSummaryFromConfig(config, 'graphql_envelop_request_time_summary', {
|
|
42
|
+
help: 'Summary to measure the time to complete GraphQL operations',
|
|
43
|
+
});
|
|
44
|
+
const errorsCounter = getCounterFromConfig(config, 'graphql_envelop_error_result', {
|
|
45
|
+
help: 'Counts the amount of errors reported from all phases',
|
|
46
|
+
labelNames: ['operationType', 'operationName', 'path', 'phase'].filter(label => labelExists(config, label)),
|
|
47
|
+
}, params => filterFillParamsFnParams(config, {
|
|
48
|
+
operationName: params.operationName,
|
|
49
|
+
operationType: params.operationType,
|
|
50
|
+
path: params.error?.path?.join('.'),
|
|
51
|
+
phase: params.errorPhase,
|
|
52
|
+
}));
|
|
53
|
+
const reqCounter = getCounterFromConfig(config, 'graphql_envelop_request', {
|
|
54
|
+
help: 'Counts the amount of GraphQL requests executed through Envelop',
|
|
55
|
+
});
|
|
56
|
+
const deprecationCounter = getCounterFromConfig(config, 'graphql_envelop_deprecated_field', {
|
|
57
|
+
help: 'Counts the amount of deprecated fields used in selection sets',
|
|
58
|
+
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName'].filter(label => labelExists(config, label)),
|
|
59
|
+
}, params => filterFillParamsFnParams(config, {
|
|
60
|
+
operationName: params.operationName,
|
|
61
|
+
operationType: params.operationType,
|
|
62
|
+
fieldName: params.deprecationInfo?.fieldName,
|
|
63
|
+
typeName: params.deprecationInfo?.typeName,
|
|
64
|
+
}));
|
|
65
|
+
const schemaChangeCounter = getCounterFromConfig(config, 'graphql_envelop_schema_change', {
|
|
66
|
+
help: 'Counts the amount of schema changes',
|
|
67
|
+
labelNames: [],
|
|
68
|
+
}, () => ({}));
|
|
153
69
|
const onParse = ({ context, params }) => {
|
|
154
70
|
if (config.skipIntrospection && isIntrospectionOperationString(params.source)) {
|
|
155
71
|
return;
|
package/esm/utils.js
CHANGED
|
@@ -81,21 +81,60 @@ export function createCounter(options) {
|
|
|
81
81
|
fillLabelsFn: options.fillLabelsFn,
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
-
export function getHistogramFromConfig(config, phase,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
export function getHistogramFromConfig(config, phase, histogram, fillLabelsFn = params => filterFillParamsFnParams(config, {
|
|
85
|
+
operationName: params.operationName,
|
|
86
|
+
operationType: params.operationType,
|
|
87
|
+
})) {
|
|
88
|
+
const metric = config.metrics[phase];
|
|
89
|
+
return typeof metric === 'object'
|
|
90
|
+
? metric
|
|
91
|
+
: metric === true
|
|
88
92
|
? createHistogram({
|
|
89
93
|
registry: config.registry || defaultRegistry,
|
|
90
94
|
histogram: {
|
|
91
|
-
name,
|
|
92
|
-
help,
|
|
95
|
+
name: typeof metric === 'string' ? metric : phase,
|
|
93
96
|
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
|
|
97
|
+
...histogram,
|
|
94
98
|
},
|
|
95
|
-
fillLabelsFn
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
fillLabelsFn,
|
|
100
|
+
})
|
|
101
|
+
: undefined;
|
|
102
|
+
}
|
|
103
|
+
export function getSummaryFromConfig(config, phase, summary, fillLabelsFn = params => filterFillParamsFnParams(config, {
|
|
104
|
+
operationName: params.operationName,
|
|
105
|
+
operationType: params.operationType,
|
|
106
|
+
})) {
|
|
107
|
+
const metric = config.metrics[phase];
|
|
108
|
+
return typeof metric === 'object'
|
|
109
|
+
? metric
|
|
110
|
+
: metric === true
|
|
111
|
+
? createSummary({
|
|
112
|
+
registry: config.registry || defaultRegistry,
|
|
113
|
+
summary: {
|
|
114
|
+
name: typeof metric === 'string' ? metric : phase,
|
|
115
|
+
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
|
|
116
|
+
...summary,
|
|
117
|
+
},
|
|
118
|
+
fillLabelsFn,
|
|
119
|
+
})
|
|
120
|
+
: undefined;
|
|
121
|
+
}
|
|
122
|
+
export function getCounterFromConfig(config, phase, counter, fillLabelsFn = params => filterFillParamsFnParams(config, {
|
|
123
|
+
operationName: params.operationName,
|
|
124
|
+
operationType: params.operationType,
|
|
125
|
+
})) {
|
|
126
|
+
const metric = config.metrics[phase];
|
|
127
|
+
return typeof metric === 'object'
|
|
128
|
+
? metric
|
|
129
|
+
: metric === true
|
|
130
|
+
? createCounter({
|
|
131
|
+
registry: config.registry || defaultRegistry,
|
|
132
|
+
counter: {
|
|
133
|
+
name: typeof metric === 'string' ? metric : phase,
|
|
134
|
+
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
|
|
135
|
+
...counter,
|
|
136
|
+
},
|
|
137
|
+
fillLabelsFn,
|
|
99
138
|
})
|
|
100
139
|
: undefined;
|
|
101
140
|
}
|
package/package.json
CHANGED
package/typings/config.d.cts
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
import { Registry } from 'prom-client';
|
|
2
2
|
import { createCounter, createHistogram, createSummary } from './utils.cjs';
|
|
3
3
|
export type PrometheusTracingPluginConfig = {
|
|
4
|
-
requestCount?: boolean | string | ReturnType<typeof createCounter>;
|
|
5
|
-
requestTotalDuration?: boolean | string | ReturnType<typeof createHistogram>;
|
|
6
|
-
requestSummary?: boolean | string | ReturnType<typeof createSummary>;
|
|
7
|
-
parse?: boolean | string | ReturnType<typeof createHistogram>;
|
|
8
|
-
validate?: boolean | string | ReturnType<typeof createHistogram>;
|
|
9
|
-
contextBuilding?: boolean | string | ReturnType<typeof createHistogram>;
|
|
10
|
-
execute?: boolean | string | ReturnType<typeof createHistogram>;
|
|
11
|
-
subscribe?: boolean | string | ReturnType<typeof createHistogram>;
|
|
12
|
-
errors?: boolean | string | ReturnType<typeof createCounter>;
|
|
13
|
-
resolvers?: boolean | string | ReturnType<typeof createHistogram>;
|
|
14
|
-
resolversWhitelist?: string[];
|
|
15
|
-
deprecatedFields?: boolean | string | ReturnType<typeof createCounter>;
|
|
16
4
|
registry?: Registry;
|
|
17
5
|
skipIntrospection?: boolean;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
resolversWhitelist?: string[];
|
|
7
|
+
metrics: MetricsConfig;
|
|
8
|
+
labels?: LabelsConfig;
|
|
9
|
+
};
|
|
10
|
+
export type MetricsConfig = {
|
|
11
|
+
graphql_envelop_request?: boolean | string | ReturnType<typeof createCounter>;
|
|
12
|
+
graphql_envelop_request_duration?: boolean | string | ReturnType<typeof createHistogram>;
|
|
13
|
+
graphql_envelop_request_time_summary?: boolean | string | ReturnType<typeof createSummary>;
|
|
14
|
+
graphql_envelop_phase_parse?: boolean | string | ReturnType<typeof createHistogram>;
|
|
15
|
+
graphql_envelop_phase_validate?: boolean | string | ReturnType<typeof createHistogram>;
|
|
16
|
+
graphql_envelop_phase_context?: boolean | string | ReturnType<typeof createHistogram>;
|
|
17
|
+
graphql_envelop_phase_execute?: boolean | string | ReturnType<typeof createHistogram>;
|
|
18
|
+
graphql_envelop_phase_subscribe?: boolean | string | ReturnType<typeof createHistogram>;
|
|
19
|
+
graphql_envelop_error_result?: boolean | string | ReturnType<typeof createCounter>;
|
|
20
|
+
graphql_envelop_deprecated_field?: boolean | string | ReturnType<typeof createCounter>;
|
|
21
|
+
graphql_envelop_schema_change?: boolean | string | ReturnType<typeof createCounter>;
|
|
22
|
+
graphql_envelop_execute_resolver?: boolean | string | ReturnType<typeof createHistogram>;
|
|
23
|
+
};
|
|
24
|
+
export type LabelsConfig = {
|
|
25
|
+
operationName?: boolean;
|
|
26
|
+
operationType?: boolean;
|
|
27
|
+
fieldName?: boolean;
|
|
28
|
+
typeName?: boolean;
|
|
29
|
+
returnType?: boolean;
|
|
26
30
|
};
|
package/typings/config.d.ts
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
import { Registry } from 'prom-client';
|
|
2
2
|
import { createCounter, createHistogram, createSummary } from './utils.js';
|
|
3
3
|
export type PrometheusTracingPluginConfig = {
|
|
4
|
-
requestCount?: boolean | string | ReturnType<typeof createCounter>;
|
|
5
|
-
requestTotalDuration?: boolean | string | ReturnType<typeof createHistogram>;
|
|
6
|
-
requestSummary?: boolean | string | ReturnType<typeof createSummary>;
|
|
7
|
-
parse?: boolean | string | ReturnType<typeof createHistogram>;
|
|
8
|
-
validate?: boolean | string | ReturnType<typeof createHistogram>;
|
|
9
|
-
contextBuilding?: boolean | string | ReturnType<typeof createHistogram>;
|
|
10
|
-
execute?: boolean | string | ReturnType<typeof createHistogram>;
|
|
11
|
-
subscribe?: boolean | string | ReturnType<typeof createHistogram>;
|
|
12
|
-
errors?: boolean | string | ReturnType<typeof createCounter>;
|
|
13
|
-
resolvers?: boolean | string | ReturnType<typeof createHistogram>;
|
|
14
|
-
resolversWhitelist?: string[];
|
|
15
|
-
deprecatedFields?: boolean | string | ReturnType<typeof createCounter>;
|
|
16
4
|
registry?: Registry;
|
|
17
5
|
skipIntrospection?: boolean;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
resolversWhitelist?: string[];
|
|
7
|
+
metrics: MetricsConfig;
|
|
8
|
+
labels?: LabelsConfig;
|
|
9
|
+
};
|
|
10
|
+
export type MetricsConfig = {
|
|
11
|
+
graphql_envelop_request?: boolean | string | ReturnType<typeof createCounter>;
|
|
12
|
+
graphql_envelop_request_duration?: boolean | string | ReturnType<typeof createHistogram>;
|
|
13
|
+
graphql_envelop_request_time_summary?: boolean | string | ReturnType<typeof createSummary>;
|
|
14
|
+
graphql_envelop_phase_parse?: boolean | string | ReturnType<typeof createHistogram>;
|
|
15
|
+
graphql_envelop_phase_validate?: boolean | string | ReturnType<typeof createHistogram>;
|
|
16
|
+
graphql_envelop_phase_context?: boolean | string | ReturnType<typeof createHistogram>;
|
|
17
|
+
graphql_envelop_phase_execute?: boolean | string | ReturnType<typeof createHistogram>;
|
|
18
|
+
graphql_envelop_phase_subscribe?: boolean | string | ReturnType<typeof createHistogram>;
|
|
19
|
+
graphql_envelop_error_result?: boolean | string | ReturnType<typeof createCounter>;
|
|
20
|
+
graphql_envelop_deprecated_field?: boolean | string | ReturnType<typeof createCounter>;
|
|
21
|
+
graphql_envelop_schema_change?: boolean | string | ReturnType<typeof createCounter>;
|
|
22
|
+
graphql_envelop_execute_resolver?: boolean | string | ReturnType<typeof createHistogram>;
|
|
23
|
+
};
|
|
24
|
+
export type LabelsConfig = {
|
|
25
|
+
operationName?: boolean;
|
|
26
|
+
operationType?: boolean;
|
|
27
|
+
fieldName?: boolean;
|
|
28
|
+
typeName?: boolean;
|
|
29
|
+
returnType?: boolean;
|
|
26
30
|
};
|
package/typings/index.d.cts
CHANGED
|
@@ -4,4 +4,4 @@ import { createCounter, createHistogram, createSummary, FillLabelsFnParams, type
|
|
|
4
4
|
export { CounterAndLabels, FillLabelsFnParams, HistogramAndLabels, PrometheusTracingPluginConfig, SummaryAndLabels, createCounter, createHistogram, createSummary, };
|
|
5
5
|
export declare const fillLabelsFnParamsMap: WeakMap<any, FillLabelsFnParams | null>;
|
|
6
6
|
export declare const execStartTimeMap: WeakMap<any, number>;
|
|
7
|
-
export declare const usePrometheus: (config
|
|
7
|
+
export declare const usePrometheus: (config: PrometheusTracingPluginConfig) => Plugin;
|
package/typings/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ import { createCounter, createHistogram, createSummary, FillLabelsFnParams, type
|
|
|
4
4
|
export { CounterAndLabels, FillLabelsFnParams, HistogramAndLabels, PrometheusTracingPluginConfig, SummaryAndLabels, createCounter, createHistogram, createSummary, };
|
|
5
5
|
export declare const fillLabelsFnParamsMap: WeakMap<any, FillLabelsFnParams | null>;
|
|
6
6
|
export declare const execStartTimeMap: WeakMap<any, number>;
|
|
7
|
-
export declare const usePrometheus: (config
|
|
7
|
+
export declare const usePrometheus: (config: PrometheusTracingPluginConfig) => Plugin;
|
package/typings/utils.d.cts
CHANGED
|
@@ -48,10 +48,10 @@ export declare function createCounter<LabelNames extends string, Params extends
|
|
|
48
48
|
counter: Omit<CounterConfiguration<LabelNames>, 'registers'>;
|
|
49
49
|
fillLabelsFn: FillLabelsFn<LabelNames, Params>;
|
|
50
50
|
}): CounterAndLabels<LabelNames, Params>;
|
|
51
|
-
export declare function getHistogramFromConfig(config: PrometheusTracingPluginConfig, phase: keyof PrometheusTracingPluginConfig,
|
|
51
|
+
export declare function getHistogramFromConfig<Params extends Record<string, any> = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof PrometheusTracingPluginConfig['metrics'], histogram: Omit<HistogramConfiguration<string>, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn<string, Params>): ReturnType<typeof createHistogram<string, Params>> | undefined;
|
|
52
|
+
export declare function getSummaryFromConfig<Params extends Record<string, any> = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof PrometheusTracingPluginConfig['metrics'], summary: Omit<SummaryConfiguration<string>, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn<string, Params>): ReturnType<typeof createSummary<string, Params>> | undefined;
|
|
53
|
+
export declare function getCounterFromConfig<Params extends Record<string, any> = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof PrometheusTracingPluginConfig['metrics'], counter: Omit<CounterConfiguration<string>, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn<string, Params>): ReturnType<typeof createCounter<string, Params>> | undefined;
|
|
52
54
|
export declare function extractDeprecatedFields(node: ASTNode, typeInfo: TypeInfo): DeprecatedFieldInfo[];
|
|
53
55
|
export declare function labelExists(config: PrometheusTracingPluginConfig, label: string): any;
|
|
54
|
-
export declare function filterFillParamsFnParams(config: PrometheusTracingPluginConfig, params: Record<
|
|
55
|
-
[k: string]: any;
|
|
56
|
-
};
|
|
56
|
+
export declare function filterFillParamsFnParams<T extends string>(config: PrometheusTracingPluginConfig, params: Partial<Record<T, any>>): Record<T, any>;
|
|
57
57
|
export declare function instrumentRegistry(registry: Registry): Registry<"text/plain; version=0.0.4; charset=utf-8">;
|
package/typings/utils.d.ts
CHANGED
|
@@ -48,10 +48,10 @@ export declare function createCounter<LabelNames extends string, Params extends
|
|
|
48
48
|
counter: Omit<CounterConfiguration<LabelNames>, 'registers'>;
|
|
49
49
|
fillLabelsFn: FillLabelsFn<LabelNames, Params>;
|
|
50
50
|
}): CounterAndLabels<LabelNames, Params>;
|
|
51
|
-
export declare function getHistogramFromConfig(config: PrometheusTracingPluginConfig, phase: keyof PrometheusTracingPluginConfig,
|
|
51
|
+
export declare function getHistogramFromConfig<Params extends Record<string, any> = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof PrometheusTracingPluginConfig['metrics'], histogram: Omit<HistogramConfiguration<string>, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn<string, Params>): ReturnType<typeof createHistogram<string, Params>> | undefined;
|
|
52
|
+
export declare function getSummaryFromConfig<Params extends Record<string, any> = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof PrometheusTracingPluginConfig['metrics'], summary: Omit<SummaryConfiguration<string>, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn<string, Params>): ReturnType<typeof createSummary<string, Params>> | undefined;
|
|
53
|
+
export declare function getCounterFromConfig<Params extends Record<string, any> = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof PrometheusTracingPluginConfig['metrics'], counter: Omit<CounterConfiguration<string>, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn<string, Params>): ReturnType<typeof createCounter<string, Params>> | undefined;
|
|
52
54
|
export declare function extractDeprecatedFields(node: ASTNode, typeInfo: TypeInfo): DeprecatedFieldInfo[];
|
|
53
55
|
export declare function labelExists(config: PrometheusTracingPluginConfig, label: string): any;
|
|
54
|
-
export declare function filterFillParamsFnParams(config: PrometheusTracingPluginConfig, params: Record<
|
|
55
|
-
[k: string]: any;
|
|
56
|
-
};
|
|
56
|
+
export declare function filterFillParamsFnParams<T extends string>(config: PrometheusTracingPluginConfig, params: Partial<Record<T, any>>): Record<T, any>;
|
|
57
57
|
export declare function instrumentRegistry(registry: Registry): Registry<"text/plain; version=0.0.4; charset=utf-8">;
|
package/cjs/metrics.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/esm/metrics.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/typings/metrics.d.cts
DELETED
|
File without changes
|
package/typings/metrics.d.ts
DELETED
|
File without changes
|