Skip to content

Commit

Permalink
Account for standard ports when collecting tags
Browse files Browse the repository at this point in the history
  • Loading branch information
w1am committed Jan 6, 2025
1 parent 699470d commit 3890596
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/EventStore.Client.Streams/EventStoreClient.Append.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ CancellationToken cancellationToken
) {
var tags = new ActivityTagsCollection()
.WithRequiredTag(TelemetryTags.EventStore.Stream, header.Options.StreamIdentifier.StreamName.ToStringUtf8())
.WithGrpcChannelServerTags(channelInfo)
.WithGrpcChannelServerTags(Settings, channelInfo)
.WithClientSettingsServerTags(Settings)
.WithOptionalTag(TelemetryTags.Database.User, userCredentials?.Username ?? Settings.DefaultCredentials?.Username);

Expand Down Expand Up @@ -284,7 +284,7 @@ CancellationToken cancellationToken
) {
var tags = new ActivityTagsCollection()
.WithRequiredTag(TelemetryTags.EventStore.Stream, options.StreamIdentifier.StreamName.ToStringUtf8())
.WithGrpcChannelServerTags(_channelInfo)
.WithGrpcChannelServerTags(_settings, _channelInfo)
.WithClientSettingsServerTags(_settings)
.WithOptionalTag(TelemetryTags.Database.User, _settings.DefaultCredentials?.Username);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public static async ValueTask<T> TraceClientOperation<T>(
string operationName,
ActivityTagsCollection? tags = null
) {
if (source.HasNoActiveListeners())
return await tracedOperation().ConfigureAwait(false);

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

try {
Expand Down Expand Up @@ -47,7 +50,7 @@ public static void TraceSubscriptionEvent(
.WithRequiredTag(TelemetryTags.EventStore.EventId, resolvedEvent.OriginalEvent.EventId.ToString())
.WithRequiredTag(TelemetryTags.EventStore.EventType, resolvedEvent.OriginalEvent.EventType)
// Ensure consistent server.address attribute when connecting to cluster via dns discovery
.WithGrpcChannelServerTags(channelInfo)
.WithGrpcChannelServerTags(settings, channelInfo)
.WithClientSettingsServerTags(settings)
.WithOptionalTag(
TelemetryTags.Database.User,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ namespace EventStore.Client.Diagnostics;

static class ActivityTagsCollectionExtensions {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ActivityTagsCollection WithGrpcChannelServerTags(this ActivityTagsCollection tags, ChannelInfo? channelInfo) {
public static ActivityTagsCollection WithGrpcChannelServerTags(this ActivityTagsCollection tags, EventStoreClientSettings settings, ChannelInfo? channelInfo) {
if (channelInfo is null)
return tags;

var authorityParts = channelInfo.Channel.Target.Split(':');

return tags
.WithRequiredTag(TelemetryTags.Server.Address, authorityParts[0])
.WithRequiredTag(TelemetryTags.Server.Port, int.Parse(authorityParts[1]));
}
var authorityParts = channelInfo.Channel.Target.Split([':'], StringSplitOptions.RemoveEmptyEntries);

string host = authorityParts[0];
int port = authorityParts.Length == 1
? settings.ConnectivitySettings.Insecure ? 80 : 443
: int.Parse(authorityParts[1]);

return tags
.WithRequiredTag(TelemetryTags.Server.Address, host)
.WithRequiredTag(TelemetryTags.Server.Port, port);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ActivityTagsCollection WithClientSettingsServerTags(this ActivityTagsCollection source, EventStoreClientSettings settings) {
Expand Down

0 comments on commit 3890596

Please sign in to comment.