Skip to content

Commit 25ca468

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

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎tests/durabletask/test_tracing.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff 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):

0 commit comments

Comments
 (0)