Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/Instrumentation/InstrumentationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static class InstrumentationBuilderExtensions
public static TracerProviderBuilder AddInMemoryMessagingInstrumentation(this TracerProviderBuilder builder)
{
builder.AddSource(InMemoryMessagingTraceInstrumentation.InstrumentationName);
InMemoryMessagingTraceInstrumentation.IsEnabled = true;

return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ internal struct InMemoryMessagingTraceInstrumentation
internal const string InstrumentationName = "InMemoryMessaging";

/// <summary>
/// The key to add/read the id of activity (parent trace and span) to/from the publishing/received events.
/// Determines whether the instrumentation is enabled or not.
/// </summary>
public const string TraceParentIdKey = "TraceParentId";
public static bool IsEnabled { get; internal set; }

/// <summary>
/// The activity source to create a new activity
Expand All @@ -27,10 +27,12 @@ internal struct InMemoryMessagingTraceInstrumentation
/// </summary>
/// <param name="name">Name of new activity</param>
/// <param name="kind">Type of new activity. The default is <see cref="ActivityKind.Internal"/></param>
/// <param name="traceParentId">The id of activity (parent trace and span) to assign. Example: "{version}-{trace-id}-{parent-span-id}-{trace-flags}"</param>
/// <returns>Newly created an open telemetry activity</returns>
internal static Activity StartActivity(string name, ActivityKind kind = ActivityKind.Internal, string traceParentId = null)
internal static Activity StartActivity(string name, ActivityKind kind = ActivityKind.Producer)
{
if (!IsEnabled) return null;

var traceParentId = Activity.Current?.Id;
ActivityContext.TryParse(traceParentId, null, out ActivityContext parentContext);
var activity = ActivitySource.StartActivity(name, kind, parentContext);

Expand Down
3 changes: 1 addition & 2 deletions src/Managers/MessageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public async Task PublishAsync<TMessage>(TMessage message) where TMessage : clas

try
{
var traceParentId = Activity.Current?.Id;
using var activity = InMemoryMessagingTraceInstrumentation.StartActivity($"DomainEvent: Executing handlers of the '{messageName}' memory message.", ActivityKind.Producer, traceParentId);
using var activity = InMemoryMessagingTraceInstrumentation.StartActivity($"DomainEvent: Executing handler(s) of the '{messageName}' memory message.");

OnExecutingReceivedMessage(message);

Expand Down