@envelop/prometheus 9.3.1 → 9.4.0-rc-20240313135943-9409a08d

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 CHANGED
@@ -14,17 +14,21 @@ exports.fillLabelsFnParamsMap = new WeakMap();
14
14
  exports.execStartTimeMap = new WeakMap();
15
15
  const usePrometheus = (config = {}) => {
16
16
  let typeInfo = null;
17
- const parseHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'parse', 'graphql_envelop_phase_parse', 'Time spent on running GraphQL "parse" function');
18
- const validateHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'validate', 'graphql_envelop_phase_validate', 'Time spent on running GraphQL "validate" function');
19
- const contextBuildingHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'contextBuilding', 'graphql_envelop_phase_context', 'Time spent on building the GraphQL context');
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');
17
+ const parseHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'parse', typeof config.parse === 'string' ? config.parse : 'graphql_envelop_phase_parse', 'Time spent on running GraphQL "parse" function');
18
+ const validateHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'validate', typeof config.validate === 'string' ? config.validate : 'graphql_envelop_phase_validate', 'Time spent on running GraphQL "validate" function');
19
+ const contextBuildingHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'contextBuilding', typeof config.contextBuilding === 'string'
20
+ ? config.contextBuilding
21
+ : 'graphql_envelop_phase_context', 'Time spent on building the GraphQL context');
22
+ const executeHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'execute', typeof config.execute === 'string' ? config.execute : 'graphql_envelop_phase_execute', 'Time spent on running the GraphQL "execute" function');
23
+ const subscribeHistogram = (0, utils_js_1.getHistogramFromConfig)(config, 'subscribe', typeof config.subscribe === 'string' ? config.subscribe : 'graphql_envelop_phase_subscribe', 'Time spent on running the GraphQL "subscribe" function');
22
24
  const resolversHistogram = typeof config.resolvers === 'object'
23
25
  ? config.resolvers
24
- : config.resolvers === true
26
+ : config.resolvers === true || typeof config.resolvers === 'string'
25
27
  ? (0, utils_js_1.createHistogram)({
26
28
  histogram: new prom_client_1.Histogram({
27
- name: 'graphql_envelop_execute_resolver',
29
+ name: typeof config.resolvers === 'string'
30
+ ? config.resolvers
31
+ : 'graphql_envelop_execute_resolver',
28
32
  help: 'Time spent on running the GraphQL resolvers',
29
33
  labelNames: [
30
34
  'operationType',
@@ -46,10 +50,12 @@ const usePrometheus = (config = {}) => {
46
50
  : undefined;
47
51
  const requestTotalHistogram = typeof config.requestTotalDuration === 'object'
48
52
  ? config.requestTotalDuration
49
- : config.requestTotalDuration === true
53
+ : config.requestTotalDuration === true || typeof config.requestTotalDuration === 'string'
50
54
  ? (0, utils_js_1.createHistogram)({
51
55
  histogram: new prom_client_1.Histogram({
52
- name: 'graphql_envelop_request_duration',
56
+ name: typeof config.requestTotalDuration === 'string'
57
+ ? config.requestTotalDuration
58
+ : 'graphql_envelop_request_duration',
53
59
  help: 'Time spent on running the GraphQL operation from parse to execute',
54
60
  labelNames: ['operationType', 'operationName'].filter(label => (0, utils_js_1.labelExists)(config, label)),
55
61
  registers: [config.registry || prom_client_1.register],
@@ -62,10 +68,12 @@ const usePrometheus = (config = {}) => {
62
68
  : undefined;
63
69
  const requestSummary = typeof config.requestSummary === 'object'
64
70
  ? config.requestSummary
65
- : config.requestSummary === true
71
+ : config.requestSummary === true || typeof config.requestSummary === 'string'
66
72
  ? (0, utils_js_1.createSummary)({
67
73
  summary: new prom_client_1.Summary({
68
- name: 'graphql_envelop_request_time_summary',
74
+ name: typeof config.requestSummary === 'string'
75
+ ? config.requestSummary
76
+ : 'graphql_envelop_request_time_summary',
69
77
  help: 'Summary to measure the time to complete GraphQL operations',
70
78
  labelNames: ['operationType', 'operationName'].filter(label => (0, utils_js_1.labelExists)(config, label)),
71
79
  registers: [config.registry || prom_client_1.register],
@@ -78,10 +86,10 @@ const usePrometheus = (config = {}) => {
78
86
  : undefined;
79
87
  const errorsCounter = typeof config.errors === 'object'
80
88
  ? config.errors
81
- : config.errors === true
89
+ : config.errors === true || typeof config.errors === 'string'
82
90
  ? (0, utils_js_1.createCounter)({
83
91
  counter: new prom_client_1.Counter({
84
- name: 'graphql_envelop_error_result',
92
+ name: typeof config.errors === 'string' ? config.errors : 'graphql_envelop_error_result',
85
93
  help: 'Counts the amount of errors reported from all phases',
86
94
  labelNames: ['operationType', 'operationName', 'path', 'phase'].filter(label => (0, utils_js_1.labelExists)(config, label)),
87
95
  registers: [config.registry || prom_client_1.register],
@@ -96,10 +104,12 @@ const usePrometheus = (config = {}) => {
96
104
  : undefined;
97
105
  const reqCounter = typeof config.requestCount === 'object'
98
106
  ? config.requestCount
99
- : config.requestCount === true
107
+ : config.requestCount === true || typeof config.requestCount === 'string'
100
108
  ? (0, utils_js_1.createCounter)({
101
109
  counter: new prom_client_1.Counter({
102
- name: 'graphql_envelop_request',
110
+ name: typeof config.requestCount === 'string'
111
+ ? config.requestCount
112
+ : 'graphql_envelop_request',
103
113
  help: 'Counts the amount of GraphQL requests executed through Envelop',
104
114
  labelNames: ['operationType', 'operationName'].filter(label => (0, utils_js_1.labelExists)(config, label)),
105
115
  registers: [config.registry || prom_client_1.register],
@@ -112,10 +122,12 @@ const usePrometheus = (config = {}) => {
112
122
  : undefined;
113
123
  const deprecationCounter = typeof config.deprecatedFields === 'object'
114
124
  ? config.deprecatedFields
115
- : config.deprecatedFields === true
125
+ : config.deprecatedFields === true || typeof config.deprecatedFields === 'string'
116
126
  ? (0, utils_js_1.createCounter)({
117
127
  counter: new prom_client_1.Counter({
118
- name: 'graphql_envelop_deprecated_field',
128
+ name: typeof config.deprecatedFields === 'string'
129
+ ? config.deprecatedFields
130
+ : 'graphql_envelop_deprecated_field',
119
131
  help: 'Counts the amount of deprecated fields used in selection sets',
120
132
  labelNames: ['operationType', 'operationName', 'fieldName', 'typeName'].filter(label => (0, utils_js_1.labelExists)(config, label)),
121
133
  registers: [config.registry || prom_client_1.register],
@@ -130,10 +142,12 @@ const usePrometheus = (config = {}) => {
130
142
  : undefined;
131
143
  const schemaChangeCounter = typeof config.schemaChangeCount === 'object'
132
144
  ? config.schemaChangeCount
133
- : config.schemaChangeCount === true
145
+ : config.schemaChangeCount === true || typeof config.schemaChangeCount === 'string'
134
146
  ? (0, utils_js_1.createCounter)({
135
147
  counter: new prom_client_1.Counter({
136
- name: 'graphql_envelop_schema_change',
148
+ name: typeof config.schemaChangeCount === 'string'
149
+ ? config.schemaChangeCount
150
+ : 'graphql_envelop_schema_change',
137
151
  help: 'Counts the amount of schema changes',
138
152
  registers: [config.registry || prom_client_1.register],
139
153
  }),
package/esm/index.js CHANGED
@@ -9,17 +9,21 @@ export const fillLabelsFnParamsMap = new WeakMap();
9
9
  export const execStartTimeMap = new WeakMap();
10
10
  export const usePrometheus = (config = {}) => {
11
11
  let typeInfo = null;
12
- const parseHistogram = getHistogramFromConfig(config, 'parse', 'graphql_envelop_phase_parse', 'Time spent on running GraphQL "parse" function');
13
- const validateHistogram = getHistogramFromConfig(config, 'validate', 'graphql_envelop_phase_validate', 'Time spent on running GraphQL "validate" function');
14
- const contextBuildingHistogram = getHistogramFromConfig(config, 'contextBuilding', 'graphql_envelop_phase_context', 'Time spent on building the GraphQL context');
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');
12
+ const parseHistogram = getHistogramFromConfig(config, 'parse', typeof config.parse === 'string' ? config.parse : 'graphql_envelop_phase_parse', 'Time spent on running GraphQL "parse" function');
13
+ const validateHistogram = getHistogramFromConfig(config, 'validate', typeof config.validate === 'string' ? config.validate : 'graphql_envelop_phase_validate', 'Time spent on running GraphQL "validate" function');
14
+ const contextBuildingHistogram = getHistogramFromConfig(config, 'contextBuilding', typeof config.contextBuilding === 'string'
15
+ ? config.contextBuilding
16
+ : 'graphql_envelop_phase_context', 'Time spent on building the GraphQL context');
17
+ const executeHistogram = getHistogramFromConfig(config, 'execute', typeof config.execute === 'string' ? config.execute : 'graphql_envelop_phase_execute', 'Time spent on running the GraphQL "execute" function');
18
+ const subscribeHistogram = getHistogramFromConfig(config, 'subscribe', typeof config.subscribe === 'string' ? config.subscribe : 'graphql_envelop_phase_subscribe', 'Time spent on running the GraphQL "subscribe" function');
17
19
  const resolversHistogram = typeof config.resolvers === 'object'
18
20
  ? config.resolvers
19
- : config.resolvers === true
21
+ : config.resolvers === true || typeof config.resolvers === 'string'
20
22
  ? createHistogram({
21
23
  histogram: new Histogram({
22
- name: 'graphql_envelop_execute_resolver',
24
+ name: typeof config.resolvers === 'string'
25
+ ? config.resolvers
26
+ : 'graphql_envelop_execute_resolver',
23
27
  help: 'Time spent on running the GraphQL resolvers',
24
28
  labelNames: [
25
29
  'operationType',
@@ -41,10 +45,12 @@ export const usePrometheus = (config = {}) => {
41
45
  : undefined;
42
46
  const requestTotalHistogram = typeof config.requestTotalDuration === 'object'
43
47
  ? config.requestTotalDuration
44
- : config.requestTotalDuration === true
48
+ : config.requestTotalDuration === true || typeof config.requestTotalDuration === 'string'
45
49
  ? createHistogram({
46
50
  histogram: new Histogram({
47
- name: 'graphql_envelop_request_duration',
51
+ name: typeof config.requestTotalDuration === 'string'
52
+ ? config.requestTotalDuration
53
+ : 'graphql_envelop_request_duration',
48
54
  help: 'Time spent on running the GraphQL operation from parse to execute',
49
55
  labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
50
56
  registers: [config.registry || defaultRegistry],
@@ -57,10 +63,12 @@ export const usePrometheus = (config = {}) => {
57
63
  : undefined;
58
64
  const requestSummary = typeof config.requestSummary === 'object'
59
65
  ? config.requestSummary
60
- : config.requestSummary === true
66
+ : config.requestSummary === true || typeof config.requestSummary === 'string'
61
67
  ? createSummary({
62
68
  summary: new Summary({
63
- name: 'graphql_envelop_request_time_summary',
69
+ name: typeof config.requestSummary === 'string'
70
+ ? config.requestSummary
71
+ : 'graphql_envelop_request_time_summary',
64
72
  help: 'Summary to measure the time to complete GraphQL operations',
65
73
  labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
66
74
  registers: [config.registry || defaultRegistry],
@@ -73,10 +81,10 @@ export const usePrometheus = (config = {}) => {
73
81
  : undefined;
74
82
  const errorsCounter = typeof config.errors === 'object'
75
83
  ? config.errors
76
- : config.errors === true
84
+ : config.errors === true || typeof config.errors === 'string'
77
85
  ? createCounter({
78
86
  counter: new Counter({
79
- name: 'graphql_envelop_error_result',
87
+ name: typeof config.errors === 'string' ? config.errors : 'graphql_envelop_error_result',
80
88
  help: 'Counts the amount of errors reported from all phases',
81
89
  labelNames: ['operationType', 'operationName', 'path', 'phase'].filter(label => labelExists(config, label)),
82
90
  registers: [config.registry || defaultRegistry],
@@ -91,10 +99,12 @@ export const usePrometheus = (config = {}) => {
91
99
  : undefined;
92
100
  const reqCounter = typeof config.requestCount === 'object'
93
101
  ? config.requestCount
94
- : config.requestCount === true
102
+ : config.requestCount === true || typeof config.requestCount === 'string'
95
103
  ? createCounter({
96
104
  counter: new Counter({
97
- name: 'graphql_envelop_request',
105
+ name: typeof config.requestCount === 'string'
106
+ ? config.requestCount
107
+ : 'graphql_envelop_request',
98
108
  help: 'Counts the amount of GraphQL requests executed through Envelop',
99
109
  labelNames: ['operationType', 'operationName'].filter(label => labelExists(config, label)),
100
110
  registers: [config.registry || defaultRegistry],
@@ -107,10 +117,12 @@ export const usePrometheus = (config = {}) => {
107
117
  : undefined;
108
118
  const deprecationCounter = typeof config.deprecatedFields === 'object'
109
119
  ? config.deprecatedFields
110
- : config.deprecatedFields === true
120
+ : config.deprecatedFields === true || typeof config.deprecatedFields === 'string'
111
121
  ? createCounter({
112
122
  counter: new Counter({
113
- name: 'graphql_envelop_deprecated_field',
123
+ name: typeof config.deprecatedFields === 'string'
124
+ ? config.deprecatedFields
125
+ : 'graphql_envelop_deprecated_field',
114
126
  help: 'Counts the amount of deprecated fields used in selection sets',
115
127
  labelNames: ['operationType', 'operationName', 'fieldName', 'typeName'].filter(label => labelExists(config, label)),
116
128
  registers: [config.registry || defaultRegistry],
@@ -125,10 +137,12 @@ export const usePrometheus = (config = {}) => {
125
137
  : undefined;
126
138
  const schemaChangeCounter = typeof config.schemaChangeCount === 'object'
127
139
  ? config.schemaChangeCount
128
- : config.schemaChangeCount === true
140
+ : config.schemaChangeCount === true || typeof config.schemaChangeCount === 'string'
129
141
  ? createCounter({
130
142
  counter: new Counter({
131
- name: 'graphql_envelop_schema_change',
143
+ name: typeof config.schemaChangeCount === 'string'
144
+ ? config.schemaChangeCount
145
+ : 'graphql_envelop_schema_change',
132
146
  help: 'Counts the amount of schema changes',
133
147
  registers: [config.registry || defaultRegistry],
134
148
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envelop/prometheus",
3
- "version": "9.3.1",
3
+ "version": "9.4.0-rc-20240313135943-9409a08d",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "@envelop/core": "^5.0.0",
@@ -1,21 +1,21 @@
1
1
  import { Registry } from 'prom-client';
2
2
  import { createCounter, createHistogram, createSummary } from './utils.cjs';
3
3
  export type PrometheusTracingPluginConfig = {
4
- requestCount?: boolean | ReturnType<typeof createCounter>;
5
- requestTotalDuration?: boolean | ReturnType<typeof createHistogram>;
6
- requestSummary?: boolean | ReturnType<typeof createSummary>;
7
- parse?: boolean | ReturnType<typeof createHistogram>;
8
- validate?: boolean | ReturnType<typeof createHistogram>;
9
- contextBuilding?: boolean | ReturnType<typeof createHistogram>;
10
- execute?: boolean | ReturnType<typeof createHistogram>;
11
- subscribe?: boolean | ReturnType<typeof createHistogram>;
12
- errors?: boolean | ReturnType<typeof createCounter>;
13
- resolvers?: boolean | ReturnType<typeof createHistogram>;
4
+ requestCount?: boolean | string | ReturnType<typeof createCounter>;
5
+ requestTotalDuration?: boolean | string | ReturnType<typeof createHistogram>;
6
+ requestSummary?: boolean | string | ReturnType<typeof createSummary>;
7
+ parse?: boolean | string | ReturnType<typeof createHistogram>;
8
+ validate?: boolean | string | ReturnType<typeof createHistogram>;
9
+ contextBuilding?: boolean | string | ReturnType<typeof createHistogram>;
10
+ execute?: boolean | string | ReturnType<typeof createHistogram>;
11
+ subscribe?: boolean | string | ReturnType<typeof createHistogram>;
12
+ errors?: boolean | string | ReturnType<typeof createCounter>;
13
+ resolvers?: boolean | string | ReturnType<typeof createHistogram>;
14
14
  resolversWhitelist?: string[];
15
- deprecatedFields?: boolean | ReturnType<typeof createCounter>;
15
+ deprecatedFields?: boolean | string | ReturnType<typeof createCounter>;
16
16
  registry?: Registry;
17
17
  skipIntrospection?: boolean;
18
- schemaChangeCount?: boolean | ReturnType<typeof createCounter>;
18
+ schemaChangeCount?: boolean | string | ReturnType<typeof createCounter>;
19
19
  labels?: {
20
20
  operationName?: boolean;
21
21
  operationType?: boolean;
@@ -1,21 +1,21 @@
1
1
  import { Registry } from 'prom-client';
2
2
  import { createCounter, createHistogram, createSummary } from './utils.js';
3
3
  export type PrometheusTracingPluginConfig = {
4
- requestCount?: boolean | ReturnType<typeof createCounter>;
5
- requestTotalDuration?: boolean | ReturnType<typeof createHistogram>;
6
- requestSummary?: boolean | ReturnType<typeof createSummary>;
7
- parse?: boolean | ReturnType<typeof createHistogram>;
8
- validate?: boolean | ReturnType<typeof createHistogram>;
9
- contextBuilding?: boolean | ReturnType<typeof createHistogram>;
10
- execute?: boolean | ReturnType<typeof createHistogram>;
11
- subscribe?: boolean | ReturnType<typeof createHistogram>;
12
- errors?: boolean | ReturnType<typeof createCounter>;
13
- resolvers?: boolean | ReturnType<typeof createHistogram>;
4
+ requestCount?: boolean | string | ReturnType<typeof createCounter>;
5
+ requestTotalDuration?: boolean | string | ReturnType<typeof createHistogram>;
6
+ requestSummary?: boolean | string | ReturnType<typeof createSummary>;
7
+ parse?: boolean | string | ReturnType<typeof createHistogram>;
8
+ validate?: boolean | string | ReturnType<typeof createHistogram>;
9
+ contextBuilding?: boolean | string | ReturnType<typeof createHistogram>;
10
+ execute?: boolean | string | ReturnType<typeof createHistogram>;
11
+ subscribe?: boolean | string | ReturnType<typeof createHistogram>;
12
+ errors?: boolean | string | ReturnType<typeof createCounter>;
13
+ resolvers?: boolean | string | ReturnType<typeof createHistogram>;
14
14
  resolversWhitelist?: string[];
15
- deprecatedFields?: boolean | ReturnType<typeof createCounter>;
15
+ deprecatedFields?: boolean | string | ReturnType<typeof createCounter>;
16
16
  registry?: Registry;
17
17
  skipIntrospection?: boolean;
18
- schemaChangeCount?: boolean | ReturnType<typeof createCounter>;
18
+ schemaChangeCount?: boolean | string | ReturnType<typeof createCounter>;
19
19
  labels?: {
20
20
  operationName?: boolean;
21
21
  operationType?: boolean;