From 3890596878794cc6f0c5a2a36bf8035191197756 Mon Sep 17 00:00:00 2001 From: William Chong Date: Mon, 6 Jan 2025 18:30:18 +0400 Subject: [PATCH] Account for standard ports when collecting tags --- .../EventStoreClient.Append.cs | 4 ++-- .../Diagnostics/ActivitySourceExtensions.cs | 5 ++++- .../ActivityTagsCollectionExtensions.cs | 19 ++++++++++++------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/EventStore.Client.Streams/EventStoreClient.Append.cs b/src/EventStore.Client.Streams/EventStoreClient.Append.cs index 9fa0a62d8..1dca9fd6a 100644 --- a/src/EventStore.Client.Streams/EventStoreClient.Append.cs +++ b/src/EventStore.Client.Streams/EventStoreClient.Append.cs @@ -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); @@ -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); diff --git a/src/EventStore.Client/Common/Diagnostics/ActivitySourceExtensions.cs b/src/EventStore.Client/Common/Diagnostics/ActivitySourceExtensions.cs index 28d336a85..778fd19ee 100644 --- a/src/EventStore.Client/Common/Diagnostics/ActivitySourceExtensions.cs +++ b/src/EventStore.Client/Common/Diagnostics/ActivitySourceExtensions.cs @@ -14,6 +14,9 @@ public static async ValueTask TraceClientOperation( 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 { @@ -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, diff --git a/src/EventStore.Client/Common/Diagnostics/ActivityTagsCollectionExtensions.cs b/src/EventStore.Client/Common/Diagnostics/ActivityTagsCollectionExtensions.cs index 865959eb9..bc3c2aa75 100644 --- a/src/EventStore.Client/Common/Diagnostics/ActivityTagsCollectionExtensions.cs +++ b/src/EventStore.Client/Common/Diagnostics/ActivityTagsCollectionExtensions.cs @@ -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) {