Skip to content

Commit 622b1a4

Browse files
committed
test(tracing): verify async schedule_new_orchestration matches OTel span instance ID
Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
1 parent 25ca468 commit 622b1a4

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎tests/durabletask/test_tracing.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,29 @@ async def test_async_client_propagates_ambient_context_without_lifecycle_spans(
638638
assert [span.name for span in otel_setup.get_finished_spans()] == [
639639
"host-request"]
640640

641+
@pytest.mark.asyncio
642+
async def test_async_client_schedule_new_orchestration_matches_span_instance_id_when_auto_generated(
643+
self, otel_setup: InMemorySpanExporter):
644+
"""When instance_id is omitted, async request.instanceId must match the producer span instance ID."""
645+
stub = MagicMock()
646+
stub.StartInstance = AsyncMock(side_effect=lambda req: pb.CreateInstanceResponse(instanceId=req.instanceId))
647+
with patch(
648+
"durabletask.client.stubs.TaskHubSidecarServiceStub",
649+
return_value=stub):
650+
grpc_client = client.AsyncTaskHubGrpcClient(channel=MagicMock(), emit_trace_spans=True)
651+
652+
returned_instance_id = await grpc_client.schedule_new_orchestration("MyAsyncOrchestrator")
653+
654+
start_request = stub.StartInstance.call_args.args[0]
655+
assert start_request.instanceId == returned_instance_id
656+
assert start_request.instanceId != ""
657+
658+
spans = otel_setup.get_finished_spans()
659+
create_spans = [s for s in spans if s.name == "create_orchestration:MyAsyncOrchestrator"]
660+
assert len(create_spans) == 1
661+
assert create_spans[0].attributes[tracing.ATTR_TASK_INSTANCE_ID] == returned_instance_id
662+
assert create_spans[0].attributes[tracing.ATTR_TASK_INSTANCE_ID] == start_request.instanceId
663+
641664

642665
class TestOrchestrationServerSpan:
643666
"""Tests for emit_orchestration_span."""

0 commit comments

Comments
 (0)