@@ -94,8 +94,8 @@ def init_sdk(timeout_warning=False, **extra_init_args):
9494def run_cloud_function ():
9595 def inner (code , subprocess_kwargs = ()):
9696
97- event = []
98- envelope = []
97+ events = []
98+ envelopes = []
9999 return_value = None
100100
101101 # STEP : Create a zip of cloud function
@@ -133,10 +133,10 @@ def inner(code, subprocess_kwargs=()):
133133 print ("GCP:" , line )
134134 if line .startswith ("EVENT: " ):
135135 line = line [len ("EVENT: " ) :]
136- event = json .loads (line )
136+ events . append ( json .loads (line ) )
137137 elif line .startswith ("ENVELOPE: " ):
138138 line = line [len ("ENVELOPE: " ) :]
139- envelope = json .loads (line )
139+ envelopes . append ( json .loads (line ) )
140140 elif line .startswith ("RETURN VALUE: " ):
141141 line = line [len ("RETURN VALUE: " ) :]
142142 return_value = json .loads (line )
@@ -145,13 +145,13 @@ def inner(code, subprocess_kwargs=()):
145145
146146 stream .close ()
147147
148- return envelope , event , return_value
148+ return envelopes , events , return_value
149149
150150 return inner
151151
152152
153153def test_handled_exception (run_cloud_function ):
154- envelope , event , return_value = run_cloud_function (
154+ _ , events , return_value = run_cloud_function (
155155 dedent (
156156 """
157157 functionhandler = None
@@ -168,16 +168,16 @@ def cloud_function(functionhandler, event):
168168 """
169169 )
170170 )
171- assert event ["level" ] == "error"
172- (exception ,) = event ["exception" ]["values" ]
171+ assert events [ 0 ] ["level" ] == "error"
172+ (exception ,) = events [ 0 ] ["exception" ]["values" ]
173173
174174 assert exception ["type" ] == "Exception"
175175 assert exception ["value" ] == "something went wrong"
176176 assert exception ["mechanism" ] == {"type" : "gcp" , "handled" : False }
177177
178178
179179def test_unhandled_exception (run_cloud_function ):
180- envelope , event , return_value = run_cloud_function (
180+ _ , events , _ = run_cloud_function (
181181 dedent (
182182 """
183183 functionhandler = None
@@ -195,16 +195,16 @@ def cloud_function(functionhandler, event):
195195 """
196196 )
197197 )
198- assert event ["level" ] == "error"
199- (exception ,) = event ["exception" ]["values" ]
198+ assert events [ 0 ] ["level" ] == "error"
199+ (exception ,) = events [ 0 ] ["exception" ]["values" ]
200200
201201 assert exception ["type" ] == "ZeroDivisionError"
202202 assert exception ["value" ] == "division by zero"
203203 assert exception ["mechanism" ] == {"type" : "gcp" , "handled" : False }
204204
205205
206206def test_timeout_error (run_cloud_function ):
207- envelope , event , return_value = run_cloud_function (
207+ _ , events , _ = run_cloud_function (
208208 dedent (
209209 """
210210 functionhandler = None
@@ -222,8 +222,8 @@ def cloud_function(functionhandler, event):
222222 """
223223 )
224224 )
225- assert event ["level" ] == "error"
226- (exception ,) = event ["exception" ]["values" ]
225+ assert events [ 0 ] ["level" ] == "error"
226+ (exception ,) = events [ 0 ] ["exception" ]["values" ]
227227
228228 assert exception ["type" ] == "ServerlessTimeoutWarning"
229229 assert (
@@ -234,7 +234,7 @@ def cloud_function(functionhandler, event):
234234
235235
236236def test_performance_no_error (run_cloud_function ):
237- envelope , event , return_value = run_cloud_function (
237+ envelopes , _ , _ = run_cloud_function (
238238 dedent (
239239 """
240240 functionhandler = None
@@ -252,15 +252,15 @@ def cloud_function(functionhandler, event):
252252 )
253253 )
254254
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" ]
260260
261261
262262def test_performance_error (run_cloud_function ):
263- envelope , event , return_value = run_cloud_function (
263+ envelopes , events , _ = run_cloud_function (
264264 dedent (
265265 """
266266 functionhandler = None
@@ -278,17 +278,18 @@ def cloud_function(functionhandler, event):
278278 )
279279 )
280280
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" ]
287283
288284 assert exception ["type" ] == "Exception"
289285 assert exception ["value" ] == "something went wrong"
290286 assert exception ["mechanism" ] == {"type" : "gcp" , "handled" : False }
291287
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+
292293
293294def test_traces_sampler_gets_correct_values_in_sampling_context (
294295 run_cloud_function , DictionaryContaining # noqa:N803
0 commit comments