Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
af21cb2
added distributed tracing for entities
Mar 6, 2025
8846d70
change in how the distributed trace context is propagated in the case…
Mar 10, 2025
d3f25f3
slight style update
Mar 11, 2025
ed72bf7
some more tiny style things
Mar 12, 2025
1c271de
addressing two more PR comments
Mar 12, 2025
ffe061e
forgot to add one annotation
Mar 13, 2025
7462c40
yet another small style change
Mar 13, 2025
8871873
addressing PR comments
Mar 18, 2025
d49c005
forgot one file
Mar 18, 2025
7175737
addressing more PR comments
Mar 25, 2025
b2f859f
forgot two comments
Mar 25, 2025
869d1a2
addressing a few small comments
Mar 31, 2025
3116463
refactored most of the tracing into this repo to more accurately refl…
Apr 11, 2025
87776bc
fixing spacing
Apr 11, 2025
97cd8e6
slight change in formatting of the create orchestration trace
Apr 11, 2025
d01179f
addressing PR comments
Apr 15, 2025
30db2fb
adding back new lines at the ends of files
Apr 15, 2025
c4dc784
trying to fix these line endings
Apr 15, 2025
41b0280
dealing with new lines again
Apr 15, 2025
dcac8a8
tiny change
Apr 15, 2025
9a54fef
missed a null check
Apr 15, 2025
9aec0fc
reverting to old design
Apr 18, 2025
d8c10bb
missed some
Apr 18, 2025
6b2bce1
and missed some more
Apr 18, 2025
0b56873
missed even more
Apr 18, 2025
ac98d23
will it ever end
Apr 18, 2025
9ef781c
last one i think
Apr 18, 2025
ee86dd2
moved activity for entity starting an orchestration back into webjobs
Apr 22, 2025
2206569
as always missed some stuff
Apr 22, 2025
ba75851
added support for an entities enabled flag
Apr 25, 2025
92e5c26
added a null check for client span ID when creating the activity for …
Apr 25, 2025
13d56ad
getting rid of an extra line
Apr 25, 2025
9ad0099
addressing PR comment
Apr 28, 2025
69d968e
Merge branch 'main' into stevosyan/distributed-tracing-for-entities
May 6, 2025
e172546
addressing a few PR comments
May 6, 2025
5062030
addressing some PR comments, slightly changing the logic of the modif…
May 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/DurableTask.Core/Entities/EventFormat/RequestMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ internal class RequestMessage : EntityMessage
[DataMember]
public bool IsLockRequest => LockSet != null;

/// <summary>
/// Whether this message already has a trace created for it
/// </summary>
[DataMember(Name = "traceCreated")]
public bool TraceCreated { get; set; }

/// <inheritdoc/>
public override string GetShortDescription()
{
Expand Down
10 changes: 10 additions & 0 deletions src/DurableTask.Core/OrchestrationTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ public static class OrchestrationTags
/// </remarks>
public const string FireAndForget = "FireAndForget";

/// <summary>
/// The ID of the parent trace that created this orchestration instance (see https://www.w3.org/TR/trace-context/#traceparent-header)
/// </summary>
public const string TraceParent = "TraceParent";

/// <summary>
/// The trace state of the parent trace that created this orchestration instance (see https://www.w3.org/TR/trace-context/#tracestate-header)
/// </summary>
public const string TraceState = "TraceState";

/// <summary>
/// Check whether the given tags contain the fire and forget tag
/// </summary>
Expand Down
33 changes: 27 additions & 6 deletions src/DurableTask.Core/TaskOrchestrationDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,29 @@ protected async Task<bool> OnProcessWorkItemAsync(TaskOrchestrationWorkItem work
break;
case OrchestratorActionType.CreateSubOrchestration:
var createSubOrchestrationAction = (CreateSubOrchestrationAction)decision;
ActivityContext? parentTraceContext = traceActivity?.Context;
var spanId = ActivitySpanId.CreateRandom();
if (createSubOrchestrationAction.Tags != null
&& createSubOrchestrationAction.Tags.TryGetValue(OrchestrationTags.TraceParent, out string traceParent)
&& createSubOrchestrationAction.Tags.TryGetValue(OrchestrationTags.TraceState, out string traceState))
{
try
{
parentTraceContext = ActivityContext.Parse(traceParent, traceState);
spanId = parentTraceContext.Value.SpanId;
}
catch (Exception e)
{
TraceHelper.TraceException(TraceEventType.Error, "TaskOrchestrationDispatcher-CreateSubOrchestration-MalformedParentTrace", e);
}
}
orchestratorMessages.Add(
this.ProcessCreateSubOrchestrationInstanceDecision(
createSubOrchestrationAction,
runtimeState,
this.IncludeParameters,
traceActivity));
parentTraceContext,
spanId));
break;
case OrchestratorActionType.SendEvent:
var sendEventAction = (SendEventOrchestratorAction)decision;
Expand Down Expand Up @@ -1083,7 +1100,8 @@ TaskMessage ProcessCreateSubOrchestrationInstanceDecision(
CreateSubOrchestrationAction createSubOrchestrationAction,
OrchestrationRuntimeState runtimeState,
bool includeParameters,
Activity? parentTraceActivity)
ActivityContext? parentTraceContext,
ActivitySpanId spanId)
{
var historyEvent = new SubOrchestrationInstanceCreatedEvent(createSubOrchestrationAction.Id)
{
Expand All @@ -1096,8 +1114,7 @@ TaskMessage ProcessCreateSubOrchestrationInstanceDecision(
historyEvent.Input = createSubOrchestrationAction.Input;
}

ActivitySpanId clientSpanId = ActivitySpanId.CreateRandom();
historyEvent.ClientSpanId = clientSpanId.ToString();
historyEvent.ClientSpanId = spanId.ToString();

runtimeState.AddEvent(historyEvent);

Expand All @@ -1122,9 +1139,13 @@ TaskMessage ProcessCreateSubOrchestrationInstanceDecision(
Version = createSubOrchestrationAction.Version
};

if (parentTraceActivity != null)
if (parentTraceContext is ActivityContext parentContext)
{
ActivityContext activityContext = new ActivityContext(parentTraceActivity.TraceId, clientSpanId, parentTraceActivity.ActivityTraceFlags, parentTraceActivity.TraceStateString);
ActivityContext activityContext = new ActivityContext(
parentContext.TraceId,
spanId,
parentContext.TraceFlags,
parentContext.TraceState);
startedEvent.SetParentTraceContext(activityContext);
}

Expand Down
14 changes: 13 additions & 1 deletion src/DurableTask.Core/Tracing/TraceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class TraceHelper
{
newActivity.SetTag(Schema.Task.Version, startEvent.Version);
}

startEvent.SetParentTraceContext(newActivity);
}

Expand Down Expand Up @@ -357,6 +357,12 @@ internal static void EmitTraceActivityForSubOrchestrationFailed(
OrchestrationInstance? instance,
string? targetInstanceId)
{
// There is a possibility that we mislabel the event as an entity event if entities are not enabled
if (Entities.IsEntityInstance(targetInstanceId ?? string.Empty) || Entities.IsEntityInstance(instance?.InstanceId ?? string.Empty))
{
return null;
}

Activity? newActivity = ActivityTraceSource.StartActivity(
CreateSpanName(TraceActivityConstants.OrchestrationEvent, eventRaisedEvent.Name, null),
kind: ActivityKind.Producer,
Expand Down Expand Up @@ -390,6 +396,12 @@ internal static void EmitTraceActivityForSubOrchestrationFailed(
/// </returns>
internal static Activity? StartActivityForNewEventRaisedFromClient(EventRaisedEvent eventRaised, OrchestrationInstance instance)
{
// There is a possibility that we mislabel the event as an entity event if entities are not enabled
if (Entities.IsEntityInstance(instance.InstanceId))
{
return null;
}

Activity? newActivity = ActivityTraceSource.StartActivity(
CreateSpanName(TraceActivityConstants.OrchestrationEvent, eventRaised.Name, null),
kind: ActivityKind.Producer,
Expand Down
Loading