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
1375
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 0.1.0 to 0.1.1-alpha-4c5b429.0

config.d.ts

40

index.d.ts
import { Plugin } from '@envelop/types';
import { DocumentNode, OperationDefinitionNode, GraphQLResolveInfo, GraphQLError } from 'graphql';
import { Counter, Histogram, Registry } from 'prom-client';
export declare type TracerOptions<Args> = {
name: string;
help?: string;
modifyReportLabels?: (args: Args, labels: Record<string, string>) => Record<string, string>[];
};
import { createHistogram, createCounter, FillLabelsFnParams } from './utils';
import { PrometheusTracingPluginConfig } from './config';
export { PrometheusTracingPluginConfig, createCounter, createHistogram, FillLabelsFnParams };
declare const promPluginContext: unique symbol;
export declare type FillLabelsFnParams = {
document: DocumentNode;
operationName: string;
operationType: OperationDefinitionNode['operation'];
info?: GraphQLResolveInfo;
errorPhase?: string;
error?: GraphQLError;
};
export declare function createHistogram<LabelNames extends string>(options: {
histogram: Histogram<LabelNames>;
fillLabelsFn?: (params: FillLabelsFnParams) => Record<LabelNames, string>;
}): typeof options;
export declare function createCounter<LabelNames extends string>(options: {
counter: Counter<LabelNames>;
fillLabelsFn?: (params: FillLabelsFnParams) => Record<LabelNames, string>;
}): typeof options;
export declare type PrometheusTracingPluginConfig = {
parse?: boolean | ReturnType<typeof createHistogram>;
validate?: boolean | ReturnType<typeof createHistogram>;
contextBuilding?: boolean | ReturnType<typeof createHistogram>;
execute?: boolean | ReturnType<typeof createHistogram>;
errors?: boolean | ReturnType<typeof createCounter>;
resolvers?: boolean | ReturnType<typeof createHistogram>;
resolversWhitelist?: string[];
deprecatedFields?: boolean | ReturnType<typeof createCounter>;
registry?: Registry;
};
declare type PluginInternalContext = {
[promPluginContext]: FillLabelsFnParams;
};
export declare const usePrometheus: (config: PrometheusTracingPluginConfig) => Plugin<PluginInternalContext>;
export {};
export declare const usePrometheus: (config?: PrometheusTracingPluginConfig) => Plugin<PluginInternalContext>;

@@ -7,3 +7,11 @@ 'use strict';

const promPluginContext = Symbol('promPluginContext');
function shouldTraceFieldResolver(info, whitelist) {
if (!whitelist) {
return true;
}
const parentType = info.parentType.name;
const fieldName = info.fieldName;
const coordinate = `${parentType}.${fieldName}`;
return whitelist.includes(coordinate) || whitelist.includes(`${parentType}.*`);
}
function getOperation(document) {

@@ -35,3 +43,3 @@ return document.definitions[0];

}
function getHistogram(config, phase, name, help) {
function getHistogramFromConfig(config, phase, name, help) {
return typeof config[phase] === 'object'

@@ -54,16 +62,9 @@ ? config[phase]

}
function shouldTraceFieldResolver(info, whitelist) {
if (!whitelist) {
return true;
}
const parentType = info.parentType.name;
const fieldName = info.fieldName;
const coordinate = `${parentType}.${fieldName}`;
return whitelist.includes(coordinate) || whitelist.includes(`${parentType}.*`);
}
const usePrometheus = (config) => {
const parseHistogram = getHistogram(config, 'parse', 'graphql_envelop_phase_parse', 'Time spent on running GraphQL "parse" function');
const validateHistogram = getHistogram(config, 'validate', 'graphql_envelop_phase_validate', 'Time spent on running GraphQL "validate" function');
const contextBuildingHistogram = getHistogram(config, 'contextBuilding', 'graphql_envelop_phase_context', 'Time spent on building the GraphQL context');
const executeHistogram = getHistogram(config, 'execute', 'graphql_envelop_phase_execute', 'Time spent on running the GraphQL "execute" function');
const promPluginContext = Symbol('promPluginContext');
const usePrometheus = (config = {}) => {
const parseHistogram = getHistogramFromConfig(config, 'parse', 'graphql_envelop_phase_parse', 'Time spent on running GraphQL "parse" function');
const validateHistogram = getHistogramFromConfig(config, 'validate', 'graphql_envelop_phase_validate', 'Time spent on running GraphQL "validate" function');
const contextBuildingHistogram = getHistogramFromConfig(config, 'contextBuilding', 'graphql_envelop_phase_context', 'Time spent on building the GraphQL context');
const executeHistogram = getHistogramFromConfig(config, 'execute', 'graphql_envelop_phase_execute', 'Time spent on running the GraphQL "execute" function');
const resolversHistogram = typeof config.resolvers === 'object'

@@ -70,0 +71,0 @@ ? config.resolvers

{
"name": "@envelop/prometheus",
"version": "0.1.0",
"version": "0.1.1-alpha-4c5b429.0",
"sideEffects": false,

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

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