@@ -94,8 +94,8 @@ def init_sdk(timeout_warning=False, **extra_init_args):
94
94
def run_cloud_function ():
95
95
def inner (code , subprocess_kwargs = ()):
96
96
97
- event = []
98
- envelope = []
97
+ events = []
98
+ envelopes = []
99
99
return_value = None
100
100
101
101
# STEP : Create a zip of cloud function
@@ -133,10 +133,10 @@ def inner(code, subprocess_kwargs=()):
133
133
print ("GCP:" , line )
134
134
if line .startswith ("EVENT: " ):
135
135
line = line [len ("EVENT: " ) :]
136
- event = json .loads (line )
136
+ events . append ( json .loads (line ) )
137
137
elif line .startswith ("ENVELOPE: " ):
138
138
line = line [len ("ENVELOPE: " ) :]
139
- envelope = json .loads (line )
139
+ envelopes . append ( json .loads (line ) )
140
140
elif line .startswith ("RETURN VALUE: " ):
141
141
line = line [len ("RETURN VALUE: " ) :]
142
142
return_value = json .loads (line )
@@ -145,13 +145,13 @@ def inner(code, subprocess_kwargs=()):
145
145
146
146
stream .close ()
147
147
148
- return envelope , event , return_value
148
+ return envelopes , events , return_value
149
149
150
150
return inner
151
151
152
152
153
153
def test_handled_exception (run_cloud_function ):
154
- envelope , event , return_value = run_cloud_function (
154
+ _ , events , return_value = run_cloud_function (
155
155
dedent (
156
156
"""
157
157
functionhandler = None
@@ -168,16 +168,16 @@ def cloud_function(functionhandler, event):
168
168
"""
169
169
)
170
170
)
171
- assert event ["level" ] == "error"
172
- (exception ,) = event ["exception" ]["values" ]
171
+ assert events [ 0 ] ["level" ] == "error"
172
+ (exception ,) = events [ 0 ] ["exception" ]["values" ]
173
173
174
174
assert exception ["type" ] == "Exception"
175
175
assert exception ["value" ] == "something went wrong"
176
176
assert exception ["mechanism" ] == {"type" : "gcp" , "handled" : False }
177
177
178
178
179
179
def test_unhandled_exception (run_cloud_function ):
180
- envelope , event , return_value = run_cloud_function (
180
+ _ , events , _ = run_cloud_function (
181
181
dedent (
182
182
"""
183
183
functionhandler = None
@@ -195,16 +195,16 @@ def cloud_function(functionhandler, event):
195
195
"""
196
196
)
197
197
)
198
- assert event ["level" ] == "error"
199
- (exception ,) = event ["exception" ]["values" ]
198
+ assert events [ 0 ] ["level" ] == "error"
199
+ (exception ,) = events [ 0 ] ["exception" ]["values" ]
200
200
201
201
assert exception ["type" ] == "ZeroDivisionError"
202
202
assert exception ["value" ] == "division by zero"
203
203
assert exception ["mechanism" ] == {"type" : "gcp" , "handled" : False }
204
204
205
205
206
206
def test_timeout_error (run_cloud_function ):
207
- envelope , event , return_value = run_cloud_function (
207
+ _ , events , _ = run_cloud_function (
208
208
dedent (
209
209
"""
210
210
functionhandler = None
@@ -222,8 +222,8 @@ def cloud_function(functionhandler, event):
222
222
"""
223
223
)
224
224
)
225
- assert event ["level" ] == "error"
226
- (exception ,) = event ["exception" ]["values" ]
225
+ assert events [ 0 ] ["level" ] == "error"
226
+ (exception ,) = events [ 0 ] ["exception" ]["values" ]
227
227
228
228
assert exception ["type" ] == "ServerlessTimeoutWarning"
229
229
assert (
@@ -234,7 +234,7 @@ def cloud_function(functionhandler, event):
234
234
235
235
236
236
def test_performance_no_error (run_cloud_function ):
237
- envelope , event , return_value = run_cloud_function (
237
+ envelopes , _ , _ = run_cloud_function (
238
238
dedent (
239
239
"""
240
240
functionhandler = None
@@ -252,15 +252,15 @@ def cloud_function(functionhandler, event):
252
252
)
253
253
)
254
254
255
- assert envelope ["type" ] == "transaction"
256
- assert envelope ["contexts" ]["trace" ]["op" ] == "function.gcp"
257
- assert envelope ["transaction" ].startswith ("Google Cloud function" )
258
- assert envelope ["transaction_info" ] == {"source" : "component" }
259
- assert envelope [ "transaction" ] in envelope ["request" ]["url" ]
255
+ assert envelopes [ 0 ] ["type" ] == "transaction"
256
+ assert envelopes [ 0 ] ["contexts" ]["trace" ]["op" ] == "function.gcp"
257
+ assert envelopes [ 0 ] ["transaction" ].startswith ("Google Cloud function" )
258
+ assert envelopes [ 0 ] ["transaction_info" ] == {"source" : "component" }
259
+ assert envelopes [ 0 ][ "transaction" ] in envelopes [ 0 ] ["request" ]["url" ]
260
260
261
261
262
262
def test_performance_error (run_cloud_function ):
263
- envelope , event , return_value = run_cloud_function (
263
+ envelopes , events , _ = run_cloud_function (
264
264
dedent (
265
265
"""
266
266
functionhandler = None
@@ -278,17 +278,18 @@ def cloud_function(functionhandler, event):
278
278
)
279
279
)
280
280
281
- assert envelope ["type" ] == "transaction"
282
- assert envelope ["contexts" ]["trace" ]["op" ] == "function.gcp"
283
- assert envelope ["transaction" ].startswith ("Google Cloud function" )
284
- assert envelope ["transaction" ] in envelope ["request" ]["url" ]
285
- assert event ["level" ] == "error"
286
- (exception ,) = event ["exception" ]["values" ]
281
+ assert envelopes [0 ]["level" ] == "error"
282
+ (exception ,) = envelopes [0 ]["exception" ]["values" ]
287
283
288
284
assert exception ["type" ] == "Exception"
289
285
assert exception ["value" ] == "something went wrong"
290
286
assert exception ["mechanism" ] == {"type" : "gcp" , "handled" : False }
291
287
288
+ assert envelopes [1 ]["type" ] == "transaction"
289
+ assert envelopes [1 ]["contexts" ]["trace" ]["op" ] == "function.gcp"
290
+ assert envelopes [1 ]["transaction" ].startswith ("Google Cloud function" )
291
+ assert envelopes [1 ]["transaction" ] in envelopes [0 ]["request" ]["url" ]
292
+
292
293
293
294
def test_traces_sampler_gets_correct_values_in_sampling_context (
294
295
run_cloud_function , DictionaryContaining # noqa:N803
0 commit comments