Skip to content

Commit

Permalink
Factory method for building activity tags collection
Browse files Browse the repository at this point in the history
  • Loading branch information
w1am committed Jan 6, 2025
1 parent 3890596 commit 3feb7c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
28 changes: 14 additions & 14 deletions src/EventStore.Client.Streams/EventStoreClient.Append.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,7 @@ ValueTask<IWriteResult> AppendToStreamInternal(
UserCredentials? userCredentials,
CancellationToken cancellationToken
) {
var tags = new ActivityTagsCollection()
.WithRequiredTag(TelemetryTags.EventStore.Stream, header.Options.StreamIdentifier.StreamName.ToStringUtf8())
.WithGrpcChannelServerTags(Settings, channelInfo)
.WithClientSettingsServerTags(Settings)
.WithOptionalTag(TelemetryTags.Database.User, userCredentials?.Username ?? Settings.DefaultCredentials?.Username);

return EventStoreClientDiagnostics.ActivitySource.TraceClientOperation(Operation, TracingConstants.Operations.Append, tags);
return EventStoreClientDiagnostics.ActivitySource.TraceClientOperation(Operation, TracingConstants.Operations.Append, AppendTags);

async ValueTask<IWriteResult> Operation() {
using var call = new StreamsClient(channelInfo.CallInvoker)
Expand Down Expand Up @@ -157,6 +151,12 @@ await call.RequestStream

return HandleWrongExpectedRevision(response, header, operationOptions);
}

ActivityTagsCollection AppendTags() => new ActivityTagsCollection()
.WithRequiredTag(TelemetryTags.EventStore.Stream, header.Options.StreamIdentifier.StreamName.ToStringUtf8())
.WithGrpcChannelServerTags(Settings, channelInfo)
.WithClientSettingsServerTags(Settings)
.WithOptionalTag(TelemetryTags.Database.User, userCredentials?.Username ?? Settings.DefaultCredentials?.Username);
}

IWriteResult HandleSuccessAppend(AppendResp response, AppendReq header) {
Expand Down Expand Up @@ -282,16 +282,10 @@ ValueTask<IWriteResult> AppendInternal(
IEnumerable<EventData> events,
CancellationToken cancellationToken
) {
var tags = new ActivityTagsCollection()
.WithRequiredTag(TelemetryTags.EventStore.Stream, options.StreamIdentifier.StreamName.ToStringUtf8())
.WithGrpcChannelServerTags(_settings, _channelInfo)
.WithClientSettingsServerTags(_settings)
.WithOptionalTag(TelemetryTags.Database.User, _settings.DefaultCredentials?.Username);

return EventStoreClientDiagnostics.ActivitySource.TraceClientOperation(
Operation,
TracingConstants.Operations.Append,
tags
AppendTags
);

async ValueTask<IWriteResult> Operation() {
Expand All @@ -310,6 +304,12 @@ async ValueTask<IWriteResult> Operation() {

return await complete.Task.ConfigureAwait(false);
}

ActivityTagsCollection AppendTags() => new ActivityTagsCollection()
.WithRequiredTag(TelemetryTags.EventStore.Stream, options.StreamIdentifier.StreamName.ToStringUtf8())
.WithGrpcChannelServerTags(_settings, _channelInfo)
.WithClientSettingsServerTags(_settings)
.WithOptionalTag(TelemetryTags.Database.User, _settings.DefaultCredentials?.Username);
}

async Task Duplex(ValueTask<ChannelInfo> channelInfoTask) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ public static async ValueTask<T> TraceClientOperation<T>(
this ActivitySource source,
Func<ValueTask<T>> tracedOperation,
string operationName,
ActivityTagsCollection? tags = null
Func<ActivityTagsCollection?>? tagsFactory = null
) {
if (source.HasNoActiveListeners())
return await tracedOperation().ConfigureAwait(false);

var tags = tagsFactory?.Invoke();

using var activity = StartActivity(source, operationName, ActivityKind.Client, tags, Activity.Current?.Context);

try {
Expand Down

0 comments on commit 3feb7c7

Please sign in to comment.