@envelop/prometheus 14.1.1 → 14.2.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/LICENSE +3 -1
- package/cjs/index.js +28 -34
- package/cjs/utils.js +12 -24
- package/esm/index.js +28 -34
- package/esm/utils.js +13 -25
- package/package.json +6 -6
- package/typings/config.d.cts +2 -2
- package/typings/config.d.ts +2 -2
- package/typings/index.d.cts +3 -3
- package/typings/index.d.ts +3 -3
- package/typings/utils.d.cts +3 -3
- package/typings/utils.d.ts +3 -3
package/LICENSE
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2020
|
|
3
|
+
Copyright (c) 2018-2020 Graphcool
|
|
4
|
+
Copyright (c) 2020-2021 Prisma
|
|
5
|
+
Copyright (c) 2021- The Guild
|
|
4
6
|
|
|
5
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
8
|
of this software and associated documentation files (the "Software"), to deal
|
package/cjs/index.js
CHANGED
|
@@ -171,14 +171,12 @@ const usePrometheus = (config) => {
|
|
|
171
171
|
phase: params.errorPhase,
|
|
172
172
|
};
|
|
173
173
|
if (params.error?.path) {
|
|
174
|
-
labels
|
|
174
|
+
labels['path'] = params.error.path?.join('.');
|
|
175
175
|
}
|
|
176
176
|
return (0, utils_js_1.filterFillParamsFnParams)(config, labels);
|
|
177
177
|
});
|
|
178
178
|
if (errorsCounter) {
|
|
179
|
-
['parse', 'validate']
|
|
180
|
-
.filter(phase => errorsCounter.phases.includes(phase))
|
|
181
|
-
.forEach(phase => {
|
|
179
|
+
for (const phase of ['parse', 'validate'].filter(phase => errorsCounter.phases.includes(phase))) {
|
|
182
180
|
phasesToHook[phase].push({
|
|
183
181
|
shouldHandle: (params, context) => !!params.errorPhase && errorsCounter.shouldObserve(params, context),
|
|
184
182
|
handler: ({ params, context }) => {
|
|
@@ -186,10 +184,8 @@ const usePrometheus = (config) => {
|
|
|
186
184
|
errorsCounter?.counter.labels(labels).inc();
|
|
187
185
|
},
|
|
188
186
|
});
|
|
189
|
-
}
|
|
190
|
-
['execute', 'subscribe']
|
|
191
|
-
.filter(phase => errorsCounter.phases.includes(phase))
|
|
192
|
-
.forEach(phase => {
|
|
187
|
+
}
|
|
188
|
+
for (const phase of ['execute', 'subscribe'].filter(phase => errorsCounter.phases.includes(phase))) {
|
|
193
189
|
phasesToHook[phase].result.push({
|
|
194
190
|
shouldHandle: errorsCounter.shouldObserve,
|
|
195
191
|
handler: ({ result, params, context }) => {
|
|
@@ -206,11 +202,11 @@ const usePrometheus = (config) => {
|
|
|
206
202
|
}
|
|
207
203
|
},
|
|
208
204
|
});
|
|
209
|
-
}
|
|
205
|
+
}
|
|
210
206
|
if (errorsCounter.phases.includes('subscribe')) {
|
|
211
207
|
phasesToHook.subscribe.error.push({
|
|
212
208
|
shouldHandle: errorsCounter.shouldObserve,
|
|
213
|
-
handler: ({ params, context
|
|
209
|
+
handler: ({ params, context }) => {
|
|
214
210
|
const labels = errorsCounter.fillLabelsFn(params, context);
|
|
215
211
|
errorsCounter.counter.labels(labels).inc();
|
|
216
212
|
},
|
|
@@ -307,9 +303,8 @@ const usePrometheus = (config) => {
|
|
|
307
303
|
totalTime: (Date.now() - startTime) / 1000,
|
|
308
304
|
params: fillLabelsFnParams ?? { error: params.result, errorPhase: 'parse' },
|
|
309
305
|
};
|
|
310
|
-
phasesToHook.parse
|
|
311
|
-
|
|
312
|
-
.forEach(({ handler }) => handler(args));
|
|
306
|
+
for (const { handler } of phasesToHook.parse.filter(({ shouldHandle }) => shouldHandle(args.params, context)))
|
|
307
|
+
handler(args);
|
|
313
308
|
};
|
|
314
309
|
};
|
|
315
310
|
const onValidate = ({ context }) => {
|
|
@@ -324,9 +319,8 @@ const usePrometheus = (config) => {
|
|
|
324
319
|
context,
|
|
325
320
|
totalTime: (Date.now() - startTime) / 1000,
|
|
326
321
|
};
|
|
327
|
-
phasesToHook.validate
|
|
328
|
-
|
|
329
|
-
.forEach(({ handler }) => handler(args));
|
|
322
|
+
for (const { handler } of phasesToHook.validate.filter(({ shouldHandle }) => shouldHandle(args.params, context)))
|
|
323
|
+
handler(args);
|
|
330
324
|
// TODO: we should probably iterate over validation errors to report each error.
|
|
331
325
|
};
|
|
332
326
|
};
|
|
@@ -341,9 +335,8 @@ const usePrometheus = (config) => {
|
|
|
341
335
|
params: fillLabelsFnParams,
|
|
342
336
|
totalTime: (Date.now() - startTime) / 1000,
|
|
343
337
|
};
|
|
344
|
-
phasesToHook.context
|
|
345
|
-
|
|
346
|
-
.forEach(({ handler }) => handler(args));
|
|
338
|
+
for (const { handler } of phasesToHook.context.filter(({ shouldHandle }) => shouldHandle(fillLabelsFnParams, context)))
|
|
339
|
+
handler(args);
|
|
347
340
|
};
|
|
348
341
|
const onExecute = ({ args: { contextValue: context } }) => {
|
|
349
342
|
const fillLabelsFnParams = exports.fillLabelsFnParamsMap.get(context);
|
|
@@ -359,12 +352,14 @@ const usePrometheus = (config) => {
|
|
|
359
352
|
function handleResult({ result }) {
|
|
360
353
|
const totalTime = (Date.now() - startTime) / 1000;
|
|
361
354
|
const args = { params: fillLabelsFnParams, context, totalTime, result };
|
|
362
|
-
|
|
355
|
+
for (const { handler } of resultHandlers)
|
|
356
|
+
handler(args);
|
|
363
357
|
}
|
|
364
358
|
const handleEnd = () => {
|
|
365
359
|
const totalTime = (Date.now() - startTime) / 1000;
|
|
366
360
|
const args = { params: fillLabelsFnParams, context, totalTime };
|
|
367
|
-
|
|
361
|
+
for (const { handler } of endHandlers)
|
|
362
|
+
handler(args);
|
|
368
363
|
};
|
|
369
364
|
return {
|
|
370
365
|
onExecuteDone: ({ result }) => {
|
|
@@ -374,11 +369,9 @@ const usePrometheus = (config) => {
|
|
|
374
369
|
onEnd: endHandlers.length ? handleEnd : undefined,
|
|
375
370
|
};
|
|
376
371
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
return undefined;
|
|
381
|
-
}
|
|
372
|
+
handleResult({ result });
|
|
373
|
+
handleEnd();
|
|
374
|
+
return undefined;
|
|
382
375
|
},
|
|
383
376
|
};
|
|
384
377
|
};
|
|
@@ -397,17 +390,20 @@ const usePrometheus = (config) => {
|
|
|
397
390
|
function handleResult({ result }) {
|
|
398
391
|
const totalTime = (Date.now() - startTime) / 1000;
|
|
399
392
|
const args = { params: fillLabelsFnParams, context, totalTime, result };
|
|
400
|
-
|
|
393
|
+
for (const { handler } of resultHandlers)
|
|
394
|
+
handler(args);
|
|
401
395
|
}
|
|
402
396
|
const handleEnd = () => {
|
|
403
397
|
const totalTime = (Date.now() - startTime) / 1000;
|
|
404
398
|
const args = { params: fillLabelsFnParams, context, totalTime };
|
|
405
|
-
|
|
399
|
+
for (const { handler } of endHandlers)
|
|
400
|
+
handler(args);
|
|
406
401
|
};
|
|
407
402
|
const handleError = ({ error }) => {
|
|
408
403
|
const totalTime = (Date.now() - startTime) / 1000;
|
|
409
404
|
const args = { params: fillLabelsFnParams, context, totalTime, error };
|
|
410
|
-
|
|
405
|
+
for (const { handler } of errorHandlers)
|
|
406
|
+
handler(args);
|
|
411
407
|
};
|
|
412
408
|
return {
|
|
413
409
|
onSubscribeResult: ({ result }) => {
|
|
@@ -417,11 +413,9 @@ const usePrometheus = (config) => {
|
|
|
417
413
|
onEnd: endHandlers.length ? handleEnd : undefined,
|
|
418
414
|
};
|
|
419
415
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
return undefined;
|
|
424
|
-
}
|
|
416
|
+
handleResult({ result });
|
|
417
|
+
handleEnd();
|
|
418
|
+
return undefined;
|
|
425
419
|
},
|
|
426
420
|
onSubscribeError: errorHandlers.length ? handleError : undefined,
|
|
427
421
|
};
|
package/cjs/utils.js
CHANGED
|
@@ -119,8 +119,8 @@ function createCounter(options) {
|
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
121
|
function getHistogramFromConfig(config, phase, availablePhases, histogram, fillLabelsFn = params => ({
|
|
122
|
-
operationName: params
|
|
123
|
-
operationType: params
|
|
122
|
+
operationName: params['operationName'],
|
|
123
|
+
operationType: params['operationType'],
|
|
124
124
|
})) {
|
|
125
125
|
const metric = config.metrics[phase];
|
|
126
126
|
if (!metric) {
|
|
@@ -143,12 +143,8 @@ function getHistogramFromConfig(config, phase, availablePhases, histogram, fillL
|
|
|
143
143
|
}
|
|
144
144
|
else if (typeof metric === 'object') {
|
|
145
145
|
const customMetric = metric;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
if (!customMetric.shouldObserve) {
|
|
150
|
-
customMetric.shouldObserve = () => true;
|
|
151
|
-
}
|
|
146
|
+
customMetric.phases ||= availablePhases;
|
|
147
|
+
customMetric.shouldObserve ||= () => true;
|
|
152
148
|
return customMetric;
|
|
153
149
|
}
|
|
154
150
|
return createHistogram({
|
|
@@ -164,8 +160,8 @@ function getHistogramFromConfig(config, phase, availablePhases, histogram, fillL
|
|
|
164
160
|
});
|
|
165
161
|
}
|
|
166
162
|
function getSummaryFromConfig(config, phase, availablePhases, summary, fillLabelsFn = params => filterFillParamsFnParams(config, {
|
|
167
|
-
operationName: params
|
|
168
|
-
operationType: params
|
|
163
|
+
operationName: params['operationName'],
|
|
164
|
+
operationType: params['operationType'],
|
|
169
165
|
})) {
|
|
170
166
|
const metric = config.metrics[phase];
|
|
171
167
|
if (!metric) {
|
|
@@ -185,12 +181,8 @@ function getSummaryFromConfig(config, phase, availablePhases, summary, fillLabel
|
|
|
185
181
|
}
|
|
186
182
|
else if (typeof metric === 'object') {
|
|
187
183
|
const customMetric = metric;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
if (!customMetric.shouldObserve) {
|
|
192
|
-
customMetric.shouldObserve = () => true;
|
|
193
|
-
}
|
|
184
|
+
customMetric.phases ||= availablePhases;
|
|
185
|
+
customMetric.shouldObserve ||= () => true;
|
|
194
186
|
return customMetric;
|
|
195
187
|
}
|
|
196
188
|
return createSummary({
|
|
@@ -206,8 +198,8 @@ function getSummaryFromConfig(config, phase, availablePhases, summary, fillLabel
|
|
|
206
198
|
});
|
|
207
199
|
}
|
|
208
200
|
function getCounterFromConfig(config, phase, availablePhases, counter, fillLabelsFn = params => filterFillParamsFnParams(config, {
|
|
209
|
-
operationName: params
|
|
210
|
-
operationType: params
|
|
201
|
+
operationName: params['operationName'],
|
|
202
|
+
operationType: params['operationType'],
|
|
211
203
|
})) {
|
|
212
204
|
const metric = config.metrics[phase];
|
|
213
205
|
let phases = availablePhases;
|
|
@@ -227,12 +219,8 @@ function getCounterFromConfig(config, phase, availablePhases, counter, fillLabel
|
|
|
227
219
|
}
|
|
228
220
|
else if (typeof metric === 'object') {
|
|
229
221
|
const customMetric = metric;
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
if (!customMetric.shouldObserve) {
|
|
234
|
-
customMetric.shouldObserve = () => true;
|
|
235
|
-
}
|
|
222
|
+
customMetric.phases ||= availablePhases;
|
|
223
|
+
customMetric.shouldObserve ||= () => true;
|
|
236
224
|
return customMetric;
|
|
237
225
|
}
|
|
238
226
|
return createCounter({
|
package/esm/index.js
CHANGED
|
@@ -163,14 +163,12 @@ export const usePrometheus = (config) => {
|
|
|
163
163
|
phase: params.errorPhase,
|
|
164
164
|
};
|
|
165
165
|
if (params.error?.path) {
|
|
166
|
-
labels
|
|
166
|
+
labels['path'] = params.error.path?.join('.');
|
|
167
167
|
}
|
|
168
168
|
return filterFillParamsFnParams(config, labels);
|
|
169
169
|
});
|
|
170
170
|
if (errorsCounter) {
|
|
171
|
-
['parse', 'validate']
|
|
172
|
-
.filter(phase => errorsCounter.phases.includes(phase))
|
|
173
|
-
.forEach(phase => {
|
|
171
|
+
for (const phase of ['parse', 'validate'].filter(phase => errorsCounter.phases.includes(phase))) {
|
|
174
172
|
phasesToHook[phase].push({
|
|
175
173
|
shouldHandle: (params, context) => !!params.errorPhase && errorsCounter.shouldObserve(params, context),
|
|
176
174
|
handler: ({ params, context }) => {
|
|
@@ -178,10 +176,8 @@ export const usePrometheus = (config) => {
|
|
|
178
176
|
errorsCounter?.counter.labels(labels).inc();
|
|
179
177
|
},
|
|
180
178
|
});
|
|
181
|
-
}
|
|
182
|
-
['execute', 'subscribe']
|
|
183
|
-
.filter(phase => errorsCounter.phases.includes(phase))
|
|
184
|
-
.forEach(phase => {
|
|
179
|
+
}
|
|
180
|
+
for (const phase of ['execute', 'subscribe'].filter(phase => errorsCounter.phases.includes(phase))) {
|
|
185
181
|
phasesToHook[phase].result.push({
|
|
186
182
|
shouldHandle: errorsCounter.shouldObserve,
|
|
187
183
|
handler: ({ result, params, context }) => {
|
|
@@ -198,11 +194,11 @@ export const usePrometheus = (config) => {
|
|
|
198
194
|
}
|
|
199
195
|
},
|
|
200
196
|
});
|
|
201
|
-
}
|
|
197
|
+
}
|
|
202
198
|
if (errorsCounter.phases.includes('subscribe')) {
|
|
203
199
|
phasesToHook.subscribe.error.push({
|
|
204
200
|
shouldHandle: errorsCounter.shouldObserve,
|
|
205
|
-
handler: ({ params, context
|
|
201
|
+
handler: ({ params, context }) => {
|
|
206
202
|
const labels = errorsCounter.fillLabelsFn(params, context);
|
|
207
203
|
errorsCounter.counter.labels(labels).inc();
|
|
208
204
|
},
|
|
@@ -299,9 +295,8 @@ export const usePrometheus = (config) => {
|
|
|
299
295
|
totalTime: (Date.now() - startTime) / 1000,
|
|
300
296
|
params: fillLabelsFnParams ?? { error: params.result, errorPhase: 'parse' },
|
|
301
297
|
};
|
|
302
|
-
phasesToHook.parse
|
|
303
|
-
|
|
304
|
-
.forEach(({ handler }) => handler(args));
|
|
298
|
+
for (const { handler } of phasesToHook.parse.filter(({ shouldHandle }) => shouldHandle(args.params, context)))
|
|
299
|
+
handler(args);
|
|
305
300
|
};
|
|
306
301
|
};
|
|
307
302
|
const onValidate = ({ context }) => {
|
|
@@ -316,9 +311,8 @@ export const usePrometheus = (config) => {
|
|
|
316
311
|
context,
|
|
317
312
|
totalTime: (Date.now() - startTime) / 1000,
|
|
318
313
|
};
|
|
319
|
-
phasesToHook.validate
|
|
320
|
-
|
|
321
|
-
.forEach(({ handler }) => handler(args));
|
|
314
|
+
for (const { handler } of phasesToHook.validate.filter(({ shouldHandle }) => shouldHandle(args.params, context)))
|
|
315
|
+
handler(args);
|
|
322
316
|
// TODO: we should probably iterate over validation errors to report each error.
|
|
323
317
|
};
|
|
324
318
|
};
|
|
@@ -333,9 +327,8 @@ export const usePrometheus = (config) => {
|
|
|
333
327
|
params: fillLabelsFnParams,
|
|
334
328
|
totalTime: (Date.now() - startTime) / 1000,
|
|
335
329
|
};
|
|
336
|
-
phasesToHook.context
|
|
337
|
-
|
|
338
|
-
.forEach(({ handler }) => handler(args));
|
|
330
|
+
for (const { handler } of phasesToHook.context.filter(({ shouldHandle }) => shouldHandle(fillLabelsFnParams, context)))
|
|
331
|
+
handler(args);
|
|
339
332
|
};
|
|
340
333
|
const onExecute = ({ args: { contextValue: context } }) => {
|
|
341
334
|
const fillLabelsFnParams = fillLabelsFnParamsMap.get(context);
|
|
@@ -351,12 +344,14 @@ export const usePrometheus = (config) => {
|
|
|
351
344
|
function handleResult({ result }) {
|
|
352
345
|
const totalTime = (Date.now() - startTime) / 1000;
|
|
353
346
|
const args = { params: fillLabelsFnParams, context, totalTime, result };
|
|
354
|
-
|
|
347
|
+
for (const { handler } of resultHandlers)
|
|
348
|
+
handler(args);
|
|
355
349
|
}
|
|
356
350
|
const handleEnd = () => {
|
|
357
351
|
const totalTime = (Date.now() - startTime) / 1000;
|
|
358
352
|
const args = { params: fillLabelsFnParams, context, totalTime };
|
|
359
|
-
|
|
353
|
+
for (const { handler } of endHandlers)
|
|
354
|
+
handler(args);
|
|
360
355
|
};
|
|
361
356
|
return {
|
|
362
357
|
onExecuteDone: ({ result }) => {
|
|
@@ -366,11 +361,9 @@ export const usePrometheus = (config) => {
|
|
|
366
361
|
onEnd: endHandlers.length ? handleEnd : undefined,
|
|
367
362
|
};
|
|
368
363
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
return undefined;
|
|
373
|
-
}
|
|
364
|
+
handleResult({ result });
|
|
365
|
+
handleEnd();
|
|
366
|
+
return undefined;
|
|
374
367
|
},
|
|
375
368
|
};
|
|
376
369
|
};
|
|
@@ -389,17 +382,20 @@ export const usePrometheus = (config) => {
|
|
|
389
382
|
function handleResult({ result }) {
|
|
390
383
|
const totalTime = (Date.now() - startTime) / 1000;
|
|
391
384
|
const args = { params: fillLabelsFnParams, context, totalTime, result };
|
|
392
|
-
|
|
385
|
+
for (const { handler } of resultHandlers)
|
|
386
|
+
handler(args);
|
|
393
387
|
}
|
|
394
388
|
const handleEnd = () => {
|
|
395
389
|
const totalTime = (Date.now() - startTime) / 1000;
|
|
396
390
|
const args = { params: fillLabelsFnParams, context, totalTime };
|
|
397
|
-
|
|
391
|
+
for (const { handler } of endHandlers)
|
|
392
|
+
handler(args);
|
|
398
393
|
};
|
|
399
394
|
const handleError = ({ error }) => {
|
|
400
395
|
const totalTime = (Date.now() - startTime) / 1000;
|
|
401
396
|
const args = { params: fillLabelsFnParams, context, totalTime, error };
|
|
402
|
-
|
|
397
|
+
for (const { handler } of errorHandlers)
|
|
398
|
+
handler(args);
|
|
403
399
|
};
|
|
404
400
|
return {
|
|
405
401
|
onSubscribeResult: ({ result }) => {
|
|
@@ -409,11 +405,9 @@ export const usePrometheus = (config) => {
|
|
|
409
405
|
onEnd: endHandlers.length ? handleEnd : undefined,
|
|
410
406
|
};
|
|
411
407
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
return undefined;
|
|
416
|
-
}
|
|
408
|
+
handleResult({ result });
|
|
409
|
+
handleEnd();
|
|
410
|
+
return undefined;
|
|
417
411
|
},
|
|
418
412
|
onSubscribeError: errorHandlers.length ? handleError : undefined,
|
|
419
413
|
};
|
package/esm/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { visit, visitWithTypeInfo
|
|
1
|
+
import { visit, visitWithTypeInfo } from 'graphql';
|
|
2
2
|
import { Counter, register as defaultRegistry, Histogram, Summary, } from 'prom-client';
|
|
3
3
|
const histograms = new WeakMap();
|
|
4
4
|
const summaries = new WeakMap();
|
|
@@ -102,8 +102,8 @@ export function createCounter(options) {
|
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
export function getHistogramFromConfig(config, phase, availablePhases, histogram, fillLabelsFn = params => ({
|
|
105
|
-
operationName: params
|
|
106
|
-
operationType: params
|
|
105
|
+
operationName: params['operationName'],
|
|
106
|
+
operationType: params['operationType'],
|
|
107
107
|
})) {
|
|
108
108
|
const metric = config.metrics[phase];
|
|
109
109
|
if (!metric) {
|
|
@@ -126,12 +126,8 @@ export function getHistogramFromConfig(config, phase, availablePhases, histogram
|
|
|
126
126
|
}
|
|
127
127
|
else if (typeof metric === 'object') {
|
|
128
128
|
const customMetric = metric;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
if (!customMetric.shouldObserve) {
|
|
133
|
-
customMetric.shouldObserve = () => true;
|
|
134
|
-
}
|
|
129
|
+
customMetric.phases ||= availablePhases;
|
|
130
|
+
customMetric.shouldObserve ||= () => true;
|
|
135
131
|
return customMetric;
|
|
136
132
|
}
|
|
137
133
|
return createHistogram({
|
|
@@ -147,8 +143,8 @@ export function getHistogramFromConfig(config, phase, availablePhases, histogram
|
|
|
147
143
|
});
|
|
148
144
|
}
|
|
149
145
|
export function getSummaryFromConfig(config, phase, availablePhases, summary, fillLabelsFn = params => filterFillParamsFnParams(config, {
|
|
150
|
-
operationName: params
|
|
151
|
-
operationType: params
|
|
146
|
+
operationName: params['operationName'],
|
|
147
|
+
operationType: params['operationType'],
|
|
152
148
|
})) {
|
|
153
149
|
const metric = config.metrics[phase];
|
|
154
150
|
if (!metric) {
|
|
@@ -168,12 +164,8 @@ export function getSummaryFromConfig(config, phase, availablePhases, summary, fi
|
|
|
168
164
|
}
|
|
169
165
|
else if (typeof metric === 'object') {
|
|
170
166
|
const customMetric = metric;
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
if (!customMetric.shouldObserve) {
|
|
175
|
-
customMetric.shouldObserve = () => true;
|
|
176
|
-
}
|
|
167
|
+
customMetric.phases ||= availablePhases;
|
|
168
|
+
customMetric.shouldObserve ||= () => true;
|
|
177
169
|
return customMetric;
|
|
178
170
|
}
|
|
179
171
|
return createSummary({
|
|
@@ -189,8 +181,8 @@ export function getSummaryFromConfig(config, phase, availablePhases, summary, fi
|
|
|
189
181
|
});
|
|
190
182
|
}
|
|
191
183
|
export function getCounterFromConfig(config, phase, availablePhases, counter, fillLabelsFn = params => filterFillParamsFnParams(config, {
|
|
192
|
-
operationName: params
|
|
193
|
-
operationType: params
|
|
184
|
+
operationName: params['operationName'],
|
|
185
|
+
operationType: params['operationType'],
|
|
194
186
|
})) {
|
|
195
187
|
const metric = config.metrics[phase];
|
|
196
188
|
let phases = availablePhases;
|
|
@@ -210,12 +202,8 @@ export function getCounterFromConfig(config, phase, availablePhases, counter, fi
|
|
|
210
202
|
}
|
|
211
203
|
else if (typeof metric === 'object') {
|
|
212
204
|
const customMetric = metric;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
if (!customMetric.shouldObserve) {
|
|
217
|
-
customMetric.shouldObserve = () => true;
|
|
218
|
-
}
|
|
205
|
+
customMetric.phases ||= availablePhases;
|
|
206
|
+
customMetric.shouldObserve ||= () => true;
|
|
219
207
|
return customMetric;
|
|
220
208
|
}
|
|
221
209
|
return createCounter({
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/prometheus",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.2.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0",
|
|
6
|
+
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0",
|
|
7
7
|
"prom-client": "^15.0.0",
|
|
8
|
-
"@envelop/core": "^5.
|
|
8
|
+
"@envelop/core": "^5.6.0"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"tslib": "^2.5.0",
|
|
12
|
-
"@envelop/on-resolve": "^7.
|
|
12
|
+
"@envelop/on-resolve": "^7.2.0"
|
|
13
13
|
},
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
|
-
"url": "https://github.com/graphql-hive/
|
|
17
|
-
"directory": "packages/plugins/prometheus"
|
|
16
|
+
"url": "https://github.com/graphql-hive/graphql-yoga.git",
|
|
17
|
+
"directory": "packages/envelop/plugins/prometheus"
|
|
18
18
|
},
|
|
19
19
|
"author": "Dotan Simha <dotansimha@gmail.com>",
|
|
20
20
|
"license": "MIT",
|
package/typings/config.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GraphQLResolveInfo } from 'graphql';
|
|
2
|
-
import { Registry } from 'prom-client';
|
|
3
|
-
import { createCounter, createHistogram, createSummary,
|
|
2
|
+
import type { Registry } from 'prom-client';
|
|
3
|
+
import type { AtLeastOne, createCounter, createHistogram, createSummary, DeprecatedFieldInfo, FillLabelsFnParams } from './utils.cjs';
|
|
4
4
|
export type PrometheusTracingPluginConfig = {
|
|
5
5
|
/**
|
|
6
6
|
* The `prom-client` registry to use. If not provided, the default global registry will be used.
|
package/typings/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GraphQLResolveInfo } from 'graphql';
|
|
2
|
-
import { Registry } from 'prom-client';
|
|
3
|
-
import { createCounter, createHistogram, createSummary,
|
|
2
|
+
import type { Registry } from 'prom-client';
|
|
3
|
+
import type { AtLeastOne, createCounter, createHistogram, createSummary, DeprecatedFieldInfo, FillLabelsFnParams } from './utils.js';
|
|
4
4
|
export type PrometheusTracingPluginConfig = {
|
|
5
5
|
/**
|
|
6
6
|
* The `prom-client` registry to use. If not provided, the default global registry will be used.
|
package/typings/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Plugin } from '@envelop/core';
|
|
2
|
-
import { CounterMetricOption, HistogramMetricOption, PrometheusTracingPluginConfig, SummaryMetricOption } from './config.cjs';
|
|
3
|
-
import { createCounter, createHistogram, createSummary,
|
|
4
|
-
export { CounterAndLabels, FillLabelsFnParams, HistogramAndLabels, PrometheusTracingPluginConfig, SummaryAndLabels, HistogramMetricOption, CounterMetricOption, SummaryMetricOption, createCounter, createHistogram, createSummary, getCounterFromConfig, getHistogramFromConfig, getSummaryFromConfig, };
|
|
2
|
+
import type { CounterMetricOption, HistogramMetricOption, PrometheusTracingPluginConfig, SummaryMetricOption } from './config.cjs';
|
|
3
|
+
import { createCounter, createHistogram, createSummary, getCounterFromConfig, getHistogramFromConfig, getSummaryFromConfig, type CounterAndLabels, type FillLabelsFnParams, type HistogramAndLabels, type SummaryAndLabels } from './utils.cjs';
|
|
4
|
+
export { CounterAndLabels, type FillLabelsFnParams, HistogramAndLabels, type PrometheusTracingPluginConfig, SummaryAndLabels, type HistogramMetricOption, type CounterMetricOption, type SummaryMetricOption, createCounter, createHistogram, createSummary, getCounterFromConfig, getHistogramFromConfig, getSummaryFromConfig, };
|
|
5
5
|
export declare const fillLabelsFnParamsMap: WeakMap<any, FillLabelsFnParams | null>;
|
|
6
6
|
export declare const execStartTimeMap: WeakMap<any, number>;
|
|
7
7
|
export declare const usePrometheus: (config: PrometheusTracingPluginConfig) => Plugin;
|
package/typings/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Plugin } from '@envelop/core';
|
|
2
|
-
import { CounterMetricOption, HistogramMetricOption, PrometheusTracingPluginConfig, SummaryMetricOption } from './config.js';
|
|
3
|
-
import { createCounter, createHistogram, createSummary,
|
|
4
|
-
export { CounterAndLabels, FillLabelsFnParams, HistogramAndLabels, PrometheusTracingPluginConfig, SummaryAndLabels, HistogramMetricOption, CounterMetricOption, SummaryMetricOption, createCounter, createHistogram, createSummary, getCounterFromConfig, getHistogramFromConfig, getSummaryFromConfig, };
|
|
2
|
+
import type { CounterMetricOption, HistogramMetricOption, PrometheusTracingPluginConfig, SummaryMetricOption } from './config.js';
|
|
3
|
+
import { createCounter, createHistogram, createSummary, getCounterFromConfig, getHistogramFromConfig, getSummaryFromConfig, type CounterAndLabels, type FillLabelsFnParams, type HistogramAndLabels, type SummaryAndLabels } from './utils.js';
|
|
4
|
+
export { CounterAndLabels, type FillLabelsFnParams, HistogramAndLabels, type PrometheusTracingPluginConfig, SummaryAndLabels, type HistogramMetricOption, type CounterMetricOption, type SummaryMetricOption, createCounter, createHistogram, createSummary, getCounterFromConfig, getHistogramFromConfig, getSummaryFromConfig, };
|
|
5
5
|
export declare const fillLabelsFnParamsMap: WeakMap<any, FillLabelsFnParams | null>;
|
|
6
6
|
export declare const execStartTimeMap: WeakMap<any, number>;
|
|
7
7
|
export declare const usePrometheus: (config: PrometheusTracingPluginConfig) => Plugin;
|
package/typings/utils.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ASTNode, DocumentNode, GraphQLError, GraphQLResolveInfo, OperationDefinitionNode, TypeInfo } from 'graphql';
|
|
1
|
+
import type { ASTNode, DocumentNode, GraphQLError, GraphQLResolveInfo, OperationDefinitionNode, TypeInfo } from 'graphql';
|
|
2
2
|
import { Counter, Histogram, Summary, type CounterConfiguration, type HistogramConfiguration, type Registry, type SummaryConfiguration } from 'prom-client';
|
|
3
|
-
import { AfterParseEventPayload } from '@envelop/core';
|
|
4
|
-
import { PrometheusTracingPluginConfig } from './config.cjs';
|
|
3
|
+
import type { AfterParseEventPayload } from '@envelop/core';
|
|
4
|
+
import type { PrometheusTracingPluginConfig } from './config.cjs';
|
|
5
5
|
export type DeprecatedFieldInfo = {
|
|
6
6
|
fieldName: string;
|
|
7
7
|
typeName: string;
|
package/typings/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ASTNode, DocumentNode, GraphQLError, GraphQLResolveInfo, OperationDefinitionNode, TypeInfo } from 'graphql';
|
|
1
|
+
import type { ASTNode, DocumentNode, GraphQLError, GraphQLResolveInfo, OperationDefinitionNode, TypeInfo } from 'graphql';
|
|
2
2
|
import { Counter, Histogram, Summary, type CounterConfiguration, type HistogramConfiguration, type Registry, type SummaryConfiguration } from 'prom-client';
|
|
3
|
-
import { AfterParseEventPayload } from '@envelop/core';
|
|
4
|
-
import { PrometheusTracingPluginConfig } from './config.js';
|
|
3
|
+
import type { AfterParseEventPayload } from '@envelop/core';
|
|
4
|
+
import type { PrometheusTracingPluginConfig } from './config.js';
|
|
5
5
|
export type DeprecatedFieldInfo = {
|
|
6
6
|
fieldName: string;
|
|
7
7
|
typeName: string;
|