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
1
Versions
1434
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 12.0.0-alpha-20241119110638-78ea8d1b8abb6ba89f9a443e4742e9c43bb1b145 to 12.0.0-alpha-20241121114839-bf3487aac3c9d6ab1a346b04280cbff55df83ca1

8

cjs/index.js

@@ -451,6 +451,10 @@ "use strict";

onContextBuilding: phasesToHook.context.length ? onContextBuilding : undefined,
onExecute: phasesToHook.execute ? onExecute : undefined,
onSubscribe: phasesToHook.subscribe ? onSubscribe : undefined,
onExecute: phasesToHook.execute.end.length + phasesToHook.execute.result.length ? onExecute : undefined,
onSubscribe: phasesToHook.subscribe.end.length +
phasesToHook.subscribe.result.length +
phasesToHook.subscribe.error.length
? onSubscribe
: undefined,
};
};
exports.usePrometheus = usePrometheus;

@@ -111,3 +111,3 @@ "use strict";

phases: options.phases,
shouldObserve: options.shouldObserve ?? (() => true),
shouldObserve: options.shouldObserve,
};

@@ -121,5 +121,11 @@ }

const metric = config.metrics[phase];
if (!metric) {
return undefined;
}
let phases = availablePhases;
if (Array.isArray(metric) && metric.length === 0) {
if (isBucketsList(metric)) {
if (Array.isArray(metric)) {
if (metric.length === 0) {
throw TypeError(`Bad value provided for 'metrics.${phase.toString()}': the array must contain at least one element`);
}
else if (isBucketsList(metric)) {
histogram.buckets = metric;

@@ -139,7 +145,7 @@ }

}
if (!customMetric.shouldObserve) {
customMetric.shouldObserve = () => true;
}
return customMetric;
}
if (metric !== true) {
return undefined;
}
return createHistogram({

@@ -154,2 +160,3 @@ registry: config.registry || prom_client_1.register,

phases,
shouldObserve: () => true,
});

@@ -163,5 +170,11 @@ }

const metric = config.metrics[phase];
if (!metric) {
return undefined;
}
let phases = availablePhases;
if (Array.isArray(metric)) {
if (isPhasesList(metric)) {
if (metric.length === 0) {
throw TypeError(`Bad value provided for 'metrics.${phase.toString()}': the array must contain at least one element`);
}
else if (isPhasesList(metric)) {
phases = filterAvailablePhases(metric, availablePhases);

@@ -178,7 +191,7 @@ }

}
if (!customMetric.shouldObserve) {
customMetric.shouldObserve = () => true;
}
return customMetric;
}
if (metric !== true) {
return undefined;
}
return createSummary({

@@ -193,2 +206,3 @@ registry: config.registry || prom_client_1.register,

phases,
shouldObserve: () => true,
});

@@ -203,4 +217,10 @@ }

let phases = availablePhases;
if (!metric) {
return undefined;
}
if (Array.isArray(metric)) {
if (isPhasesList(metric)) {
if (metric.length === 0) {
throw TypeError(`Bad value provided for 'metrics.${phase.toString()}': the array must contain at least one element`);
}
else if (isPhasesList(metric)) {
phases = filterAvailablePhases(metric, availablePhases);

@@ -217,7 +237,7 @@ }

}
if (!customMetric.shouldObserve) {
customMetric.shouldObserve = () => true;
}
return customMetric;
}
if (metric !== true) {
return undefined;
}
return createCounter({

@@ -232,2 +252,3 @@ registry: config.registry || prom_client_1.register,

phases,
shouldObserve: () => true,
});

@@ -299,3 +320,3 @@ }

function filterAvailablePhases(phases, availablePhases) {
return phases.filter(phase => availablePhases.includes(phase));
return availablePhases.filter(phase => phases.includes(phase));
}

@@ -443,5 +443,9 @@ /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */

onContextBuilding: phasesToHook.context.length ? onContextBuilding : undefined,
onExecute: phasesToHook.execute ? onExecute : undefined,
onSubscribe: phasesToHook.subscribe ? onSubscribe : undefined,
onExecute: phasesToHook.execute.end.length + phasesToHook.execute.result.length ? onExecute : undefined,
onSubscribe: phasesToHook.subscribe.end.length +
phasesToHook.subscribe.result.length +
phasesToHook.subscribe.error.length
? onSubscribe
: undefined,
};
};

@@ -101,3 +101,3 @@ import { visit, visitWithTypeInfo, } from 'graphql';

phases: options.phases,
shouldObserve: options.shouldObserve ?? (() => true),
shouldObserve: options.shouldObserve,
};

@@ -110,5 +110,11 @@ }

const metric = config.metrics[phase];
if (!metric) {
return undefined;
}
let phases = availablePhases;
if (Array.isArray(metric) && metric.length === 0) {
if (isBucketsList(metric)) {
if (Array.isArray(metric)) {
if (metric.length === 0) {
throw TypeError(`Bad value provided for 'metrics.${phase.toString()}': the array must contain at least one element`);
}
else if (isBucketsList(metric)) {
histogram.buckets = metric;

@@ -128,7 +134,7 @@ }

}
if (!customMetric.shouldObserve) {
customMetric.shouldObserve = () => true;
}
return customMetric;
}
if (metric !== true) {
return undefined;
}
return createHistogram({

@@ -143,2 +149,3 @@ registry: config.registry || defaultRegistry,

phases,
shouldObserve: () => true,
});

@@ -151,5 +158,11 @@ }

const metric = config.metrics[phase];
if (!metric) {
return undefined;
}
let phases = availablePhases;
if (Array.isArray(metric)) {
if (isPhasesList(metric)) {
if (metric.length === 0) {
throw TypeError(`Bad value provided for 'metrics.${phase.toString()}': the array must contain at least one element`);
}
else if (isPhasesList(metric)) {
phases = filterAvailablePhases(metric, availablePhases);

@@ -166,7 +179,7 @@ }

}
if (!customMetric.shouldObserve) {
customMetric.shouldObserve = () => true;
}
return customMetric;
}
if (metric !== true) {
return undefined;
}
return createSummary({

@@ -181,2 +194,3 @@ registry: config.registry || defaultRegistry,

phases,
shouldObserve: () => true,
});

@@ -190,4 +204,10 @@ }

let phases = availablePhases;
if (!metric) {
return undefined;
}
if (Array.isArray(metric)) {
if (isPhasesList(metric)) {
if (metric.length === 0) {
throw TypeError(`Bad value provided for 'metrics.${phase.toString()}': the array must contain at least one element`);
}
else if (isPhasesList(metric)) {
phases = filterAvailablePhases(metric, availablePhases);

@@ -204,7 +224,7 @@ }

}
if (!customMetric.shouldObserve) {
customMetric.shouldObserve = () => true;
}
return customMetric;
}
if (metric !== true) {
return undefined;
}
return createCounter({

@@ -219,2 +239,3 @@ registry: config.registry || defaultRegistry,

phases,
shouldObserve: () => true,
});

@@ -281,3 +302,3 @@ }

function filterAvailablePhases(phases, availablePhases) {
return phases.filter(phase => availablePhases.includes(phase));
return availablePhases.filter(phase => phases.includes(phase));
}
{
"name": "@envelop/prometheus",
"version": "12.0.0-alpha-20241119110638-78ea8d1b8abb6ba89f9a443e4742e9c43bb1b145",
"version": "12.0.0-alpha-20241121114839-bf3487aac3c9d6ab1a346b04280cbff55df83ca1",
"sideEffects": false,

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

import { Registry } from 'prom-client';
import { createCounter, createHistogram, createSummary, type AtLeastOne } from './utils.js';
import { createCounter, createHistogram, createSummary, type AtLeastOne, type FillLabelsFnParams } from './utils.js';
export type PrometheusTracingPluginConfig = {

@@ -51,3 +51,3 @@ /**

*/
graphql_envelop_request?: CounterMetricOption<AtLeastOne<'execute' | 'subscribe'>>;
graphql_envelop_request?: CounterMetricOption<'execute' | 'subscribe'>;
/**

@@ -64,3 +64,3 @@ * Tracks the duration of the complete GraphQL operation execution.

*/
graphql_envelop_request_duration?: HistogramMetricOption<AtLeastOne<'execute' | 'subscribe'>>;
graphql_envelop_request_duration?: HistogramMetricOption<'execute' | 'subscribe'>;
/**

@@ -76,3 +76,3 @@ * Provides a summary of the time spent on the GraphQL operation execution.

*/
graphql_envelop_request_time_summary?: SummaryMetricOption<AtLeastOne<'execute' | 'subscribe'>>;
graphql_envelop_request_time_summary?: SummaryMetricOption<'execute' | 'subscribe'>;
/**

@@ -90,3 +90,3 @@ * Tracks the duration of the parse phase of the GraphQL execution.

*/
graphql_envelop_phase_parse?: HistogramMetricOption<['parse']>;
graphql_envelop_phase_parse?: HistogramMetricOption<'parse'>;
/**

@@ -104,3 +104,3 @@ * Tracks the duration of the validate phase of the GraphQL execution.

*/
graphql_envelop_phase_validate?: HistogramMetricOption<['validate']>;
graphql_envelop_phase_validate?: HistogramMetricOption<'validate'>;
/**

@@ -118,3 +118,3 @@ * Tracks the duration of the context phase of the GraphQL execution.

*/
graphql_envelop_phase_context?: HistogramMetricOption<['context']>;
graphql_envelop_phase_context?: HistogramMetricOption<'context'>;
/**

@@ -133,3 +133,3 @@ * Tracks the duration of the execute phase of the GraphQL execution.

*/
graphql_envelop_phase_execute?: HistogramMetricOption<['execute']>;
graphql_envelop_phase_execute?: HistogramMetricOption<'execute'>;
/**

@@ -147,3 +147,3 @@ * This metric tracks the duration of the subscribe phase of the GraphQL execution.

*/
graphql_envelop_phase_subscribe?: HistogramMetricOption<['subscribe']>;
graphql_envelop_phase_subscribe?: HistogramMetricOption<'subscribe'>;
/**

@@ -161,3 +161,3 @@ * This metric tracks the number of errors that returned by the GraphQL execution.

*/
graphql_envelop_error_result?: CounterMetricOption<AtLeastOne<'parse' | 'validate' | 'context' | 'execute' | 'subscribe'>>;
graphql_envelop_error_result?: CounterMetricOption<'parse' | 'validate' | 'context' | 'execute' | 'subscribe'>;
/**

@@ -173,3 +173,3 @@ * This metric tracks the number of deprecated fields used in the GraphQL operation.

*/
graphql_envelop_deprecated_field?: CounterMetricOption<['parse']>;
graphql_envelop_deprecated_field?: CounterMetricOption<'parse'>;
/**

@@ -188,3 +188,3 @@ * This metric tracks the number of schema changes that have occurred since the gateway started.

*/
graphql_envelop_schema_change?: CounterMetricOption<['schema']>;
graphql_envelop_schema_change?: CounterMetricOption<'schema'>;
/**

@@ -204,3 +204,3 @@ * This metric tracks the duration of each resolver execution.

*/
graphql_envelop_execute_resolver?: HistogramMetricOption<AtLeastOne<'subscribe' | 'execute'>>;
graphql_envelop_execute_resolver?: HistogramMetricOption<'subscribe' | 'execute'>;
};

@@ -249,5 +249,5 @@ export type LabelsConfig = {

};
export type HistogramMetricOption<Phases extends string[], LabelNames extends string = string> = boolean | string | BucketsConfig | Phases | ReturnType<typeof createHistogram<Phases, LabelNames>>;
export type HistogramMetricOption<Phases, LabelNames extends string = string, Params extends Record<string, unknown> = FillLabelsFnParams> = boolean | string | BucketsConfig | AtLeastOne<Phases> | ReturnType<typeof createHistogram<Phases, LabelNames, Params>>;
export type BucketsConfig = AtLeastOne<number>;
export type CounterMetricOption<Phases extends string[], LabelNames extends string = string> = boolean | string | Phases | ReturnType<typeof createCounter<Phases, LabelNames>>;
export type SummaryMetricOption<Phases extends string[], LabelNames extends string = string> = boolean | string | Phases | ReturnType<typeof createSummary<Phases, LabelNames>>;
export type CounterMetricOption<Phases, LabelNames extends string = string, Params extends Record<string, unknown> = FillLabelsFnParams> = boolean | string | AtLeastOne<Phases> | ReturnType<typeof createCounter<Phases, LabelNames, Params>>;
export type SummaryMetricOption<Phases, LabelNames extends string = string, Params extends Record<string, unknown> = FillLabelsFnParams> = boolean | string | AtLeastOne<Phases> | ReturnType<typeof createSummary<Phases, LabelNames, Params>>;

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

export type ShouldObservePredicate<Params extends Record<string, any>> = (params: Params, rawContext: any) => boolean;
export type HistogramAndLabels<Phases extends string[], LabelNames extends string, Params extends Record<string, any>> = {
export type HistogramAndLabels<Phases, LabelNames extends string, Params extends Record<string, any>> = {
histogram: Histogram<LabelNames>;
fillLabelsFn: FillLabelsFn<LabelNames, Params>;
phases?: Phases;
phases?: AtLeastOne<Phases>;
shouldObserve?: ShouldObservePredicate<Params>;

@@ -35,3 +35,3 @@ };

*/
export declare function createHistogram<Phases extends string[], LabelNames extends string, Params extends Record<string, any> = FillLabelsFnParams>(options: {
export declare function createHistogram<Phases, LabelNames extends string, Params extends Record<string, any> = FillLabelsFnParams>(options: {
/**

@@ -58,3 +58,3 @@ * The registry to be used by the plugin. If you don't have a custom registry,

*/
phases?: Phases;
phases?: AtLeastOne<Phases>;
/**

@@ -68,6 +68,6 @@ * A function called for each event that can be observed.

}): HistogramAndLabels<Phases, LabelNames, Params>;
export type SummaryAndLabels<Phases extends string[], LabelNames extends string, Params extends Record<string, any>> = {
export type SummaryAndLabels<Phases, LabelNames extends string, Params extends Record<string, any>> = {
summary: Summary<LabelNames>;
fillLabelsFn: FillLabelsFn<LabelNames, Params>;
phases?: Phases;
phases?: AtLeastOne<Phases>;
shouldObserve?: ShouldObservePredicate<Params>;

@@ -81,3 +81,3 @@ };

*/
export declare function createSummary<Phases extends string[], LabelNames extends string, Params extends Record<string, any> = FillLabelsFnParams>(options: {
export declare function createSummary<Phases, LabelNames extends string, Params extends Record<string, any> = FillLabelsFnParams>(options: {
/**

@@ -104,3 +104,3 @@ * The registry to be used by the plugin. If you don't have a custom registry,

*/
phases?: Phases;
phases?: AtLeastOne<Phases>;
/**

@@ -114,6 +114,6 @@ * A function called for each event that can be observed.

}): SummaryAndLabels<Phases, LabelNames, Params>;
export type CounterAndLabels<Phases extends string[], LabelNames extends string, Params extends Record<string, any>> = {
export type CounterAndLabels<Phases, LabelNames extends string, Params extends Record<string, any>> = {
counter: Counter<LabelNames>;
fillLabelsFn: FillLabelsFn<LabelNames, Params>;
phases?: Phases;
phases?: AtLeastOne<Phases>;
shouldObserve?: ShouldObservePredicate<Params>;

@@ -127,3 +127,3 @@ };

export declare function registerCounter<LabelNames extends string>(registry: Registry, conf: Omit<CounterConfiguration<LabelNames>, 'registers'>): Counter<LabelNames>;
export declare function createCounter<Phases extends string[], LabelNames extends string, Params extends Record<string, any> = FillLabelsFnParams>(options: {
export declare function createCounter<Phases, LabelNames extends string, Params extends Record<string, any> = FillLabelsFnParams>(options: {
/**

@@ -150,3 +150,3 @@ * The registry to be used by the plugin. If you don't have a custom registry,

*/
phases?: Phases;
phases?: AtLeastOne<Phases>;
/**

@@ -160,5 +160,5 @@ * A function called for each event that can be observed.

}): CounterAndLabels<Phases, LabelNames, Params>;
export declare function getHistogramFromConfig<Phases extends string[], MetricOptions, Params extends Record<string, any> = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof MetricOptions, availablePhases: Phases, histogram: Omit<HistogramConfiguration<string>, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn<string, Params>): HistogramAndLabels<Phases, string, Params> | undefined;
export declare function getSummaryFromConfig<Phases extends string[], MetricOptions, Params extends Record<string, any> = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof MetricOptions, availablePhases: Phases, summary: Omit<SummaryConfiguration<string>, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn<string, Params>): SummaryAndLabels<Phases, string, Params> | undefined;
export declare function getCounterFromConfig<Phases extends string[], MetricOptions, Params extends Record<string, any> = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof MetricOptions, availablePhases: Phases, counter: Omit<CounterConfiguration<string>, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn<string, Params>): CounterAndLabels<Phases, string, Params> | undefined;
export declare function getHistogramFromConfig<Phases, MetricOptions, Params extends Record<string, any> = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof MetricOptions, availablePhases: AtLeastOne<Phases>, histogram: Omit<HistogramConfiguration<string>, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn<string, Params>): Required<HistogramAndLabels<Phases, string, Params>> | undefined;
export declare function getSummaryFromConfig<Phases, MetricOptions, Params extends Record<string, any> = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof MetricOptions, availablePhases: AtLeastOne<Phases>, summary: Omit<SummaryConfiguration<string>, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn<string, Params>): Required<SummaryAndLabels<Phases, string, Params>> | undefined;
export declare function getCounterFromConfig<Phases, MetricOptions, Params extends Record<string, any> = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof MetricOptions, availablePhases: AtLeastOne<Phases>, counter: Omit<CounterConfiguration<string>, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn<string, Params>): Required<CounterAndLabels<Phases, string, Params>> | undefined;
export declare function extractDeprecatedFields(node: ASTNode, typeInfo: TypeInfo): DeprecatedFieldInfo[];

@@ -165,0 +165,0 @@ export declare function labelExists(config: {

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