@@ -22,7 +22,9 @@ import {
22
22
createSummary ,
23
23
extractDeprecatedFields ,
24
24
FillLabelsFnParams ,
25
+ filterFillParamsFnParams ,
25
26
getHistogramFromConfig ,
27
+ labelExists ,
26
28
shouldTraceFieldResolver ,
27
29
} from './utils.js' ;
28
30
@@ -71,18 +73,6 @@ export const usePrometheus = (config: PrometheusTracingPluginConfig = {}): Plugi
71
73
'Time spent on running the GraphQL "subscribe" function' ,
72
74
) ;
73
75
74
- function labelExists ( label : string ) {
75
- const labelFlag = config . labels ?. [ label ] ;
76
- if ( labelFlag == null ) {
77
- return true ;
78
- }
79
- return labelFlag ;
80
- }
81
-
82
- function filterFillParamsFnParams ( params : Record < string , any > ) {
83
- return Object . fromEntries ( Object . entries ( params ) . filter ( ( [ key ] ) => labelExists ( key ) ) ) ;
84
- }
85
-
86
76
const resolversHistogram =
87
77
typeof config . resolvers === 'object'
88
78
? config . resolvers
@@ -97,11 +87,11 @@ export const usePrometheus = (config: PrometheusTracingPluginConfig = {}): Plugi
97
87
'fieldName' ,
98
88
'typeName' ,
99
89
'returnType' ,
100
- ] . filter ( labelExists ) ,
90
+ ] . filter ( label => labelExists ( config , label ) ) ,
101
91
registers : [ config . registry || defaultRegistry ] ,
102
92
} ) ,
103
93
fillLabelsFn : params =>
104
- filterFillParamsFnParams ( {
94
+ filterFillParamsFnParams ( config , {
105
95
operationName : params . operationName ! ,
106
96
operationType : params . operationType ! ,
107
97
fieldName : params . info ?. fieldName ! ,
@@ -119,11 +109,13 @@ export const usePrometheus = (config: PrometheusTracingPluginConfig = {}): Plugi
119
109
histogram : new Histogram ( {
120
110
name : 'graphql_envelop_request_duration' ,
121
111
help : 'Time spent on running the GraphQL operation from parse to execute' ,
122
- labelNames : [ 'operationType' , 'operationName' ] . filter ( labelExists ) ,
112
+ labelNames : [ 'operationType' , 'operationName' ] . filter ( label =>
113
+ labelExists ( config , label ) ,
114
+ ) ,
123
115
registers : [ config . registry || defaultRegistry ] ,
124
116
} ) ,
125
117
fillLabelsFn : params =>
126
- filterFillParamsFnParams ( {
118
+ filterFillParamsFnParams ( config , {
127
119
operationName : params . operationName ! ,
128
120
operationType : params . operationType ! ,
129
121
} ) ,
@@ -138,11 +130,13 @@ export const usePrometheus = (config: PrometheusTracingPluginConfig = {}): Plugi
138
130
summary : new Summary ( {
139
131
name : 'graphql_envelop_request_time_summary' ,
140
132
help : 'Summary to measure the time to complete GraphQL operations' ,
141
- labelNames : [ 'operationType' , 'operationName' ] . filter ( labelExists ) ,
133
+ labelNames : [ 'operationType' , 'operationName' ] . filter ( label =>
134
+ labelExists ( config , label ) ,
135
+ ) ,
142
136
registers : [ config . registry || defaultRegistry ] ,
143
137
} ) ,
144
138
fillLabelsFn : params =>
145
- filterFillParamsFnParams ( {
139
+ filterFillParamsFnParams ( config , {
146
140
operationName : params . operationName ! ,
147
141
operationType : params . operationType ! ,
148
142
} ) ,
@@ -157,11 +151,13 @@ export const usePrometheus = (config: PrometheusTracingPluginConfig = {}): Plugi
157
151
counter : new Counter ( {
158
152
name : 'graphql_envelop_error_result' ,
159
153
help : 'Counts the amount of errors reported from all phases' ,
160
- labelNames : [ 'operationType' , 'operationName' , 'path' , 'phase' ] . filter ( labelExists ) ,
154
+ labelNames : [ 'operationType' , 'operationName' , 'path' , 'phase' ] . filter ( label =>
155
+ labelExists ( config , label ) ,
156
+ ) ,
161
157
registers : [ config . registry || defaultRegistry ] ,
162
158
} ) ,
163
159
fillLabelsFn : params =>
164
- filterFillParamsFnParams ( {
160
+ filterFillParamsFnParams ( config , {
165
161
operationName : params . operationName ! ,
166
162
operationType : params . operationType ! ,
167
163
path : params . error ?. path ?. join ( '.' ) ! ,
@@ -178,11 +174,13 @@ export const usePrometheus = (config: PrometheusTracingPluginConfig = {}): Plugi
178
174
counter : new Counter ( {
179
175
name : 'graphql_envelop_request' ,
180
176
help : 'Counts the amount of GraphQL requests executed through Envelop' ,
181
- labelNames : [ 'operationType' , 'operationName' ] . filter ( labelExists ) ,
177
+ labelNames : [ 'operationType' , 'operationName' ] . filter ( label =>
178
+ labelExists ( config , label ) ,
179
+ ) ,
182
180
registers : [ config . registry || defaultRegistry ] ,
183
181
} ) ,
184
182
fillLabelsFn : params =>
185
- filterFillParamsFnParams ( {
183
+ filterFillParamsFnParams ( config , {
186
184
operationName : params . operationName ! ,
187
185
operationType : params . operationType ! ,
188
186
} ) ,
@@ -197,13 +195,13 @@ export const usePrometheus = (config: PrometheusTracingPluginConfig = {}): Plugi
197
195
counter : new Counter ( {
198
196
name : 'graphql_envelop_deprecated_field' ,
199
197
help : 'Counts the amount of deprecated fields used in selection sets' ,
200
- labelNames : [ 'operationType' , 'operationName' , 'fieldName' , 'typeName' ] . filter (
201
- labelExists ,
198
+ labelNames : [ 'operationType' , 'operationName' , 'fieldName' , 'typeName' ] . filter ( label =>
199
+ labelExists ( config , label ) ,
202
200
) ,
203
201
registers : [ config . registry || defaultRegistry ] ,
204
202
} ) ,
205
203
fillLabelsFn : params =>
206
- filterFillParamsFnParams ( {
204
+ filterFillParamsFnParams ( config , {
207
205
operationName : params . operationName ! ,
208
206
operationType : params . operationType ! ,
209
207
fieldName : params . deprecationInfo ?. fieldName ! ,
@@ -237,10 +235,8 @@ export const usePrometheus = (config: PrometheusTracingPluginConfig = {}): Plugi
237
235
const totalTime = ( Date . now ( ) - startTime ) / 1000 ;
238
236
let fillLabelsFnParams = fillLabelsFnParamsMap . get ( params . result ) ;
239
237
if ( ! fillLabelsFnParams ) {
240
- fillLabelsFnParams = createFillLabelFnParams (
241
- params . result ,
242
- context ,
243
- filterFillParamsFnParams ,
238
+ fillLabelsFnParams = createFillLabelFnParams ( params . result , context , params =>
239
+ filterFillParamsFnParams ( config , params ) ,
244
240
) ;
245
241
fillLabelsFnParamsMap . set ( context , fillLabelsFnParams ) ;
246
242
}
0 commit comments