@@ -238,65 +238,6 @@ def cloud_function(functionhandler, event):
238238 assert envelope_items [0 ]["tags" ]["cloud_function" ] == "true"
239239
240240
241- def test_performance_no_error (run_cloud_function ):
242- envelope_items , _ , _ = run_cloud_function (
243- dedent (
244- """
245- functionhandler = None
246- event = {}
247- def cloud_function(functionhandler, event):
248- return "test_string"
249- """
250- )
251- + FUNCTIONS_PRELUDE
252- + dedent (
253- """
254- init_sdk(traces_sample_rate=1.0)
255- gcp_functions.worker_v1.FunctionHandler.invoke_user_function(functionhandler, event)
256- """
257- )
258- )
259-
260- assert envelope_items [0 ]["type" ] == "transaction"
261- assert envelope_items [0 ]["contexts" ]["trace" ]["op" ] == "function.gcp"
262- assert envelope_items [0 ]["transaction" ].startswith ("Google Cloud function" )
263- assert envelope_items [0 ]["transaction_info" ] == {"source" : "component" }
264- assert envelope_items [0 ]["transaction" ] in envelope_items [0 ]["request" ]["url" ]
265-
266-
267- def test_performance_error (run_cloud_function ):
268- envelope_items , _ , _ = run_cloud_function (
269- dedent (
270- """
271- functionhandler = None
272- event = {}
273- def cloud_function(functionhandler, event):
274- raise Exception("something went wrong")
275- """
276- )
277- + FUNCTIONS_PRELUDE
278- + dedent (
279- """
280- init_sdk(traces_sample_rate=1.0)
281- gcp_functions.worker_v1.FunctionHandler.invoke_user_function(functionhandler, event)
282- """
283- )
284- )
285-
286- assert envelope_items [0 ]["level" ] == "error"
287- (exception ,) = envelope_items [0 ]["exception" ]["values" ]
288-
289- assert exception ["type" ] == "Exception"
290- assert exception ["value" ] == "something went wrong"
291- assert exception ["mechanism" ]["type" ] == "gcp"
292- assert not exception ["mechanism" ]["handled" ]
293-
294- assert envelope_items [1 ]["type" ] == "transaction"
295- assert envelope_items [1 ]["contexts" ]["trace" ]["op" ] == "function.gcp"
296- assert envelope_items [1 ]["transaction" ].startswith ("Google Cloud function" )
297- assert envelope_items [1 ]["transaction" ] in envelope_items [0 ]["request" ]["url" ]
298-
299-
300241def test_traces_sampler_gets_correct_values_in_sampling_context (
301242 run_cloud_function ,
302243 DictionaryContaining , # noqa:N803
@@ -367,6 +308,7 @@ def _safe_is_equal(x, y):
367308
368309 init_sdk(
369310 traces_sampler=traces_sampler,
311+ trace_lifecycle="stream",
370312 )
371313
372314 gcp_functions.worker_v1.FunctionHandler.invoke_user_function(functionhandler, event)
@@ -379,9 +321,9 @@ def _safe_is_equal(x, y):
379321
380322def test_error_has_new_trace_context_performance_enabled (run_cloud_function ):
381323 """
382- Check if an 'trace' context is added to errros and transactions when performance monitoring is enabled.
324+ Check if a 'trace' context is added to errors and spans when performance monitoring is enabled.
383325 """
384- envelope_items , _ , _ = run_cloud_function (
326+ envelope_items , _ , span_items = run_cloud_function (
385327 dedent (
386328 """
387329 functionhandler = None
@@ -395,26 +337,26 @@ def cloud_function(functionhandler, event):
395337 + FUNCTIONS_PRELUDE
396338 + dedent (
397339 """
398- init_sdk(traces_sample_rate=1.0)
340+ init_sdk(traces_sample_rate=1.0, trace_lifecycle="stream" )
399341 gcp_functions.worker_v1.FunctionHandler.invoke_user_function(functionhandler, event)
400342 """
401343 )
402344 )
403- (msg_event , error_event , transaction_event ) = envelope_items
345+ (msg_event , error_event ) = envelope_items
404346
405347 assert "trace" in msg_event ["contexts" ]
406348 assert "trace_id" in msg_event ["contexts" ]["trace" ]
407349
408350 assert "trace" in error_event ["contexts" ]
409351 assert "trace_id" in error_event ["contexts" ]["trace" ]
410352
411- assert "trace" in transaction_event [ "contexts" ]
412- assert "trace_id" in transaction_event [ "contexts" ][ "trace" ]
353+ assert len ( span_items ) == 1
354+ segment_span = span_items [ 0 ]
413355
414356 assert (
415357 msg_event ["contexts" ]["trace" ]["trace_id" ]
416358 == error_event ["contexts" ]["trace" ]["trace_id" ]
417- == transaction_event [ "contexts" ][ "trace" ] ["trace_id" ]
359+ == segment_span ["trace_id" ]
418360 )
419361
420362
@@ -456,59 +398,6 @@ def cloud_function(functionhandler, event):
456398 )
457399
458400
459- def test_error_has_existing_trace_context_performance_enabled (run_cloud_function ):
460- """
461- Check if an 'trace' context is added to errros and transactions
462- from the incoming 'sentry-trace' header when performance monitoring is enabled.
463- """
464- trace_id = "471a43a4192642f0b136d5159a501701"
465- parent_span_id = "6e8f22c393e68f19"
466- parent_sampled = 1
467- sentry_trace_header = "{}-{}-{}" .format (trace_id , parent_span_id , parent_sampled )
468-
469- envelope_items , _ , _ = run_cloud_function (
470- dedent (
471- """
472- functionhandler = None
473-
474- from collections import namedtuple
475- GCPEvent = namedtuple("GCPEvent", ["headers"])
476- event = GCPEvent(headers={"sentry-trace": "%s"})
477-
478- def cloud_function(functionhandler, event):
479- sentry_sdk.capture_message("hi")
480- x = 3/0
481- return "3"
482- """
483- % sentry_trace_header
484- )
485- + FUNCTIONS_PRELUDE
486- + dedent (
487- """
488- init_sdk(traces_sample_rate=1.0)
489- gcp_functions.worker_v1.FunctionHandler.invoke_user_function(functionhandler, event)
490- """
491- )
492- )
493- (msg_event , error_event , transaction_event ) = envelope_items
494-
495- assert "trace" in msg_event ["contexts" ]
496- assert "trace_id" in msg_event ["contexts" ]["trace" ]
497-
498- assert "trace" in error_event ["contexts" ]
499- assert "trace_id" in error_event ["contexts" ]["trace" ]
500-
501- assert "trace" in transaction_event ["contexts" ]
502- assert "trace_id" in transaction_event ["contexts" ]["trace" ]
503-
504- assert (
505- msg_event ["contexts" ]["trace" ]["trace_id" ]
506- == error_event ["contexts" ]["trace" ]["trace_id" ]
507- == transaction_event ["contexts" ]["trace" ]["trace_id" ]
508- == "471a43a4192642f0b136d5159a501701"
509- )
510-
511-
512401def test_error_has_existing_trace_context_performance_disabled (run_cloud_function ):
513402 """
514403 Check if an 'trace' context is added to errros and transactions
@@ -559,7 +448,7 @@ def cloud_function(functionhandler, event):
559448
560449
561450def test_span_origin (run_cloud_function ):
562- events , _ , _ = run_cloud_function (
451+ _ , _ , span_items = run_cloud_function (
563452 dedent (
564453 """
565454 functionhandler = None
@@ -571,18 +460,17 @@ def cloud_function(functionhandler, event):
571460 + FUNCTIONS_PRELUDE
572461 + dedent (
573462 """
574- init_sdk(traces_sample_rate=1.0)
463+ init_sdk(traces_sample_rate=1.0, trace_lifecycle="stream" )
575464 gcp_functions.worker_v1.FunctionHandler.invoke_user_function(functionhandler, event)
576465 """
577466 )
578467 )
579468
580- (event ,) = events
581-
582- assert event ["contexts" ]["trace" ]["origin" ] == "auto.function.gcp"
469+ assert len (span_items ) == 1
470+ assert span_items [0 ]["attributes" ]["sentry.origin" ] == "auto.function.gcp"
583471
584472
585- def test_span_streaming_no_error (run_cloud_function ):
473+ def test_performance_no_error (run_cloud_function ):
586474 _ , _ , span_items = run_cloud_function (
587475 dedent (
588476 """
@@ -616,7 +504,7 @@ def cloud_function(functionhandler, event):
616504 assert segment_span ["attributes" ]["faas.entry_point" ] == "cloud_function"
617505
618506
619- def test_span_streaming_error (run_cloud_function ):
507+ def test_performance_error (run_cloud_function ):
620508 envelope_items , _ , span_items = run_cloud_function (
621509 dedent (
622510 """
@@ -657,7 +545,7 @@ def cloud_function(functionhandler, event):
657545 assert segment_span ["status" ] == SpanStatus .ERROR
658546
659547
660- def test_span_streaming_existing_trace_context (run_cloud_function ):
548+ def test_existing_trace_context (run_cloud_function ):
661549 trace_id = "471a43a4192642f0b136d5159a501701"
662550 parent_span_id = "6e8f22c393e68f19"
663551 parent_sampled = 1
@@ -705,7 +593,7 @@ def cloud_function(functionhandler, event):
705593 assert segment_span ["attributes" ]["faas.entry_point" ] == "cloud_function"
706594
707595
708- def test_span_streaming_request_attributes (run_cloud_function ):
596+ def test_request_attributes (run_cloud_function ):
709597 _ , _ , span_items = run_cloud_function (
710598 dedent (
711599 """
@@ -746,7 +634,7 @@ def cloud_function(functionhandler, event):
746634 assert attrs ["faas.entry_point" ] == "cloud_function"
747635
748636
749- def test_span_streaming_no_query_string_without_pii (run_cloud_function ):
637+ def test_no_query_string_without_pii (run_cloud_function ):
750638 _ , _ , span_items = run_cloud_function (
751639 dedent (
752640 """
@@ -863,53 +751,7 @@ def _build_init_kwargs(send_default_pii, data_collection):
863751 "send_default_pii, data_collection, expected_event, expected_span" ,
864752 _QUERY_STRING_DATA_COLLECTION_CASES ,
865753)
866- def test_query_string_data_collection_event_processor (
867- run_cloud_function ,
868- send_default_pii ,
869- data_collection ,
870- expected_event ,
871- expected_span ,
872- ):
873- init_kwargs = _build_init_kwargs (send_default_pii , data_collection )
874- envelope_items , _ , _ = run_cloud_function (
875- dedent (
876- """
877- functionhandler = None
878-
879- from collections import namedtuple
880- GCPEvent = namedtuple("GCPEvent", ["headers", "method", "query_string"])
881- event = GCPEvent(
882- headers={},
883- method="GET",
884- query_string=b"toy=tennisball&color=red&auth=secret",
885- )
886-
887- def cloud_function(functionhandler, event):
888- raise Exception("something went wrong")
889- """
890- )
891- + FUNCTIONS_PRELUDE
892- + dedent (
893- """
894- init_sdk(%s)
895- gcp_functions.worker_v1.FunctionHandler.invoke_user_function(functionhandler, event)
896- """
897- % init_kwargs
898- )
899- )
900-
901- request = envelope_items [0 ]["request" ]
902- if expected_event is None :
903- assert "query_string" not in request
904- else :
905- assert request ["query_string" ] == expected_event
906-
907-
908- @pytest .mark .parametrize (
909- "send_default_pii, data_collection, expected_event, expected_span" ,
910- _QUERY_STRING_DATA_COLLECTION_CASES ,
911- )
912- def test_query_string_data_collection_span_streaming (
754+ def test_query_string_data_collection (
913755 run_cloud_function ,
914756 send_default_pii ,
915757 data_collection ,
0 commit comments