@envelop/prometheus 9.3.0 → 9.3.1
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 +13 -23
- package/cjs/utils.js +15 -3
- package/esm/index.js +14 -24
- package/esm/utils.js +12 -2
- package/package.json +1 -1
- package/typings/utils.d.cts +4 -0
- package/typings/utils.d.ts +4 -0
package/cjs/index.js
CHANGED
|
@@ -19,16 +19,6 @@ const usePrometheus = (config = {}) => {
|
|
|
19
19
|
const contextBuildingHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'contextBuilding', 'graphql_envelop_phase_context', 'Time spent on building the GraphQL context');
|
|
20
20
|
const executeHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'execute', 'graphql_envelop_phase_execute', 'Time spent on running the GraphQL "execute" function');
|
|
21
21
|
const subscribeHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'subscribe', 'graphql_envelop_phase_subscribe', 'Time spent on running the GraphQL "subscribe" function');
|
|
22
|
-
function labelExists(label) {
|
|
23
|
-
const labelFlag = config.labels?.[label];
|
|
24
|
-
if (labelFlag == null) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
return labelFlag;
|
|
28
|
-
}
|
|
29
|
-
function filterFillParamsFnParams(params) {
|
|
30
|
-
return Object.fromEntries(Object.entries(params).filter(([key]) => labelExists(key)));
|
|
31
|
-
}
|
|
32
22
|
const resolversHistogram = typeof config.resolvers === 'object'
|
|
33
23
|
? config.resolvers
|
|
34
24
|
: config.resolvers === true
|
|
@@ -42,10 +32,10 @@ const usePrometheus = (config = {}) => {
|
|
|
42
32
|
'fieldName',
|
|
43
33
|
'typeName',
|
|
44
34
|
'returnType',
|
|
45
|
-
].filter(labelExists),
|
|
35
|
+
].filter(label => (0, utils_js_1.labelExists)(config, label)),
|
|
46
36
|
registers: [config.registry || prom_client_1.register],
|
|
47
37
|
}),
|
|
48
|
-
fillLabelsFn: params => filterFillParamsFnParams({
|
|
38
|
+
fillLabelsFn: params => (0, utils_js_1.filterFillParamsFnParams)(config, {
|
|
49
39
|
operationName: params.operationName,
|
|
50
40
|
operationType: params.operationType,
|
|
51
41
|
fieldName: params.info?.fieldName,
|
|
@@ -61,10 +51,10 @@ const usePrometheus = (config = {}) => {
|
|
|
61
51
|
histogram: new prom_client_1.Histogram({
|
|
62
52
|
name: 'graphql_envelop_request_duration',
|
|
63
53
|
help: 'Time spent on running the GraphQL operation from parse to execute',
|
|
64
|
-
labelNames: ['operationType', 'operationName'].filter(labelExists),
|
|
54
|
+
labelNames: ['operationType', 'operationName'].filter(label => (0, utils_js_1.labelExists)(config, label)),
|
|
65
55
|
registers: [config.registry || prom_client_1.register],
|
|
66
56
|
}),
|
|
67
|
-
fillLabelsFn: params => filterFillParamsFnParams({
|
|
57
|
+
fillLabelsFn: params => (0, utils_js_1.filterFillParamsFnParams)(config, {
|
|
68
58
|
operationName: params.operationName,
|
|
69
59
|
operationType: params.operationType,
|
|
70
60
|
}),
|
|
@@ -77,10 +67,10 @@ const usePrometheus = (config = {}) => {
|
|
|
77
67
|
summary: new prom_client_1.Summary({
|
|
78
68
|
name: 'graphql_envelop_request_time_summary',
|
|
79
69
|
help: 'Summary to measure the time to complete GraphQL operations',
|
|
80
|
-
labelNames: ['operationType', 'operationName'].filter(labelExists),
|
|
70
|
+
labelNames: ['operationType', 'operationName'].filter(label => (0, utils_js_1.labelExists)(config, label)),
|
|
81
71
|
registers: [config.registry || prom_client_1.register],
|
|
82
72
|
}),
|
|
83
|
-
fillLabelsFn: params => filterFillParamsFnParams({
|
|
73
|
+
fillLabelsFn: params => (0, utils_js_1.filterFillParamsFnParams)(config, {
|
|
84
74
|
operationName: params.operationName,
|
|
85
75
|
operationType: params.operationType,
|
|
86
76
|
}),
|
|
@@ -93,10 +83,10 @@ const usePrometheus = (config = {}) => {
|
|
|
93
83
|
counter: new prom_client_1.Counter({
|
|
94
84
|
name: 'graphql_envelop_error_result',
|
|
95
85
|
help: 'Counts the amount of errors reported from all phases',
|
|
96
|
-
labelNames: ['operationType', 'operationName', 'path', 'phase'].filter(labelExists),
|
|
86
|
+
labelNames: ['operationType', 'operationName', 'path', 'phase'].filter(label => (0, utils_js_1.labelExists)(config, label)),
|
|
97
87
|
registers: [config.registry || prom_client_1.register],
|
|
98
88
|
}),
|
|
99
|
-
fillLabelsFn: params => filterFillParamsFnParams({
|
|
89
|
+
fillLabelsFn: params => (0, utils_js_1.filterFillParamsFnParams)(config, {
|
|
100
90
|
operationName: params.operationName,
|
|
101
91
|
operationType: params.operationType,
|
|
102
92
|
path: params.error?.path?.join('.'),
|
|
@@ -111,10 +101,10 @@ const usePrometheus = (config = {}) => {
|
|
|
111
101
|
counter: new prom_client_1.Counter({
|
|
112
102
|
name: 'graphql_envelop_request',
|
|
113
103
|
help: 'Counts the amount of GraphQL requests executed through Envelop',
|
|
114
|
-
labelNames: ['operationType', 'operationName'].filter(labelExists),
|
|
104
|
+
labelNames: ['operationType', 'operationName'].filter(label => (0, utils_js_1.labelExists)(config, label)),
|
|
115
105
|
registers: [config.registry || prom_client_1.register],
|
|
116
106
|
}),
|
|
117
|
-
fillLabelsFn: params => filterFillParamsFnParams({
|
|
107
|
+
fillLabelsFn: params => (0, utils_js_1.filterFillParamsFnParams)(config, {
|
|
118
108
|
operationName: params.operationName,
|
|
119
109
|
operationType: params.operationType,
|
|
120
110
|
}),
|
|
@@ -127,10 +117,10 @@ const usePrometheus = (config = {}) => {
|
|
|
127
117
|
counter: new prom_client_1.Counter({
|
|
128
118
|
name: 'graphql_envelop_deprecated_field',
|
|
129
119
|
help: 'Counts the amount of deprecated fields used in selection sets',
|
|
130
|
-
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName'].filter(labelExists),
|
|
120
|
+
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName'].filter(label => (0, utils_js_1.labelExists)(config, label)),
|
|
131
121
|
registers: [config.registry || prom_client_1.register],
|
|
132
122
|
}),
|
|
133
|
-
fillLabelsFn: params => filterFillParamsFnParams({
|
|
123
|
+
fillLabelsFn: params => (0, utils_js_1.filterFillParamsFnParams)(config, {
|
|
134
124
|
operationName: params.operationName,
|
|
135
125
|
operationType: params.operationType,
|
|
136
126
|
fieldName: params.deprecationInfo?.fieldName,
|
|
@@ -159,7 +149,7 @@ const usePrometheus = (config = {}) => {
|
|
|
159
149
|
const totalTime = (Date.now() - startTime) / 1000;
|
|
160
150
|
let fillLabelsFnParams = exports.fillLabelsFnParamsMap.get(params.result);
|
|
161
151
|
if (!fillLabelsFnParams) {
|
|
162
|
-
fillLabelsFnParams = (0, utils_js_1.createFillLabelFnParams)(params.result, context, filterFillParamsFnParams);
|
|
152
|
+
fillLabelsFnParams = (0, utils_js_1.createFillLabelFnParams)(params.result, context, params => (0, utils_js_1.filterFillParamsFnParams)(config, params));
|
|
163
153
|
exports.fillLabelsFnParamsMap.set(context, fillLabelsFnParams);
|
|
164
154
|
}
|
|
165
155
|
if (fillLabelsFnParams) {
|
package/cjs/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractDeprecatedFields = exports.getHistogramFromConfig = exports.createCounter = exports.createSummary = exports.createHistogram = exports.createFillLabelFnParams = exports.shouldTraceFieldResolver = void 0;
|
|
3
|
+
exports.filterFillParamsFnParams = exports.labelExists = exports.extractDeprecatedFields = exports.getHistogramFromConfig = exports.createCounter = exports.createSummary = exports.createHistogram = exports.createFillLabelFnParams = exports.shouldTraceFieldResolver = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
const prom_client_1 = require("prom-client");
|
|
6
6
|
function shouldTraceFieldResolver(info, whitelist) {
|
|
@@ -51,10 +51,10 @@ function getHistogramFromConfig(config, phase, name, help) {
|
|
|
51
51
|
histogram: new prom_client_1.Histogram({
|
|
52
52
|
name,
|
|
53
53
|
help,
|
|
54
|
-
labelNames: ['operationType', 'operationName'],
|
|
54
|
+
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
|
|
55
55
|
registers: [config.registry || prom_client_1.register],
|
|
56
56
|
}),
|
|
57
|
-
fillLabelsFn: params => ({
|
|
57
|
+
fillLabelsFn: params => filterFillParamsFnParams(config, {
|
|
58
58
|
operationName: params.operationName,
|
|
59
59
|
operationType: params.operationType,
|
|
60
60
|
}),
|
|
@@ -92,3 +92,15 @@ function extractDeprecatedFields(node, typeInfo) {
|
|
|
92
92
|
return found;
|
|
93
93
|
}
|
|
94
94
|
exports.extractDeprecatedFields = extractDeprecatedFields;
|
|
95
|
+
function labelExists(config, label) {
|
|
96
|
+
const labelFlag = config.labels?.[label];
|
|
97
|
+
if (labelFlag == null) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
return labelFlag;
|
|
101
|
+
}
|
|
102
|
+
exports.labelExists = labelExists;
|
|
103
|
+
function filterFillParamsFnParams(config, params) {
|
|
104
|
+
return Object.fromEntries(Object.entries(params).filter(([key]) => labelExists(config, key)));
|
|
105
|
+
}
|
|
106
|
+
exports.filterFillParamsFnParams = filterFillParamsFnParams;
|
package/esm/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { TypeInfo } from 'graphql';
|
|
|
3
3
|
import { Counter, register as defaultRegistry, Histogram, Summary } 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, getHistogramFromConfig, shouldTraceFieldResolver, } from './utils.js';
|
|
6
|
+
import { createCounter, createFillLabelFnParams, createHistogram, createSummary, extractDeprecatedFields, filterFillParamsFnParams, getHistogramFromConfig, 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();
|
|
@@ -14,16 +14,6 @@ export const usePrometheus = (config = {}) => {
|
|
|
14
14
|
const contextBuildingHistogram = getHistogramFromConfig(config, 'contextBuilding', 'graphql_envelop_phase_context', 'Time spent on building the GraphQL context');
|
|
15
15
|
const executeHistogram = getHistogramFromConfig(config, 'execute', 'graphql_envelop_phase_execute', 'Time spent on running the GraphQL "execute" function');
|
|
16
16
|
const subscribeHistogram = getHistogramFromConfig(config, 'subscribe', 'graphql_envelop_phase_subscribe', 'Time spent on running the GraphQL "subscribe" function');
|
|
17
|
-
function labelExists(label) {
|
|
18
|
-
const labelFlag = config.labels?.[label];
|
|
19
|
-
if (labelFlag == null) {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
return labelFlag;
|
|
23
|
-
}
|
|
24
|
-
function filterFillParamsFnParams(params) {
|
|
25
|
-
return Object.fromEntries(Object.entries(params).filter(([key]) => labelExists(key)));
|
|
26
|
-
}
|
|
27
17
|
const resolversHistogram = typeof config.resolvers === 'object'
|
|
28
18
|
? config.resolvers
|
|
29
19
|
: config.resolvers === true
|
|
@@ -37,10 +27,10 @@ export const usePrometheus = (config = {}) => {
|
|
|
37
27
|
'fieldName',
|
|
38
28
|
'typeName',
|
|
39
29
|
'returnType',
|
|
40
|
-
].filter(labelExists),
|
|
30
|
+
].filter(label => labelExists(config, label)),
|
|
41
31
|
registers: [config.registry || defaultRegistry],
|
|
42
32
|
}),
|
|
43
|
-
fillLabelsFn: params => filterFillParamsFnParams({
|
|
33
|
+
fillLabelsFn: params => filterFillParamsFnParams(config, {
|
|
44
34
|
operationName: params.operationName,
|
|
45
35
|
operationType: params.operationType,
|
|
46
36
|
fieldName: params.info?.fieldName,
|
|
@@ -56,10 +46,10 @@ export const usePrometheus = (config = {}) => {
|
|
|
56
46
|
histogram: new Histogram({
|
|
57
47
|
name: 'graphql_envelop_request_duration',
|
|
58
48
|
help: 'Time spent on running the GraphQL operation from parse to execute',
|
|
59
|
-
labelNames: ['operationType', 'operationName'].filter(labelExists),
|
|
49
|
+
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
|
|
60
50
|
registers: [config.registry || defaultRegistry],
|
|
61
51
|
}),
|
|
62
|
-
fillLabelsFn: params => filterFillParamsFnParams({
|
|
52
|
+
fillLabelsFn: params => filterFillParamsFnParams(config, {
|
|
63
53
|
operationName: params.operationName,
|
|
64
54
|
operationType: params.operationType,
|
|
65
55
|
}),
|
|
@@ -72,10 +62,10 @@ export const usePrometheus = (config = {}) => {
|
|
|
72
62
|
summary: new Summary({
|
|
73
63
|
name: 'graphql_envelop_request_time_summary',
|
|
74
64
|
help: 'Summary to measure the time to complete GraphQL operations',
|
|
75
|
-
labelNames: ['operationType', 'operationName'].filter(labelExists),
|
|
65
|
+
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
|
|
76
66
|
registers: [config.registry || defaultRegistry],
|
|
77
67
|
}),
|
|
78
|
-
fillLabelsFn: params => filterFillParamsFnParams({
|
|
68
|
+
fillLabelsFn: params => filterFillParamsFnParams(config, {
|
|
79
69
|
operationName: params.operationName,
|
|
80
70
|
operationType: params.operationType,
|
|
81
71
|
}),
|
|
@@ -88,10 +78,10 @@ export const usePrometheus = (config = {}) => {
|
|
|
88
78
|
counter: new Counter({
|
|
89
79
|
name: 'graphql_envelop_error_result',
|
|
90
80
|
help: 'Counts the amount of errors reported from all phases',
|
|
91
|
-
labelNames: ['operationType', 'operationName', 'path', 'phase'].filter(labelExists),
|
|
81
|
+
labelNames: ['operationType', 'operationName', 'path', 'phase'].filter(label => labelExists(config, label)),
|
|
92
82
|
registers: [config.registry || defaultRegistry],
|
|
93
83
|
}),
|
|
94
|
-
fillLabelsFn: params => filterFillParamsFnParams({
|
|
84
|
+
fillLabelsFn: params => filterFillParamsFnParams(config, {
|
|
95
85
|
operationName: params.operationName,
|
|
96
86
|
operationType: params.operationType,
|
|
97
87
|
path: params.error?.path?.join('.'),
|
|
@@ -106,10 +96,10 @@ export const usePrometheus = (config = {}) => {
|
|
|
106
96
|
counter: new Counter({
|
|
107
97
|
name: 'graphql_envelop_request',
|
|
108
98
|
help: 'Counts the amount of GraphQL requests executed through Envelop',
|
|
109
|
-
labelNames: ['operationType', 'operationName'].filter(labelExists),
|
|
99
|
+
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
|
|
110
100
|
registers: [config.registry || defaultRegistry],
|
|
111
101
|
}),
|
|
112
|
-
fillLabelsFn: params => filterFillParamsFnParams({
|
|
102
|
+
fillLabelsFn: params => filterFillParamsFnParams(config, {
|
|
113
103
|
operationName: params.operationName,
|
|
114
104
|
operationType: params.operationType,
|
|
115
105
|
}),
|
|
@@ -122,10 +112,10 @@ export const usePrometheus = (config = {}) => {
|
|
|
122
112
|
counter: new Counter({
|
|
123
113
|
name: 'graphql_envelop_deprecated_field',
|
|
124
114
|
help: 'Counts the amount of deprecated fields used in selection sets',
|
|
125
|
-
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName'].filter(labelExists),
|
|
115
|
+
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName'].filter(label => labelExists(config, label)),
|
|
126
116
|
registers: [config.registry || defaultRegistry],
|
|
127
117
|
}),
|
|
128
|
-
fillLabelsFn: params => filterFillParamsFnParams({
|
|
118
|
+
fillLabelsFn: params => filterFillParamsFnParams(config, {
|
|
129
119
|
operationName: params.operationName,
|
|
130
120
|
operationType: params.operationType,
|
|
131
121
|
fieldName: params.deprecationInfo?.fieldName,
|
|
@@ -154,7 +144,7 @@ export const usePrometheus = (config = {}) => {
|
|
|
154
144
|
const totalTime = (Date.now() - startTime) / 1000;
|
|
155
145
|
let fillLabelsFnParams = fillLabelsFnParamsMap.get(params.result);
|
|
156
146
|
if (!fillLabelsFnParams) {
|
|
157
|
-
fillLabelsFnParams = createFillLabelFnParams(params.result, context, filterFillParamsFnParams);
|
|
147
|
+
fillLabelsFnParams = createFillLabelFnParams(params.result, context, params => filterFillParamsFnParams(config, params));
|
|
158
148
|
fillLabelsFnParamsMap.set(context, fillLabelsFnParams);
|
|
159
149
|
}
|
|
160
150
|
if (fillLabelsFnParams) {
|
package/esm/utils.js
CHANGED
|
@@ -43,10 +43,10 @@ export function getHistogramFromConfig(config, phase, name, help) {
|
|
|
43
43
|
histogram: new Histogram({
|
|
44
44
|
name,
|
|
45
45
|
help,
|
|
46
|
-
labelNames: ['operationType', 'operationName'],
|
|
46
|
+
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
|
|
47
47
|
registers: [config.registry || defaultRegistry],
|
|
48
48
|
}),
|
|
49
|
-
fillLabelsFn: params => ({
|
|
49
|
+
fillLabelsFn: params => filterFillParamsFnParams(config, {
|
|
50
50
|
operationName: params.operationName,
|
|
51
51
|
operationType: params.operationType,
|
|
52
52
|
}),
|
|
@@ -82,3 +82,13 @@ export function extractDeprecatedFields(node, typeInfo) {
|
|
|
82
82
|
}));
|
|
83
83
|
return found;
|
|
84
84
|
}
|
|
85
|
+
export function labelExists(config, label) {
|
|
86
|
+
const labelFlag = config.labels?.[label];
|
|
87
|
+
if (labelFlag == null) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
return labelFlag;
|
|
91
|
+
}
|
|
92
|
+
export function filterFillParamsFnParams(config, params) {
|
|
93
|
+
return Object.fromEntries(Object.entries(params).filter(([key]) => labelExists(config, key)));
|
|
94
|
+
}
|
package/package.json
CHANGED
package/typings/utils.d.cts
CHANGED
|
@@ -32,3 +32,7 @@ export declare function createCounter<LabelNames extends string>(options: {
|
|
|
32
32
|
}): typeof options;
|
|
33
33
|
export declare function getHistogramFromConfig(config: PrometheusTracingPluginConfig, phase: keyof PrometheusTracingPluginConfig, name: string, help: string): ReturnType<typeof createHistogram> | undefined;
|
|
34
34
|
export declare function extractDeprecatedFields(node: ASTNode, typeInfo: TypeInfo): DeprecatedFieldInfo[];
|
|
35
|
+
export declare function labelExists(config: PrometheusTracingPluginConfig, label: string): any;
|
|
36
|
+
export declare function filterFillParamsFnParams(config: PrometheusTracingPluginConfig, params: Record<string, any>): {
|
|
37
|
+
[k: string]: any;
|
|
38
|
+
};
|
package/typings/utils.d.ts
CHANGED
|
@@ -32,3 +32,7 @@ export declare function createCounter<LabelNames extends string>(options: {
|
|
|
32
32
|
}): typeof options;
|
|
33
33
|
export declare function getHistogramFromConfig(config: PrometheusTracingPluginConfig, phase: keyof PrometheusTracingPluginConfig, name: string, help: string): ReturnType<typeof createHistogram> | undefined;
|
|
34
34
|
export declare function extractDeprecatedFields(node: ASTNode, typeInfo: TypeInfo): DeprecatedFieldInfo[];
|
|
35
|
+
export declare function labelExists(config: PrometheusTracingPluginConfig, label: string): any;
|
|
36
|
+
export declare function filterFillParamsFnParams(config: PrometheusTracingPluginConfig, params: Record<string, any>): {
|
|
37
|
+
[k: string]: any;
|
|
38
|
+
};
|