@envelop/prometheus 9.2.0 → 9.3.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/cjs/index.js +91 -18
- package/esm/index.js +91 -18
- package/package.json +1 -1
- package/typings/config.d.cts +1 -0
- package/typings/config.d.ts +1 -0
package/cjs/index.js
CHANGED
|
@@ -18,6 +18,7 @@ const usePrometheus = (config = {}) => {
|
|
|
18
18
|
const validateHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'validate', 'graphql_envelop_phase_validate', 'Time spent on running GraphQL "validate" function');
|
|
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
|
+
const subscribeHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'subscribe', 'graphql_envelop_phase_subscribe', 'Time spent on running the GraphQL "subscribe" function');
|
|
21
22
|
function labelExists(label) {
|
|
22
23
|
const labelFlag = config.labels?.[label];
|
|
23
24
|
if (labelFlag == null) {
|
|
@@ -232,29 +233,100 @@ const usePrometheus = (config = {}) => {
|
|
|
232
233
|
reqCounter?.counter
|
|
233
234
|
.labels(reqCounter.fillLabelsFn(fillLabelsFnParams, args.contextValue))
|
|
234
235
|
.inc();
|
|
236
|
+
function handleResult(result) {
|
|
237
|
+
if (errorsCounter && result.errors && result.errors.length > 0) {
|
|
238
|
+
for (const error of result.errors) {
|
|
239
|
+
errorsCounter.counter
|
|
240
|
+
.labels(errorsCounter.fillLabelsFn({
|
|
241
|
+
...fillLabelsFnParams,
|
|
242
|
+
errorPhase: 'execute',
|
|
243
|
+
error,
|
|
244
|
+
}, args.contextValue))
|
|
245
|
+
.inc();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
235
249
|
const result = {
|
|
236
250
|
onExecuteDone: ({ result }) => {
|
|
237
|
-
const totalTime = (Date.now() - startTime) / 1000;
|
|
238
|
-
executeHistogram.histogram.observe(executeHistogram.fillLabelsFn(fillLabelsFnParams, args.contextValue), totalTime);
|
|
239
|
-
requestTotalHistogram?.histogram.observe(requestTotalHistogram.fillLabelsFn(fillLabelsFnParams, args.contextValue), totalTime);
|
|
240
251
|
const execStartTime = exports.execStartTimeMap.get(args.contextValue);
|
|
241
|
-
|
|
242
|
-
const
|
|
243
|
-
|
|
252
|
+
const handleEnd = () => {
|
|
253
|
+
const totalTime = (Date.now() - startTime) / 1000;
|
|
254
|
+
executeHistogram.histogram.observe(executeHistogram.fillLabelsFn(fillLabelsFnParams, args.contextValue), totalTime);
|
|
255
|
+
requestTotalHistogram?.histogram.observe(requestTotalHistogram.fillLabelsFn(fillLabelsFnParams, args.contextValue), totalTime);
|
|
256
|
+
if (requestSummary && execStartTime) {
|
|
257
|
+
const summaryTime = (Date.now() - execStartTime) / 1000;
|
|
258
|
+
requestSummary.summary.observe(requestSummary.fillLabelsFn(fillLabelsFnParams, args.contextValue), summaryTime);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
if (!(0, core_1.isAsyncIterable)(result)) {
|
|
262
|
+
handleResult(result);
|
|
263
|
+
handleEnd();
|
|
264
|
+
return undefined;
|
|
244
265
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
266
|
+
else {
|
|
267
|
+
return {
|
|
268
|
+
onNext({ result }) {
|
|
269
|
+
handleResult(result);
|
|
270
|
+
},
|
|
271
|
+
onEnd() {
|
|
272
|
+
handleEnd();
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
return result;
|
|
279
|
+
}
|
|
280
|
+
: undefined;
|
|
281
|
+
const onSubscribe = subscribeHistogram
|
|
282
|
+
? ({ args }) => {
|
|
283
|
+
const fillLabelsFnParams = exports.fillLabelsFnParamsMap.get(args.contextValue);
|
|
284
|
+
if (!fillLabelsFnParams) {
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
const startTime = Date.now();
|
|
288
|
+
reqCounter?.counter
|
|
289
|
+
.labels(reqCounter.fillLabelsFn(fillLabelsFnParams, args.contextValue))
|
|
290
|
+
.inc();
|
|
291
|
+
function handleResult(result) {
|
|
292
|
+
if (errorsCounter && result.errors && result.errors.length > 0) {
|
|
293
|
+
for (const error of result.errors) {
|
|
294
|
+
errorsCounter.counter
|
|
295
|
+
.labels(errorsCounter.fillLabelsFn({
|
|
296
|
+
...fillLabelsFnParams,
|
|
297
|
+
errorPhase: 'execute',
|
|
298
|
+
error,
|
|
299
|
+
}, args.contextValue))
|
|
300
|
+
.inc();
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const result = {
|
|
305
|
+
onSubscribeResult: ({ result }) => {
|
|
306
|
+
const execStartTime = exports.execStartTimeMap.get(args.contextValue);
|
|
307
|
+
const handleEnd = () => {
|
|
308
|
+
const totalTime = (Date.now() - startTime) / 1000;
|
|
309
|
+
subscribeHistogram.histogram.observe(subscribeHistogram.fillLabelsFn(fillLabelsFnParams, args.contextValue), totalTime);
|
|
310
|
+
requestTotalHistogram?.histogram.observe(requestTotalHistogram.fillLabelsFn(fillLabelsFnParams, args.contextValue), totalTime);
|
|
311
|
+
if (requestSummary && execStartTime) {
|
|
312
|
+
const summaryTime = (Date.now() - execStartTime) / 1000;
|
|
313
|
+
requestSummary.summary.observe(requestSummary.fillLabelsFn(fillLabelsFnParams, args.contextValue), summaryTime);
|
|
257
314
|
}
|
|
315
|
+
};
|
|
316
|
+
if (!(0, core_1.isAsyncIterable)(result)) {
|
|
317
|
+
handleResult(result);
|
|
318
|
+
handleEnd();
|
|
319
|
+
return undefined;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
return {
|
|
323
|
+
onNext({ result }) {
|
|
324
|
+
handleResult(result);
|
|
325
|
+
},
|
|
326
|
+
onEnd() {
|
|
327
|
+
handleEnd();
|
|
328
|
+
},
|
|
329
|
+
};
|
|
258
330
|
}
|
|
259
331
|
},
|
|
260
332
|
};
|
|
@@ -312,6 +384,7 @@ const usePrometheus = (config = {}) => {
|
|
|
312
384
|
onValidate,
|
|
313
385
|
onContextBuilding,
|
|
314
386
|
onExecute,
|
|
387
|
+
onSubscribe,
|
|
315
388
|
};
|
|
316
389
|
};
|
|
317
390
|
exports.usePrometheus = usePrometheus;
|
package/esm/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export const usePrometheus = (config = {}) => {
|
|
|
13
13
|
const validateHistogram = getHistogramFromConfig(config, 'validate', 'graphql_envelop_phase_validate', 'Time spent on running GraphQL "validate" function');
|
|
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
|
+
const subscribeHistogram = getHistogramFromConfig(config, 'subscribe', 'graphql_envelop_phase_subscribe', 'Time spent on running the GraphQL "subscribe" function');
|
|
16
17
|
function labelExists(label) {
|
|
17
18
|
const labelFlag = config.labels?.[label];
|
|
18
19
|
if (labelFlag == null) {
|
|
@@ -227,29 +228,100 @@ export const usePrometheus = (config = {}) => {
|
|
|
227
228
|
reqCounter?.counter
|
|
228
229
|
.labels(reqCounter.fillLabelsFn(fillLabelsFnParams, args.contextValue))
|
|
229
230
|
.inc();
|
|
231
|
+
function handleResult(result) {
|
|
232
|
+
if (errorsCounter && result.errors && result.errors.length > 0) {
|
|
233
|
+
for (const error of result.errors) {
|
|
234
|
+
errorsCounter.counter
|
|
235
|
+
.labels(errorsCounter.fillLabelsFn({
|
|
236
|
+
...fillLabelsFnParams,
|
|
237
|
+
errorPhase: 'execute',
|
|
238
|
+
error,
|
|
239
|
+
}, args.contextValue))
|
|
240
|
+
.inc();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
230
244
|
const result = {
|
|
231
245
|
onExecuteDone: ({ result }) => {
|
|
232
|
-
const totalTime = (Date.now() - startTime) / 1000;
|
|
233
|
-
executeHistogram.histogram.observe(executeHistogram.fillLabelsFn(fillLabelsFnParams, args.contextValue), totalTime);
|
|
234
|
-
requestTotalHistogram?.histogram.observe(requestTotalHistogram.fillLabelsFn(fillLabelsFnParams, args.contextValue), totalTime);
|
|
235
246
|
const execStartTime = execStartTimeMap.get(args.contextValue);
|
|
236
|
-
|
|
237
|
-
const
|
|
238
|
-
|
|
247
|
+
const handleEnd = () => {
|
|
248
|
+
const totalTime = (Date.now() - startTime) / 1000;
|
|
249
|
+
executeHistogram.histogram.observe(executeHistogram.fillLabelsFn(fillLabelsFnParams, args.contextValue), totalTime);
|
|
250
|
+
requestTotalHistogram?.histogram.observe(requestTotalHistogram.fillLabelsFn(fillLabelsFnParams, args.contextValue), totalTime);
|
|
251
|
+
if (requestSummary && execStartTime) {
|
|
252
|
+
const summaryTime = (Date.now() - execStartTime) / 1000;
|
|
253
|
+
requestSummary.summary.observe(requestSummary.fillLabelsFn(fillLabelsFnParams, args.contextValue), summaryTime);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
if (!isAsyncIterable(result)) {
|
|
257
|
+
handleResult(result);
|
|
258
|
+
handleEnd();
|
|
259
|
+
return undefined;
|
|
239
260
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
261
|
+
else {
|
|
262
|
+
return {
|
|
263
|
+
onNext({ result }) {
|
|
264
|
+
handleResult(result);
|
|
265
|
+
},
|
|
266
|
+
onEnd() {
|
|
267
|
+
handleEnd();
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
return result;
|
|
274
|
+
}
|
|
275
|
+
: undefined;
|
|
276
|
+
const onSubscribe = subscribeHistogram
|
|
277
|
+
? ({ args }) => {
|
|
278
|
+
const fillLabelsFnParams = fillLabelsFnParamsMap.get(args.contextValue);
|
|
279
|
+
if (!fillLabelsFnParams) {
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
const startTime = Date.now();
|
|
283
|
+
reqCounter?.counter
|
|
284
|
+
.labels(reqCounter.fillLabelsFn(fillLabelsFnParams, args.contextValue))
|
|
285
|
+
.inc();
|
|
286
|
+
function handleResult(result) {
|
|
287
|
+
if (errorsCounter && result.errors && result.errors.length > 0) {
|
|
288
|
+
for (const error of result.errors) {
|
|
289
|
+
errorsCounter.counter
|
|
290
|
+
.labels(errorsCounter.fillLabelsFn({
|
|
291
|
+
...fillLabelsFnParams,
|
|
292
|
+
errorPhase: 'execute',
|
|
293
|
+
error,
|
|
294
|
+
}, args.contextValue))
|
|
295
|
+
.inc();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const result = {
|
|
300
|
+
onSubscribeResult: ({ result }) => {
|
|
301
|
+
const execStartTime = execStartTimeMap.get(args.contextValue);
|
|
302
|
+
const handleEnd = () => {
|
|
303
|
+
const totalTime = (Date.now() - startTime) / 1000;
|
|
304
|
+
subscribeHistogram.histogram.observe(subscribeHistogram.fillLabelsFn(fillLabelsFnParams, args.contextValue), totalTime);
|
|
305
|
+
requestTotalHistogram?.histogram.observe(requestTotalHistogram.fillLabelsFn(fillLabelsFnParams, args.contextValue), totalTime);
|
|
306
|
+
if (requestSummary && execStartTime) {
|
|
307
|
+
const summaryTime = (Date.now() - execStartTime) / 1000;
|
|
308
|
+
requestSummary.summary.observe(requestSummary.fillLabelsFn(fillLabelsFnParams, args.contextValue), summaryTime);
|
|
252
309
|
}
|
|
310
|
+
};
|
|
311
|
+
if (!isAsyncIterable(result)) {
|
|
312
|
+
handleResult(result);
|
|
313
|
+
handleEnd();
|
|
314
|
+
return undefined;
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
return {
|
|
318
|
+
onNext({ result }) {
|
|
319
|
+
handleResult(result);
|
|
320
|
+
},
|
|
321
|
+
onEnd() {
|
|
322
|
+
handleEnd();
|
|
323
|
+
},
|
|
324
|
+
};
|
|
253
325
|
}
|
|
254
326
|
},
|
|
255
327
|
};
|
|
@@ -307,5 +379,6 @@ export const usePrometheus = (config = {}) => {
|
|
|
307
379
|
onValidate,
|
|
308
380
|
onContextBuilding,
|
|
309
381
|
onExecute,
|
|
382
|
+
onSubscribe,
|
|
310
383
|
};
|
|
311
384
|
};
|
package/package.json
CHANGED
package/typings/config.d.cts
CHANGED
|
@@ -8,6 +8,7 @@ export type PrometheusTracingPluginConfig = {
|
|
|
8
8
|
validate?: boolean | ReturnType<typeof createHistogram>;
|
|
9
9
|
contextBuilding?: boolean | ReturnType<typeof createHistogram>;
|
|
10
10
|
execute?: boolean | ReturnType<typeof createHistogram>;
|
|
11
|
+
subscribe?: boolean | ReturnType<typeof createHistogram>;
|
|
11
12
|
errors?: boolean | ReturnType<typeof createCounter>;
|
|
12
13
|
resolvers?: boolean | ReturnType<typeof createHistogram>;
|
|
13
14
|
resolversWhitelist?: string[];
|
package/typings/config.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type PrometheusTracingPluginConfig = {
|
|
|
8
8
|
validate?: boolean | ReturnType<typeof createHistogram>;
|
|
9
9
|
contextBuilding?: boolean | ReturnType<typeof createHistogram>;
|
|
10
10
|
execute?: boolean | ReturnType<typeof createHistogram>;
|
|
11
|
+
subscribe?: boolean | ReturnType<typeof createHistogram>;
|
|
11
12
|
errors?: boolean | ReturnType<typeof createCounter>;
|
|
12
13
|
resolvers?: boolean | ReturnType<typeof createHistogram>;
|
|
13
14
|
resolversWhitelist?: string[];
|