New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@envelop/prometheus

Package Overview
Dependencies
Maintainers
0
Versions
1403
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@envelop/prometheus - npm Package Compare versions

Comparing version 11.0.0-alpha-20240726191829-a22a25d0 to 11.0.0-alpha-20240726211739-58c6a26f

217

cjs/index.js

@@ -15,162 +15,61 @@ "use strict";

exports.execStartTimeMap = new WeakMap();
const usePrometheus = (config = {}) => {
const usePrometheus = (config) => {
let typeInfo = null;
const registry = (0, utils_js_1.instrumentRegistry)(config.registry || prom_client_1.register);
const parseHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_phase_parse', typeof config.graphql_envelop_phase_parse === 'string'
? config.graphql_envelop_phase_parse
: 'graphql_envelop_phase_parse', 'Time spent on running GraphQL "parse" function');
const validateHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_phase_validate', typeof config.graphql_envelop_phase_validate === 'string'
? config.graphql_envelop_phase_validate
: 'graphql_envelop_phase_validate', 'Time spent on running GraphQL "validate" function');
const contextBuildingHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_phase_context', typeof config.graphql_envelop_phase_context === 'string'
? config.graphql_envelop_phase_context
: 'graphql_envelop_phase_context', 'Time spent on building the GraphQL context');
const executeHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_phase_execute', typeof config.graphql_envelop_phase_execute === 'string'
? config.graphql_envelop_phase_execute
: 'graphql_envelop_phase_execute', 'Time spent on running the GraphQL "execute" function');
const subscribeHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_phase_subscribe', typeof config.graphql_envelop_phase_subscribe === 'string'
? config.graphql_envelop_phase_subscribe
: 'graphql_envelop_phase_subscribe', 'Time spent on running the GraphQL "subscribe" function');
const resolversHistogram = typeof config.graphql_envelop_execute_resolver === 'object'
? config.graphql_envelop_execute_resolver
: config.graphql_envelop_execute_resolver === true ||
typeof config.graphql_envelop_execute_resolver === 'string'
? (0, utils_js_1.createHistogram)({
registry,
histogram: {
name: typeof config.graphql_envelop_execute_resolver === 'string'
? config.graphql_envelop_execute_resolver
: 'graphql_envelop_execute_resolver',
help: 'Time spent on running the GraphQL resolvers',
labelNames: [
'operationType',
'operationName',
'fieldName',
'typeName',
'returnType',
].filter(label => (0, utils_js_1.labelExists)(config, label)),
},
fillLabelsFn: params => (0, utils_js_1.filterFillParamsFnParams)(config, {
operationName: params.operationName,
operationType: params.operationType,
fieldName: params.info?.fieldName,
typeName: params.info?.parentType.name,
returnType: params.info?.returnType.toString(),
}),
})
: undefined;
const requestTotalHistogram = typeof config.graphql_envelop_request_duration === 'object'
? config.graphql_envelop_request_duration
: config.graphql_envelop_request_duration === true ||
typeof config.graphql_envelop_request_duration === 'string'
? (0, utils_js_1.createHistogram)({
registry,
histogram: {
name: typeof config.graphql_envelop_request_duration === 'string'
? config.graphql_envelop_request_duration
: 'graphql_envelop_request_duration',
help: 'Time spent on running the GraphQL operation from parse to execute',
labelNames: ['operationType', 'operationName'].filter(label => (0, utils_js_1.labelExists)(config, label)),
},
fillLabelsFn: params => (0, utils_js_1.filterFillParamsFnParams)(config, {
operationName: params.operationName,
operationType: params.operationType,
}),
})
: undefined;
const requestSummary = typeof config.graphql_envelop_request_time_summary === 'object'
? config.graphql_envelop_request_time_summary
: config.graphql_envelop_request_time_summary === true ||
typeof config.graphql_envelop_request_time_summary === 'string'
? (0, utils_js_1.createSummary)({
registry,
summary: {
name: typeof config.graphql_envelop_request_time_summary === 'string'
? config.graphql_envelop_request_time_summary
: 'graphql_envelop_request_time_summary',
help: 'Summary to measure the time to complete GraphQL operations',
labelNames: ['operationType', 'operationName'].filter(label => (0, utils_js_1.labelExists)(config, label)),
},
fillLabelsFn: params => (0, utils_js_1.filterFillParamsFnParams)(config, {
operationName: params.operationName,
operationType: params.operationType,
}),
})
: undefined;
const errorsCounter = typeof config.graphql_envelop_error_result === 'object'
? config.graphql_envelop_error_result
: config.graphql_envelop_error_result === true ||
typeof config.graphql_envelop_error_result === 'string'
? (0, utils_js_1.createCounter)({
registry,
counter: {
name: typeof config.graphql_envelop_error_result === 'string'
? config.graphql_envelop_error_result
: 'graphql_envelop_error_result',
help: 'Counts the amount of errors reported from all phases',
labelNames: ['operationType', 'operationName', 'path', 'phase'].filter(label => (0, utils_js_1.labelExists)(config, label)),
},
fillLabelsFn: params => (0, utils_js_1.filterFillParamsFnParams)(config, {
operationName: params.operationName,
operationType: params.operationType,
path: params.error?.path?.join('.'),
phase: params.errorPhase,
}),
})
: undefined;
const reqCounter = typeof config.graphql_envelop_request === 'object'
? config.graphql_envelop_request
: config.graphql_envelop_request === true ||
typeof config.graphql_envelop_request === 'string'
? (0, utils_js_1.createCounter)({
registry,
counter: {
name: typeof config.graphql_envelop_request === 'string'
? config.graphql_envelop_request
: 'graphql_envelop_request',
help: 'Counts the amount of GraphQL requests executed through Envelop',
labelNames: ['operationType', 'operationName'].filter(label => (0, utils_js_1.labelExists)(config, label)),
},
fillLabelsFn: params => (0, utils_js_1.filterFillParamsFnParams)(config, {
operationName: params.operationName,
operationType: params.operationType,
}),
})
: undefined;
const deprecationCounter = typeof config.graphql_envelop_deprecated_field === 'object'
? config.graphql_envelop_deprecated_field
: config.graphql_envelop_deprecated_field === true ||
typeof config.graphql_envelop_deprecated_field === 'string'
? (0, utils_js_1.createCounter)({
registry,
counter: {
name: typeof config.graphql_envelop_deprecated_field === 'string'
? config.graphql_envelop_deprecated_field
: 'graphql_envelop_deprecated_field',
help: 'Counts the amount of deprecated fields used in selection sets',
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName'].filter(label => (0, utils_js_1.labelExists)(config, label)),
},
fillLabelsFn: params => (0, utils_js_1.filterFillParamsFnParams)(config, {
operationName: params.operationName,
operationType: params.operationType,
fieldName: params.deprecationInfo?.fieldName,
typeName: params.deprecationInfo?.typeName,
}),
})
: undefined;
const schemaChangeCounter = typeof config.graphql_envelop_schema_change === 'object'
? config.graphql_envelop_schema_change
: config.graphql_envelop_schema_change === true ||
typeof config.graphql_envelop_schema_change === 'string'
? (0, utils_js_1.createCounter)({
registry,
counter: {
name: typeof config.graphql_envelop_schema_change === 'string'
? config.graphql_envelop_schema_change
: 'graphql_envelop_schema_change',
help: 'Counts the amount of schema changes',
},
fillLabelsFn: () => ({}),
})
: undefined;
config.registry = (0, utils_js_1.instrumentRegistry)(config.registry || prom_client_1.register);
const parseHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_phase_parse', {
help: 'Time spent on running GraphQL "parse" function',
});
const validateHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_phase_validate', {
help: 'Time spent on running GraphQL "validate" function',
});
const contextBuildingHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_phase_context', {
help: 'Time spent on building the GraphQL context',
});
const executeHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_phase_execute', {
help: 'Time spent on running the GraphQL "execute" function',
});
const subscribeHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_phase_subscribe', {
help: 'Time spent on running the GraphQL "subscribe" function',
});
const resolversHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_execute_resolver', {
help: 'Time spent on running the GraphQL resolvers',
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName', 'returnType'].filter(label => (0, utils_js_1.labelExists)(config, label)),
}, params => (0, utils_js_1.filterFillParamsFnParams)(config, {
operationName: params.operationName,
operationType: params.operationType,
fieldName: params.info?.fieldName,
typeName: params.info?.parentType.name,
returnType: params.info?.returnType.toString(),
}));
const requestTotalHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'graphql_envelop_request_duration', {
help: 'Time spent on running the GraphQL operation from parse to execute',
});
const requestSummary = (0, utils_js_1.getSummaryFromConfig)(config, 'graphql_envelop_request_time_summary', {
help: 'Summary to measure the time to complete GraphQL operations',
});
const errorsCounter = (0, utils_js_1.getCounterFromConfig)(config, 'graphql_envelop_error_result', {
help: 'Counts the amount of errors reported from all phases',
labelNames: ['operationType', 'operationName', 'path', 'phase'].filter(label => (0, utils_js_1.labelExists)(config, label)),
}, params => (0, utils_js_1.filterFillParamsFnParams)(config, {
operationName: params.operationName,
operationType: params.operationType,
path: params.error?.path?.join('.'),
phase: params.errorPhase,
}));
const reqCounter = (0, utils_js_1.getCounterFromConfig)(config, 'graphql_envelop_request', {
help: 'Counts the amount of GraphQL requests executed through Envelop',
});
const deprecationCounter = (0, utils_js_1.getCounterFromConfig)(config, 'graphql_envelop_deprecated_field', {
help: 'Counts the amount of deprecated fields used in selection sets',
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName'].filter(label => (0, utils_js_1.labelExists)(config, label)),
}, params => (0, utils_js_1.filterFillParamsFnParams)(config, {
operationName: params.operationName,
operationType: params.operationType,
fieldName: params.deprecationInfo?.fieldName,
typeName: params.deprecationInfo?.typeName,
}));
const schemaChangeCounter = (0, utils_js_1.getCounterFromConfig)(config, 'graphql_envelop_schema_change', {
help: 'Counts the amount of schema changes',
labelNames: [],
}, () => ({}));
const onParse = ({ context, params }) => {

@@ -177,0 +76,0 @@ if (config.skipIntrospection && (0, core_1.isIntrospectionOperationString)(params.source)) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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;
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;
const graphql_1 = require("graphql");

@@ -95,17 +95,18 @@ const prom_client_1 = require("prom-client");

exports.createCounter = createCounter;
function getHistogramFromConfig(config, phase, name, help) {
return typeof config[phase] === 'object'
? config[phase]
: config[phase] === true
function getHistogramFromConfig(config, phase, histogram, fillLabelsFn = params => filterFillParamsFnParams(config, {
operationName: params.operationName,
operationType: params.operationType,
})) {
const metric = config.metrics[phase];
return typeof metric === 'object'
? metric
: metric === true
? createHistogram({
registry: config.registry || prom_client_1.register,
histogram: {
name,
help,
name: typeof metric === 'string' ? metric : phase,
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
...histogram,
},
fillLabelsFn: params => filterFillParamsFnParams(config, {
operationName: params.operationName,
operationType: params.operationType,
}),
fillLabelsFn,
})

@@ -115,2 +116,42 @@ : undefined;

exports.getHistogramFromConfig = getHistogramFromConfig;
function getSummaryFromConfig(config, phase, summary, fillLabelsFn = params => filterFillParamsFnParams(config, {
operationName: params.operationName,
operationType: params.operationType,
})) {
const metric = config.metrics[phase];
return typeof metric === 'object'
? metric
: metric === true
? createSummary({
registry: config.registry || prom_client_1.register,
summary: {
name: typeof metric === 'string' ? metric : phase,
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
...summary,
},
fillLabelsFn,
})
: undefined;
}
exports.getSummaryFromConfig = getSummaryFromConfig;
function getCounterFromConfig(config, phase, counter, fillLabelsFn = params => filterFillParamsFnParams(config, {
operationName: params.operationName,
operationType: params.operationType,
})) {
const metric = config.metrics[phase];
return typeof metric === 'object'
? metric
: metric === true
? createCounter({
registry: config.registry || prom_client_1.register,
counter: {
name: typeof metric === 'string' ? metric : phase,
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
...counter,
},
fillLabelsFn,
})
: undefined;
}
exports.getCounterFromConfig = getCounterFromConfig;
function extractDeprecatedFields(node, typeInfo) {

@@ -117,0 +158,0 @@ const found = [];

@@ -6,166 +6,65 @@ /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */

import { useOnResolve } from '@envelop/on-resolve';
import { createCounter, createFillLabelFnParams, createHistogram, createSummary, extractDeprecatedFields, filterFillParamsFnParams, getHistogramFromConfig, instrumentRegistry, labelExists, shouldTraceFieldResolver, } from './utils.js';
import { createCounter, createFillLabelFnParams, createHistogram, createSummary, extractDeprecatedFields, filterFillParamsFnParams, getCounterFromConfig, getHistogramFromConfig, getSummaryFromConfig, instrumentRegistry, labelExists, shouldTraceFieldResolver, } from './utils.js';
export { createCounter, createHistogram, createSummary, };
export const fillLabelsFnParamsMap = new WeakMap();
export const execStartTimeMap = new WeakMap();
export const usePrometheus = (config = {}) => {
export const usePrometheus = (config) => {
let typeInfo = null;
const registry = instrumentRegistry(config.registry || defaultRegistry);
const parseHistogram = getHistogramFromConfig(config, 'graphql_envelop_phase_parse', typeof config.graphql_envelop_phase_parse === 'string'
? config.graphql_envelop_phase_parse
: 'graphql_envelop_phase_parse', 'Time spent on running GraphQL "parse" function');
const validateHistogram = getHistogramFromConfig(config, 'graphql_envelop_phase_validate', typeof config.graphql_envelop_phase_validate === 'string'
? config.graphql_envelop_phase_validate
: 'graphql_envelop_phase_validate', 'Time spent on running GraphQL "validate" function');
const contextBuildingHistogram = getHistogramFromConfig(config, 'graphql_envelop_phase_context', typeof config.graphql_envelop_phase_context === 'string'
? config.graphql_envelop_phase_context
: 'graphql_envelop_phase_context', 'Time spent on building the GraphQL context');
const executeHistogram = getHistogramFromConfig(config, 'graphql_envelop_phase_execute', typeof config.graphql_envelop_phase_execute === 'string'
? config.graphql_envelop_phase_execute
: 'graphql_envelop_phase_execute', 'Time spent on running the GraphQL "execute" function');
const subscribeHistogram = getHistogramFromConfig(config, 'graphql_envelop_phase_subscribe', typeof config.graphql_envelop_phase_subscribe === 'string'
? config.graphql_envelop_phase_subscribe
: 'graphql_envelop_phase_subscribe', 'Time spent on running the GraphQL "subscribe" function');
const resolversHistogram = typeof config.graphql_envelop_execute_resolver === 'object'
? config.graphql_envelop_execute_resolver
: config.graphql_envelop_execute_resolver === true ||
typeof config.graphql_envelop_execute_resolver === 'string'
? createHistogram({
registry,
histogram: {
name: typeof config.graphql_envelop_execute_resolver === 'string'
? config.graphql_envelop_execute_resolver
: 'graphql_envelop_execute_resolver',
help: 'Time spent on running the GraphQL resolvers',
labelNames: [
'operationType',
'operationName',
'fieldName',
'typeName',
'returnType',
].filter(label => labelExists(config, label)),
},
fillLabelsFn: params => filterFillParamsFnParams(config, {
operationName: params.operationName,
operationType: params.operationType,
fieldName: params.info?.fieldName,
typeName: params.info?.parentType.name,
returnType: params.info?.returnType.toString(),
}),
})
: undefined;
const requestTotalHistogram = typeof config.graphql_envelop_request_duration === 'object'
? config.graphql_envelop_request_duration
: config.graphql_envelop_request_duration === true ||
typeof config.graphql_envelop_request_duration === 'string'
? createHistogram({
registry,
histogram: {
name: typeof config.graphql_envelop_request_duration === 'string'
? config.graphql_envelop_request_duration
: 'graphql_envelop_request_duration',
help: 'Time spent on running the GraphQL operation from parse to execute',
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
},
fillLabelsFn: params => filterFillParamsFnParams(config, {
operationName: params.operationName,
operationType: params.operationType,
}),
})
: undefined;
const requestSummary = typeof config.graphql_envelop_request_time_summary === 'object'
? config.graphql_envelop_request_time_summary
: config.graphql_envelop_request_time_summary === true ||
typeof config.graphql_envelop_request_time_summary === 'string'
? createSummary({
registry,
summary: {
name: typeof config.graphql_envelop_request_time_summary === 'string'
? config.graphql_envelop_request_time_summary
: 'graphql_envelop_request_time_summary',
help: 'Summary to measure the time to complete GraphQL operations',
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
},
fillLabelsFn: params => filterFillParamsFnParams(config, {
operationName: params.operationName,
operationType: params.operationType,
}),
})
: undefined;
const errorsCounter = typeof config.graphql_envelop_error_result === 'object'
? config.graphql_envelop_error_result
: config.graphql_envelop_error_result === true ||
typeof config.graphql_envelop_error_result === 'string'
? createCounter({
registry,
counter: {
name: typeof config.graphql_envelop_error_result === 'string'
? config.graphql_envelop_error_result
: 'graphql_envelop_error_result',
help: 'Counts the amount of errors reported from all phases',
labelNames: ['operationType', 'operationName', 'path', 'phase'].filter(label => labelExists(config, label)),
},
fillLabelsFn: params => filterFillParamsFnParams(config, {
operationName: params.operationName,
operationType: params.operationType,
path: params.error?.path?.join('.'),
phase: params.errorPhase,
}),
})
: undefined;
const reqCounter = typeof config.graphql_envelop_request === 'object'
? config.graphql_envelop_request
: config.graphql_envelop_request === true ||
typeof config.graphql_envelop_request === 'string'
? createCounter({
registry,
counter: {
name: typeof config.graphql_envelop_request === 'string'
? config.graphql_envelop_request
: 'graphql_envelop_request',
help: 'Counts the amount of GraphQL requests executed through Envelop',
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
},
fillLabelsFn: params => filterFillParamsFnParams(config, {
operationName: params.operationName,
operationType: params.operationType,
}),
})
: undefined;
const deprecationCounter = typeof config.graphql_envelop_deprecated_field === 'object'
? config.graphql_envelop_deprecated_field
: config.graphql_envelop_deprecated_field === true ||
typeof config.graphql_envelop_deprecated_field === 'string'
? createCounter({
registry,
counter: {
name: typeof config.graphql_envelop_deprecated_field === 'string'
? config.graphql_envelop_deprecated_field
: 'graphql_envelop_deprecated_field',
help: 'Counts the amount of deprecated fields used in selection sets',
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName'].filter(label => labelExists(config, label)),
},
fillLabelsFn: params => filterFillParamsFnParams(config, {
operationName: params.operationName,
operationType: params.operationType,
fieldName: params.deprecationInfo?.fieldName,
typeName: params.deprecationInfo?.typeName,
}),
})
: undefined;
const schemaChangeCounter = typeof config.graphql_envelop_schema_change === 'object'
? config.graphql_envelop_schema_change
: config.graphql_envelop_schema_change === true ||
typeof config.graphql_envelop_schema_change === 'string'
? createCounter({
registry,
counter: {
name: typeof config.graphql_envelop_schema_change === 'string'
? config.graphql_envelop_schema_change
: 'graphql_envelop_schema_change',
help: 'Counts the amount of schema changes',
},
fillLabelsFn: () => ({}),
})
: undefined;
config.registry = instrumentRegistry(config.registry || defaultRegistry);
const parseHistogram = getHistogramFromConfig(config, 'graphql_envelop_phase_parse', {
help: 'Time spent on running GraphQL "parse" function',
});
const validateHistogram = getHistogramFromConfig(config, 'graphql_envelop_phase_validate', {
help: 'Time spent on running GraphQL "validate" function',
});
const contextBuildingHistogram = getHistogramFromConfig(config, 'graphql_envelop_phase_context', {
help: 'Time spent on building the GraphQL context',
});
const executeHistogram = getHistogramFromConfig(config, 'graphql_envelop_phase_execute', {
help: 'Time spent on running the GraphQL "execute" function',
});
const subscribeHistogram = getHistogramFromConfig(config, 'graphql_envelop_phase_subscribe', {
help: 'Time spent on running the GraphQL "subscribe" function',
});
const resolversHistogram = getHistogramFromConfig(config, 'graphql_envelop_execute_resolver', {
help: 'Time spent on running the GraphQL resolvers',
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName', 'returnType'].filter(label => labelExists(config, label)),
}, params => filterFillParamsFnParams(config, {
operationName: params.operationName,
operationType: params.operationType,
fieldName: params.info?.fieldName,
typeName: params.info?.parentType.name,
returnType: params.info?.returnType.toString(),
}));
const requestTotalHistogram = getHistogramFromConfig(config, 'graphql_envelop_request_duration', {
help: 'Time spent on running the GraphQL operation from parse to execute',
});
const requestSummary = getSummaryFromConfig(config, 'graphql_envelop_request_time_summary', {
help: 'Summary to measure the time to complete GraphQL operations',
});
const errorsCounter = getCounterFromConfig(config, 'graphql_envelop_error_result', {
help: 'Counts the amount of errors reported from all phases',
labelNames: ['operationType', 'operationName', 'path', 'phase'].filter(label => labelExists(config, label)),
}, params => filterFillParamsFnParams(config, {
operationName: params.operationName,
operationType: params.operationType,
path: params.error?.path?.join('.'),
phase: params.errorPhase,
}));
const reqCounter = getCounterFromConfig(config, 'graphql_envelop_request', {
help: 'Counts the amount of GraphQL requests executed through Envelop',
});
const deprecationCounter = getCounterFromConfig(config, 'graphql_envelop_deprecated_field', {
help: 'Counts the amount of deprecated fields used in selection sets',
labelNames: ['operationType', 'operationName', 'fieldName', 'typeName'].filter(label => labelExists(config, label)),
}, params => filterFillParamsFnParams(config, {
operationName: params.operationName,
operationType: params.operationType,
fieldName: params.deprecationInfo?.fieldName,
typeName: params.deprecationInfo?.typeName,
}));
const schemaChangeCounter = getCounterFromConfig(config, 'graphql_envelop_schema_change', {
help: 'Counts the amount of schema changes',
labelNames: [],
}, () => ({}));
const onParse = ({ context, params }) => {

@@ -172,0 +71,0 @@ if (config.skipIntrospection && isIntrospectionOperationString(params.source)) {

@@ -84,20 +84,59 @@ import { visit, visitWithTypeInfo, } from 'graphql';

}
export function getHistogramFromConfig(config, phase, name, help) {
return typeof config[phase] === 'object'
? config[phase]
: config[phase] === true
export function getHistogramFromConfig(config, phase, histogram, fillLabelsFn = params => filterFillParamsFnParams(config, {
operationName: params.operationName,
operationType: params.operationType,
})) {
const metric = config.metrics[phase];
return typeof metric === 'object'
? metric
: metric === true
? createHistogram({
registry: config.registry || defaultRegistry,
histogram: {
name,
help,
name: typeof metric === 'string' ? metric : phase,
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
...histogram,
},
fillLabelsFn: params => filterFillParamsFnParams(config, {
operationName: params.operationName,
operationType: params.operationType,
}),
fillLabelsFn,
})
: undefined;
}
export function getSummaryFromConfig(config, phase, summary, fillLabelsFn = params => filterFillParamsFnParams(config, {
operationName: params.operationName,
operationType: params.operationType,
})) {
const metric = config.metrics[phase];
return typeof metric === 'object'
? metric
: metric === true
? createSummary({
registry: config.registry || defaultRegistry,
summary: {
name: typeof metric === 'string' ? metric : phase,
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
...summary,
},
fillLabelsFn,
})
: undefined;
}
export function getCounterFromConfig(config, phase, counter, fillLabelsFn = params => filterFillParamsFnParams(config, {
operationName: params.operationName,
operationType: params.operationType,
})) {
const metric = config.metrics[phase];
return typeof metric === 'object'
? metric
: metric === true
? createCounter({
registry: config.registry || defaultRegistry,
counter: {
name: typeof metric === 'string' ? metric : phase,
labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
...counter,
},
fillLabelsFn,
})
: undefined;
}
export function extractDeprecatedFields(node, typeInfo) {

@@ -104,0 +143,0 @@ const found = [];

{
"name": "@envelop/prometheus",
"version": "11.0.0-alpha-20240726191829-a22a25d0",
"version": "11.0.0-alpha-20240726211739-58c6a26f",
"sideEffects": false,

@@ -5,0 +5,0 @@ "peerDependencies": {

@@ -6,2 +6,7 @@ import { Registry } from 'prom-client';

skipIntrospection?: boolean;
resolversWhitelist?: string[];
metrics: MetricsConfig;
labels?: LabelsConfig;
};
export type MetricsConfig = {
graphql_envelop_request?: boolean | string | ReturnType<typeof createCounter>;

@@ -19,10 +24,9 @@ graphql_envelop_request_duration?: boolean | string | ReturnType<typeof createHistogram>;

graphql_envelop_execute_resolver?: boolean | string | ReturnType<typeof createHistogram>;
resolversWhitelist?: string[];
labels?: {
operationName?: boolean;
operationType?: boolean;
fieldName?: boolean;
typeName?: boolean;
returnType?: boolean;
};
};
export type LabelsConfig = {
operationName?: boolean;
operationType?: boolean;
fieldName?: boolean;
typeName?: boolean;
returnType?: boolean;
};

@@ -7,2 +7,2 @@ import { Plugin } from '@envelop/core';

export declare const execStartTimeMap: WeakMap<any, number>;
export declare const usePrometheus: (config?: PrometheusTracingPluginConfig) => Plugin;
export declare const usePrometheus: (config: PrometheusTracingPluginConfig) => Plugin;

@@ -51,8 +51,8 @@ import { ASTNode, DocumentNode, GraphQLError, GraphQLResolveInfo, OperationDefinitionNode, TypeInfo } from 'graphql';

}): CounterAndLabels<LabelNames, Params>;
export declare function getHistogramFromConfig(config: PrometheusTracingPluginConfig, phase: keyof PrometheusTracingPluginConfig, name: string, help: string): ReturnType<typeof createHistogram> | undefined;
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;
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;
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;
export declare function extractDeprecatedFields(node: ASTNode, typeInfo: TypeInfo): DeprecatedFieldInfo[];
export declare function labelExists(config: PrometheusTracingPluginConfig, label: string): any;
export declare function filterFillParamsFnParams(config: PrometheusTracingPluginConfig, params: Record<string, any>): {
[k: string]: any;
};
export declare function filterFillParamsFnParams<T extends string>(config: PrometheusTracingPluginConfig, params: Partial<Record<T, any>>): Record<T, any>;
export declare function instrumentRegistry(registry: Registry): Registry<"text/plain; version=0.0.4; charset=utf-8">;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc