Skip to content

Distributed Tracing for Entities (Isolated) #1198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 71 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
71 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
a904e3e
first commit!
Mar 28, 2025
869d1a2
addressing a few small comments
Mar 31, 2025
25b87ad
added some new lines back
Mar 31, 2025
34a09f1
added comments, fixed up some incorrect logic regarding linking trace…
Apr 3, 2025
129a2e6
trying to add support for tracing when ShimDurableTaskClient is used …
Apr 8, 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
9ed4bf6
aligning the isolated case with the new in-process changes
Apr 11, 2025
864a068
pushing what i have so far
Apr 14, 2025
8e1ff2e
seems like everything is working and aligned with the new in-process …
Apr 14, 2025
900567e
adding back new lines at the end of files
Apr 14, 2025
f71e300
missed some
Apr 14, 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
f698251
Merge branch 'stevosyan/distributed-tracing-for-entities' into stevos…
Apr 15, 2025
2bd49c7
attempting to fix some whitespace issues
Apr 15, 2025
d82f3a4
attempting to fix some whitespace issues
Apr 15, 2025
128970b
attempting to fix some whitespace issues
Apr 15, 2025
9a54fef
missed a null check
Apr 15, 2025
82bc84d
added a check for if we cannot successfully parse the parent trace co…
Apr 15, 2025
2be54cf
moving all trace activities into TaskEntityDispatcher to avoid any ex…
Apr 17, 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
8e203b0
Merge branch 'stevosyan/distributed-tracing-for-entities' into stevos…
Apr 19, 2025
ee86dd2
moved activity for entity starting an orchestration back into webjobs
Apr 22, 2025
2206569
as always missed some stuff
Apr 22, 2025
d09e145
Merge branch 'stevosyan/distributed-tracing-for-entities' into stevos…
Apr 22, 2025
5f9842c
missed a spacing thing
Apr 23, 2025
a22ba16
fixing a bug where we needed a parent trace context for orchestration…
Apr 23, 2025
ba75851
added support for an entities enabled flag
Apr 25, 2025
87703e6
Merge branch 'stevosyan/distributed-tracing-for-entities' into stevos…
Apr 25, 2025
14faf90
added a start time to OperationResult
Apr 25, 2025
92e5c26
added a null check for client span ID when creating the activity for …
Apr 25, 2025
37764a6
Merge branch 'stevosyan/distributed-tracing-for-entities' into stevos…
Apr 25, 2025
13d56ad
getting rid of an extra line
Apr 25, 2025
1d6571b
Merge branch 'stevosyan/distributed-tracing-for-entities' into stevos…
Apr 25, 2025
9ad0099
addressing PR comment
Apr 28, 2025
389711f
Merge branch 'stevosyan/distributed-tracing-for-entities' into stevos…
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
b3405d3
Merge branch 'stevosyan/distributed-tracing-for-entities' into stevos…
May 8, 2025
5062030
addressing some PR comments, slightly changing the logic of the modif…
May 8, 2025
a97b5fe
tiny style update
May 10, 2025
0994ec5
missed a line
May 10, 2025
3ee6b03
slight style update... decided not to unnecessarily check for a inval…
May 12, 2025
2785860
Merge branch 'stevosyan/distributed-tracing-for-entities' into stevos…
May 12, 2025
b4054f5
addressing PR comments
May 13, 2025
8f4171b
fix for the bug with the scheduled time - if the scheduled time for a…
May 14, 2025
c22275b
tiny method name change
May 14, 2025
0d30abf
addressing PR comments
May 15, 2025
71d0f06
changed startTime/endTime to startTimeUtc/endTimeUtc and made the req…
May 16, 2025
18f8aeb
Merge branch 'main' into stevosyan/distributed-tracing-for-entities-i…
May 20, 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
9 changes: 8 additions & 1 deletion src/DurableTask.Core/Entities/ClientEntityHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace DurableTask.Core.Entities
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System;
using DurableTask.Core.Tracing;

/// <summary>
/// Utility functions for clients that interact with entities, either by sending events or by accessing the entity state directly in storage
Expand All @@ -32,8 +33,11 @@ public static class ClientEntityHelpers
/// <param name="operationName">The name of the operation.</param>
/// <param name="input">The serialized input for the operation.</param>
/// <param name="scheduledTimeUtc">The time to schedule this signal, or null if not a scheduled signal</param>
/// <param name="parentTraceContext">The parent trace context for this operation.</param>
/// <param name="requestTime">The time at which the request was made.</param>
/// <param name="createTrace">Whether to create a trace for this signal operation.</param>
/// <returns>The event to send.</returns>
public static EntityMessageEvent EmitOperationSignal(OrchestrationInstance targetInstance, Guid requestId, string operationName, string? input, (DateTime Original, DateTime Capped)? scheduledTimeUtc)
public static EntityMessageEvent EmitOperationSignal(OrchestrationInstance targetInstance, Guid requestId, string operationName, string? input, (DateTime Original, DateTime Capped)? scheduledTimeUtc, DistributedTraceContext? parentTraceContext = null, DateTimeOffset? requestTime = null, bool createTrace = false)
{
var request = new RequestMessage()
{
Expand All @@ -44,6 +48,9 @@ public static EntityMessageEvent EmitOperationSignal(OrchestrationInstance targe
Operation = operationName,
ScheduledTime = scheduledTimeUtc?.Original,
Input = input,
ParentTraceContext = parentTraceContext,
RequestTime = requestTime,
CreateTrace = createTrace,
};

var eventName = scheduledTimeUtc.HasValue
Expand Down
24 changes: 24 additions & 0 deletions src/DurableTask.Core/Entities/EventFormat/RequestMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#nullable enable
namespace DurableTask.Core.Entities.EventFormat
{
using DurableTask.Core.Tracing;
using System;
using System.Runtime.Serialization;

Expand Down Expand Up @@ -98,6 +99,29 @@ internal class RequestMessage : EntityMessage
[DataMember]
public bool IsLockRequest => LockSet != null;

/// <summary>
/// Parent trace context of this request message.
/// </summary>
[DataMember(Name = "parentTraceContext", EmitDefaultValue = false)]
public DistributedTraceContext? ParentTraceContext { get; set; }

/// <summary>
/// Whether or not to create an entity-specific trace for this request message
/// </summary>
[DataMember(Name = "createTrace")]
public bool CreateTrace { get; set; }

/// <summary>
/// The time the request was generated.
/// </summary>
[DataMember(Name = "requestTime", EmitDefaultValue = false)]
public DateTimeOffset? RequestTime { get; set; }

/// <summary>
/// The client span ID of this request.
/// </summary>
public string? ClientSpanId { get; set; }

/// <inheritdoc/>
public override string GetShortDescription()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#nullable enable
namespace DurableTask.Core.Entities.OperationFormat
{
using DurableTask.Core.Tracing;
using System;

/// <summary>
Expand All @@ -37,5 +38,10 @@ public class OperationRequest
/// The input for the operation. Can be null if no input was given.
/// </summary>
public string? Input { get; set; }

/// <summary>
/// The trace context for the operation, if any.
/// </summary>
public DistributedTraceContext? TraceContext { get; set; }
}
}
12 changes: 12 additions & 0 deletions src/DurableTask.Core/Entities/OperationFormat/OperationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// limitations under the License.
// ----------------------------------------------------------------------------------
#nullable enable
using System;

namespace DurableTask.Core.Entities.OperationFormat
{
/// <summary>
Expand Down Expand Up @@ -46,5 +48,15 @@ public bool IsError
/// this field exclusively when collecting error information.
/// </summary>
public FailureDetails? FailureDetails { get; set; }

/// <summary>
/// The start time of the operation.
/// </summary>
public DateTime? StartTime { get; set; }

/// <summary>
/// The completion time of the operation.
/// </summary>
public DateTime? EndTime { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#nullable enable
namespace DurableTask.Core.Entities.OperationFormat
{
using DurableTask.Core.Tracing;
using System;

/// <summary>
Expand Down Expand Up @@ -45,5 +46,15 @@ public class SendSignalOperationAction : OperationAction
/// Optionally, a scheduled delivery time for the signal.
/// </summary>
public DateTime? ScheduledTime { get; set; }

/// <summary>
/// The time the signal request was generated.
/// </summary>
public DateTime? RequestTime { get; set; }

/// <summary>
/// The parent trace context for the signal, if any.
/// </summary>
public DistributedTraceContext? ParentTraceContext { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#nullable enable
namespace DurableTask.Core.Entities.OperationFormat
{
using DurableTask.Core.Tracing;
using System;
using System.Collections.Generic;

Expand Down Expand Up @@ -52,5 +53,15 @@ public class StartNewOrchestrationOperationAction : OperationAction
/// </summary>
public DateTime? ScheduledStartTime { get; set; }

/// <summary>
/// The time of the new orchestration request creation.
/// </summary>
public DateTime? RequestTime { get; set; }

/// <summary>
/// The parent trace context for the operation, if any.
/// </summary>
public DistributedTraceContext? ParentTraceContext { get; set; }

}
}
8 changes: 7 additions & 1 deletion src/DurableTask.Core/Entities/OrchestrationEntityContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,18 @@ public IEnumerable<EntityMessageEvent> EmitLockReleaseMessages()
/// <param name="operationId">A unique identifier for this request.</param>
/// <param name="scheduledTimeUtc">A time for which to schedule the delivery, or null if this is not a scheduled message</param>
/// <param name="input">The operation input</param>
/// <param name="requestTime">The time at which the request was made.</param>
/// <param name="createTrace">Whether or not to create an entity-specific trace for this event</param>
/// <returns>The event to send.</returns>
public EntityMessageEvent EmitRequestMessage(
OrchestrationInstance target,
string operationName,
bool oneWay,
Guid operationId,
(DateTime Original, DateTime Capped)? scheduledTimeUtc,
string? input)
string? input,
DateTimeOffset? requestTime = null,
bool createTrace = false)
{
this.CheckEntitySupport();

Expand All @@ -248,6 +252,8 @@ public EntityMessageEvent EmitRequestMessage(
Operation = operationName,
ScheduledTime = scheduledTimeUtc?.Original,
Input = input,
RequestTime = requestTime,
CreateTrace = createTrace,
};

this.AdjustOutgoingMessage(target.InstanceId, request, scheduledTimeUtc?.Capped, out string eventName);
Expand Down
20 changes: 20 additions & 0 deletions src/DurableTask.Core/OrchestrationTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ 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 = "MS_Entities_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 = "MS_Entities_TraceState";

/// <summary>
/// The time the request for a new orchestration was created.
/// </summary>
public const string RequestTime = "MS_Entities_RequestTime";

/// <summary>
/// Whether or not to create a trace for the <see cref="DurableTask.Core.History.ExecutionStartedEvent"/> of the orchestration
/// </summary>
public const string CreateTraceForNewOrchestration = "MS_CreateTrace";

/// <summary>
/// Check whether the given tags contain the fire and forget tag
/// </summary>
Expand Down
Loading