File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -591,6 +591,28 @@ def test_sync_client_propagates_ambient_context_without_lifecycle_spans(
591591 assert [span .name for span in otel_setup .get_finished_spans ()] == [
592592 "host-request" ]
593593
594+ def test_sync_client_schedule_new_orchestration_matches_span_instance_id_when_auto_generated (
595+ self , otel_setup : InMemorySpanExporter ):
596+ """When instance_id is omitted, request.instanceId must match the producer span instance ID."""
597+ stub = MagicMock ()
598+ stub .StartInstance .side_effect = lambda req : pb .CreateInstanceResponse (instanceId = req .instanceId )
599+ with patch (
600+ "durabletask.client.stubs.TaskHubSidecarServiceStub" ,
601+ return_value = stub ):
602+ grpc_client = client .TaskHubGrpcClient (channel = MagicMock (), emit_trace_spans = True )
603+
604+ returned_instance_id = grpc_client .schedule_new_orchestration ("MyOrchestrator" )
605+
606+ start_request = stub .StartInstance .call_args .args [0 ]
607+ assert start_request .instanceId == returned_instance_id
608+ assert start_request .instanceId != ""
609+
610+ spans = otel_setup .get_finished_spans ()
611+ create_spans = [s for s in spans if s .name == "create_orchestration:MyOrchestrator" ]
612+ assert len (create_spans ) == 1
613+ assert create_spans [0 ].attributes [tracing .ATTR_TASK_INSTANCE_ID ] == returned_instance_id
614+ assert create_spans [0 ].attributes [tracing .ATTR_TASK_INSTANCE_ID ] == start_request .instanceId
615+
594616 @pytest .mark .asyncio
595617 async def test_async_client_propagates_ambient_context_without_lifecycle_spans (
596618 self , otel_setup : InMemorySpanExporter ):
You can’t perform that action at this time.
0 commit comments