Skip to content

Update the trace support #541

@WeihanLi

Description

@WeihanLi

Currently in the TraceEnricherHook, we're adding tags/events to the current activity,

var tags = new ActivityTagsCollection();
foreach (var kvp in evaluationEvent.Attributes)
{
tags[kvp.Key] = kvp.Value;
}
this.AddCustomTags(tags);
this.AddFlagMetadataTags(details.FlagMetadata, tags);
Activity.Current?.AddEvent(new ActivityEvent(evaluationEvent.Name, tags: tags));

In this way, it's hard to listen to the event specifically, since the event is not determined, and sometimes there's no activity.

From the practice on docs, we should create an individual ActivitySource like the Meter, so that we could listen to the ActivitySource when we want to focus on the feature flag activity

https://learn.microsoft.com/en-us/dotnet/core/diagnostics/distributed-tracing-instrumentation-walkthroughs#best-practices

Another thought on the activity, we should try to avoid unnecessary operations to improve performance, for example, we could skip creating and adding tags/events when there's no activity or the Activity.IsAllDataRequested property is false

https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.activity.isalldatarequested

Finally, since we're creating a separate ActivitySource, think it could be built-in the main logic other than a hook, the users would need to listen to the ActivitySource explicitly to get related activities, so that no need to register additional trace hook.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions