Skip to content

Commit 7ea9c0d

Browse files
sophiatevSophia Tevosyan
and
Sophia Tevosyan
authored
Distributed Tracing for Entities (Isolated) (#404)
* first commit! * one small proto change * fixed line endings, removed proto changes * trying to revert proto changes * line endings :( * one more time? * pushing what i have so far * seems like everything is working and aligned with the new in-process changes * a very small change to create a trace regardless of calling or signaling an entity from an orchestration * added a start time to OperationResult * missed one file * some stylistic updates per PR comments * super tiny style update * changed startTime/endTime to startTimeUtc/endTimeUtc and made the request times DateTimeOffset * first commit! (#436) Co-authored-by: Sophia Tevosyan <[email protected]> --------- Co-authored-by: Sophia Tevosyan <[email protected]>
1 parent 76afb96 commit 7ea9c0d

File tree

11 files changed

+130
-21
lines changed

11 files changed

+130
-21
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
<!-- DurableTask Packages -->
3030
<ItemGroup>
31-
<PackageVersion Include="Microsoft.Azure.DurableTask.Core" Version="3.1.0" />
31+
<PackageVersion Include="Microsoft.Azure.DurableTask.Core" Version="3.2.0" />
3232
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.2.2" />
3333
</ItemGroup>
3434

eng/targets/Release.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</PropertyGroup>
1818

1919
<PropertyGroup>
20-
<VersionPrefix>1.10.0</VersionPrefix>
20+
<VersionPrefix>1.11.0</VersionPrefix>
2121
<VersionSuffix></VersionSuffix>
2222
</PropertyGroup>
2323

src/Client/Grpc/GrpcDurableEntityClient.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
using System.Diagnostics;
45
using Microsoft.DurableTask.Client.Entities;
56
using Microsoft.DurableTask.Entities;
67
using Microsoft.Extensions.Logging;
@@ -54,8 +55,16 @@ public override async Task SignalEntityAsync(
5455
RequestId = requestId.ToString(),
5556
Name = operationName,
5657
Input = this.dataConverter.Serialize(input),
57-
ScheduledTime = scheduledTime?.ToTimestamp(),
58-
};
58+
ScheduledTime = scheduledTime?.ToTimestamp(),
59+
RequestTime = DateTimeOffset.UtcNow.ToTimestamp(),
60+
};
61+
62+
if (Activity.Current is { } activity)
63+
{
64+
request.ParentTraceContext ??= new P.TraceContext();
65+
request.ParentTraceContext.TraceParent = activity.Id;
66+
request.ParentTraceContext.TraceState = activity.TraceStateString;
67+
}
5968

6069
// TODO this.logger.LogSomething
6170
try

src/Client/Grpc/GrpcDurableTaskClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

44
using System.Diagnostics;
@@ -95,6 +95,7 @@ public override async Task<string> ScheduleNewOrchestrationInstanceAsync(
9595
Version = version,
9696
InstanceId = options?.InstanceId ?? Guid.NewGuid().ToString("N"),
9797
Input = this.DataConverter.Serialize(input),
98+
RequestTime = DateTimeOffset.UtcNow.ToTimestamp(),
9899
};
99100

100101
// Add tags to the collection

src/Client/OrchestrationServiceClientShim/ShimDurableEntityClient.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
using System.Diagnostics;
45
using DurableTask.Core;
5-
using DurableTask.Core.Entities;
6+
using DurableTask.Core.Entities;
7+
using DurableTask.Core.Tracing;
68
using Microsoft.DurableTask.Client.Entities;
79
using Microsoft.DurableTask.Entities;
810

@@ -90,7 +92,10 @@ public override async Task SignalEntityAsync(
9092
EntityMessageEvent.GetCappedScheduledTime(
9193
DateTime.UtcNow,
9294
this.options.Entities.MaxSignalDelayTimeOrDefault,
93-
scheduledTime?.UtcDateTime));
95+
scheduledTime?.UtcDateTime),
96+
Activity.Current is { } activity ? new DistributedTraceContext(activity.Id!, activity.TraceStateString) : null,
97+
requestTime: DateTimeOffset.UtcNow,
98+
createTrace: true);
9499

95100
await this.options.Client!.SendTaskOrchestrationMessageAsync(eventToSend.AsTaskMessage());
96101
}

src/Client/OrchestrationServiceClientShim/ShimDurableTaskClient.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
using System.Diagnostics;
45
using System.Diagnostics.CodeAnalysis;
6+
using System.Globalization;
57
using DurableTask.Core;
68
using DurableTask.Core.History;
79
using DurableTask.Core.Query;
@@ -166,6 +168,16 @@ public override async Task<string> ScheduleNewOrchestrationInstanceAsync(
166168
};
167169

168170
string? serializedInput = this.DataConverter.Serialize(input);
171+
172+
var tags = new Dictionary<string, string>();
173+
if (options?.Tags != null)
174+
{
175+
tags = options.Tags.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
176+
}
177+
178+
tags[OrchestrationTags.CreateTraceForNewOrchestration] = "true";
179+
tags[OrchestrationTags.RequestTime] = DateTimeOffset.UtcNow.ToString(CultureInfo.InvariantCulture);
180+
169181
TaskMessage message = new()
170182
{
171183
OrchestrationInstance = instance,
@@ -175,7 +187,8 @@ public override async Task<string> ScheduleNewOrchestrationInstanceAsync(
175187
Version = options?.Version ?? string.Empty,
176188
OrchestrationInstance = instance,
177189
ScheduledStartTime = options?.StartAt?.UtcDateTime,
178-
Tags = options?.Tags != null ? options.Tags.ToDictionary(kvp => kvp.Key, kvp => kvp.Value) : null,
190+
ParentTraceContext = Activity.Current is { } activity ? new Core.Tracing.DistributedTraceContext(activity.Id!, activity.TraceStateString) : null,
191+
Tags = tags,
179192
},
180193
};
181194

src/Grpc/orchestrator_service.proto

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ message TaskScheduledEvent {
9595
google.protobuf.StringValue version = 2;
9696
google.protobuf.StringValue input = 3;
9797
TraceContext parentTraceContext = 4;
98+
map<string, string> tags = 5;
9899
}
99100

100101
message TaskCompletedEvent {
@@ -256,6 +257,7 @@ message ScheduleTaskAction {
256257
string name = 1;
257258
google.protobuf.StringValue version = 2;
258259
google.protobuf.StringValue input = 3;
260+
map<string, string> tags = 4;
259261
}
260262

261263
message CreateSubOrchestrationAction {
@@ -343,6 +345,7 @@ message CreateInstanceRequest {
343345
google.protobuf.StringValue executionId = 7;
344346
map<string, string> tags = 8;
345347
TraceContext parentTraceContext = 9;
348+
google.protobuf.Timestamp requestTime = 10;
346349
}
347350

348351
message OrchestrationIdReusePolicy {
@@ -490,6 +493,8 @@ message SignalEntityRequest {
490493
google.protobuf.StringValue input = 3;
491494
string requestId = 4;
492495
google.protobuf.Timestamp scheduledTime = 5;
496+
TraceContext parentTraceContext = 6;
497+
google.protobuf.Timestamp requestTime = 7;
493498
}
494499

495500
message SignalEntityResponse {
@@ -575,6 +580,7 @@ message OperationRequest {
575580
string operation = 1;
576581
string requestId = 2;
577582
google.protobuf.StringValue input = 3;
583+
TraceContext traceContext = 4;
578584
}
579585

580586
message OperationResult {
@@ -591,10 +597,14 @@ message OperationInfo {
591597

592598
message OperationResultSuccess {
593599
google.protobuf.StringValue result = 1;
600+
google.protobuf.Timestamp startTimeUtc = 2;
601+
google.protobuf.Timestamp endTimeUtc = 3;
594602
}
595603

596604
message OperationResultFailure {
597605
TaskFailureDetails failureDetails = 1;
606+
google.protobuf.Timestamp startTimeUtc = 2;
607+
google.protobuf.Timestamp endTimeUtc = 3;
598608
}
599609

600610
message OperationAction {
@@ -610,6 +620,8 @@ message SendSignalAction {
610620
string name = 2;
611621
google.protobuf.StringValue input = 3;
612622
google.protobuf.Timestamp scheduledTime = 4;
623+
google.protobuf.Timestamp requestTime = 5;
624+
TraceContext parentTraceContext = 6;
613625
}
614626

615627
message StartNewOrchestrationAction {
@@ -618,6 +630,8 @@ message StartNewOrchestrationAction {
618630
google.protobuf.StringValue version = 3;
619631
google.protobuf.StringValue input = 4;
620632
google.protobuf.Timestamp scheduledTime = 5;
633+
google.protobuf.Timestamp requestTime = 6;
634+
TraceContext parentTraceContext = 7;
621635
}
622636

623637
message AbandonActivityTaskRequest {

src/Grpc/versions.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# The following files were downloaded from branch main at 2025-04-23 23:27:00 UTC
2-
https://raw.githubusercontent.com/microsoft/durabletask-protobuf/fbe5bb20835678099fc51a44993ed9b045dee5a6/protos/orchestrator_service.proto
1+
# The following files were downloaded from branch main at 2025-06-02 21:12:34 UTC
2+
https://raw.githubusercontent.com/microsoft/durabletask-protobuf/fd9369c6a03d6af4e95285e432b7c4e943c06970/protos/orchestrator_service.proto

src/Shared/Grpc/ProtoUtils.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

44
using System.Buffers;
@@ -11,6 +11,7 @@
1111
using DurableTask.Core.Entities;
1212
using DurableTask.Core.Entities.OperationFormat;
1313
using DurableTask.Core.History;
14+
using DurableTask.Core.Tracing;
1415
using Google.Protobuf;
1516
using Google.Protobuf.WellKnownTypes;
1617
using DTCore = DurableTask.Core;
@@ -590,6 +591,10 @@ internal static void ToEntityBatchRequest(
590591
Operation = operationRequest.Operation,
591592
Input = operationRequest.Input,
592593
Id = Guid.Parse(operationRequest.RequestId),
594+
TraceContext = operationRequest.TraceContext != null ?
595+
new DistributedTraceContext(
596+
operationRequest.TraceContext.TraceParent,
597+
operationRequest.TraceContext.TraceState) : null,
593598
};
594599
}
595600

@@ -612,12 +617,16 @@ internal static void ToEntityBatchRequest(
612617
return new OperationResult()
613618
{
614619
Result = operationResult.Success.Result,
620+
StartTimeUtc = operationResult.Success.StartTimeUtc?.ToDateTime(),
621+
EndTimeUtc = operationResult.Success.EndTimeUtc?.ToDateTime(),
615622
};
616623

617624
case P.OperationResult.ResultTypeOneofCase.Failure:
618625
return new OperationResult()
619626
{
620627
FailureDetails = operationResult.Failure.FailureDetails.ToCore(),
628+
StartTimeUtc = operationResult.Failure.StartTimeUtc?.ToDateTime(),
629+
EndTimeUtc = operationResult.Failure.EndTimeUtc?.ToDateTime(),
621630
};
622631

623632
default:
@@ -645,6 +654,8 @@ internal static void ToEntityBatchRequest(
645654
Success = new P.OperationResultSuccess()
646655
{
647656
Result = operationResult.Result,
657+
StartTimeUtc = operationResult.StartTimeUtc?.ToTimestamp(),
658+
EndTimeUtc = operationResult.EndTimeUtc?.ToTimestamp(),
648659
},
649660
};
650661
}
@@ -655,6 +666,8 @@ internal static void ToEntityBatchRequest(
655666
Failure = new P.OperationResultFailure()
656667
{
657668
FailureDetails = ToProtobuf(operationResult.FailureDetails),
669+
StartTimeUtc = operationResult.StartTimeUtc?.ToTimestamp(),
670+
EndTimeUtc = operationResult.EndTimeUtc?.ToTimestamp(),
658671
},
659672
};
660673
}
@@ -683,6 +696,11 @@ internal static void ToEntityBatchRequest(
683696
Input = operationAction.SendSignal.Input,
684697
InstanceId = operationAction.SendSignal.InstanceId,
685698
ScheduledTime = operationAction.SendSignal.ScheduledTime?.ToDateTime(),
699+
RequestTime = operationAction.SendSignal.RequestTime?.ToDateTimeOffset(),
700+
ParentTraceContext = operationAction.SendSignal.ParentTraceContext != null ?
701+
new DistributedTraceContext(
702+
operationAction.SendSignal.ParentTraceContext.TraceParent,
703+
operationAction.SendSignal.ParentTraceContext.TraceState) : null,
686704
};
687705

688706
case P.OperationAction.OperationActionTypeOneofCase.StartNewOrchestration:
@@ -694,6 +712,11 @@ internal static void ToEntityBatchRequest(
694712
InstanceId = operationAction.StartNewOrchestration.InstanceId,
695713
Version = operationAction.StartNewOrchestration.Version,
696714
ScheduledStartTime = operationAction.StartNewOrchestration.ScheduledTime?.ToDateTime(),
715+
RequestTime = operationAction.StartNewOrchestration.RequestTime?.ToDateTimeOffset(),
716+
ParentTraceContext = operationAction.StartNewOrchestration.ParentTraceContext != null ?
717+
new DistributedTraceContext(
718+
operationAction.StartNewOrchestration.ParentTraceContext.TraceParent,
719+
operationAction.StartNewOrchestration.ParentTraceContext.TraceState) : null,
697720
};
698721
default:
699722
throw new NotSupportedException($"Deserialization of {operationAction.OperationActionTypeCase} is not supported.");
@@ -725,6 +748,14 @@ internal static void ToEntityBatchRequest(
725748
Input = sendSignalAction.Input,
726749
InstanceId = sendSignalAction.InstanceId,
727750
ScheduledTime = sendSignalAction.ScheduledTime?.ToTimestamp(),
751+
RequestTime = sendSignalAction.RequestTime?.ToTimestamp(),
752+
ParentTraceContext = sendSignalAction.ParentTraceContext != null ?
753+
new P.TraceContext
754+
{
755+
TraceParent = sendSignalAction.ParentTraceContext.TraceParent,
756+
TraceState = sendSignalAction.ParentTraceContext.TraceState,
757+
}
758+
: null,
728759
};
729760
break;
730761

@@ -737,6 +768,14 @@ internal static void ToEntityBatchRequest(
737768
Version = startNewOrchestrationAction.Version,
738769
InstanceId = startNewOrchestrationAction.InstanceId,
739770
ScheduledTime = startNewOrchestrationAction.ScheduledStartTime?.ToTimestamp(),
771+
RequestTime = startNewOrchestrationAction.RequestTime?.ToTimestamp(),
772+
ParentTraceContext = startNewOrchestrationAction.ParentTraceContext != null ?
773+
new P.TraceContext
774+
{
775+
TraceParent = startNewOrchestrationAction.ParentTraceContext.TraceParent,
776+
TraceState = startNewOrchestrationAction.ParentTraceContext.TraceState,
777+
}
778+
: null,
740779
};
741780
break;
742781
}

0 commit comments

Comments
 (0)