From 62f66ef997626e3b88cd047edc290cd93d58d8bc Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Thu, 4 Jul 2024 10:19:53 -0400 Subject: [PATCH] Fixed ImapClient and Pop3Client.Connect/Async() when OTEL is enabled Fixes issue #1765 --- MailKit/Net/Imap/AsyncImapClient.cs | 4 ++-- MailKit/Net/Imap/ImapClient.cs | 4 ++-- MailKit/Net/Imap/ImapEngine.cs | 6 +++--- MailKit/Net/Pop3/AsyncPop3Client.cs | 4 ++-- MailKit/Net/Pop3/Pop3Client.cs | 4 ++-- MailKit/Net/Pop3/Pop3Engine.cs | 6 +++--- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/MailKit/Net/Imap/AsyncImapClient.cs b/MailKit/Net/Imap/AsyncImapClient.cs index 670f067721..364b26c4c4 100644 --- a/MailKit/Net/Imap/AsyncImapClient.cs +++ b/MailKit/Net/Imap/AsyncImapClient.cs @@ -653,7 +653,7 @@ public override async Task ConnectAsync (string host, int port = 0, SecureSocket ComputeDefaultValues (host, ref port, ref options, out var uri, out var starttls); - using var operation = engine.StartNetworkOperation (NetworkOperationKind.Connect); + using var operation = engine.StartNetworkOperation (NetworkOperationKind.Connect, uri); try { var stream = await ConnectNetworkAsync (host, port, cancellationToken).ConfigureAwait (false); @@ -827,7 +827,7 @@ public override async Task ConnectAsync (Stream stream, string host, int port = ComputeDefaultValues (host, ref port, ref options, out var uri, out var starttls); - using var operation = engine.StartNetworkOperation (NetworkOperationKind.Connect); + using var operation = engine.StartNetworkOperation (NetworkOperationKind.Connect, uri); try { Stream network; diff --git a/MailKit/Net/Imap/ImapClient.cs b/MailKit/Net/Imap/ImapClient.cs index e4b72db4a2..b6eed427f9 100644 --- a/MailKit/Net/Imap/ImapClient.cs +++ b/MailKit/Net/Imap/ImapClient.cs @@ -1561,7 +1561,7 @@ public override void Connect (string host, int port = 0, SecureSocketOptions opt ComputeDefaultValues (host, ref port, ref options, out var uri, out var starttls); - using var operation = engine.StartNetworkOperation (NetworkOperationKind.Connect); + using var operation = engine.StartNetworkOperation (NetworkOperationKind.Connect, uri); try { var stream = ConnectNetwork (host, port, cancellationToken); @@ -1746,7 +1746,7 @@ public override void Connect (Stream stream, string host, int port = 0, SecureSo ComputeDefaultValues (host, ref port, ref options, out var uri, out var starttls); - using var operation = engine.StartNetworkOperation (NetworkOperationKind.Connect); + using var operation = engine.StartNetworkOperation (NetworkOperationKind.Connect, uri); try { Stream network; diff --git a/MailKit/Net/Imap/ImapEngine.cs b/MailKit/Net/Imap/ImapEngine.cs index df8b9cf746..dbec14207f 100644 --- a/MailKit/Net/Imap/ImapEngine.cs +++ b/MailKit/Net/Imap/ImapEngine.cs @@ -619,12 +619,12 @@ internal void SetStream (ImapStream stream) Stream = stream; } - public NetworkOperation StartNetworkOperation (NetworkOperationKind kind) + public NetworkOperation StartNetworkOperation (NetworkOperationKind kind, Uri uri = null) { #if NET6_0_OR_GREATER - return NetworkOperation.Start (kind, Uri, Telemetry.ImapClient.ActivitySource, metrics); + return NetworkOperation.Start (kind, uri ?? Uri, Telemetry.ImapClient.ActivitySource, metrics); #else - return NetworkOperation.Start (kind, Uri); + return NetworkOperation.Start (kind, uri ?? Uri); #endif } diff --git a/MailKit/Net/Pop3/AsyncPop3Client.cs b/MailKit/Net/Pop3/AsyncPop3Client.cs index 5cb34d2226..1e612adea7 100644 --- a/MailKit/Net/Pop3/AsyncPop3Client.cs +++ b/MailKit/Net/Pop3/AsyncPop3Client.cs @@ -425,7 +425,7 @@ public override async Task ConnectAsync (string host, int port = 0, SecureSocket ComputeDefaultValues (host, ref port, ref options, out var uri, out var starttls); - using var operation = engine.StartNetworkOperation (NetworkOperationKind.Connect); + using var operation = engine.StartNetworkOperation (NetworkOperationKind.Connect, uri); try { var stream = await ConnectNetworkAsync (host, port, cancellationToken).ConfigureAwait (false); @@ -601,7 +601,7 @@ public override async Task ConnectAsync (Stream stream, string host, int port = ComputeDefaultValues (host, ref port, ref options, out var uri, out var starttls); - using var operation = engine.StartNetworkOperation (NetworkOperationKind.Connect); + using var operation = engine.StartNetworkOperation (NetworkOperationKind.Connect, uri); try { engine.Uri = uri; diff --git a/MailKit/Net/Pop3/Pop3Client.cs b/MailKit/Net/Pop3/Pop3Client.cs index b38a207d74..18745f4c8f 100644 --- a/MailKit/Net/Pop3/Pop3Client.cs +++ b/MailKit/Net/Pop3/Pop3Client.cs @@ -1199,7 +1199,7 @@ public override void Connect (string host, int port = 0, SecureSocketOptions opt ComputeDefaultValues (host, ref port, ref options, out var uri, out var starttls); - using var operation = engine.StartNetworkOperation (NetworkOperationKind.Connect); + using var operation = engine.StartNetworkOperation (NetworkOperationKind.Connect, uri); try { var stream = ConnectNetwork (host, port, cancellationToken); @@ -1392,7 +1392,7 @@ public override void Connect (Stream stream, string host, int port = 0, SecureSo ComputeDefaultValues (host, ref port, ref options, out var uri, out var starttls); - using var operation = engine.StartNetworkOperation (NetworkOperationKind.Connect); + using var operation = engine.StartNetworkOperation (NetworkOperationKind.Connect, uri); try { engine.Uri = uri; diff --git a/MailKit/Net/Pop3/Pop3Engine.cs b/MailKit/Net/Pop3/Pop3Engine.cs index 8839246848..e914bb02bf 100644 --- a/MailKit/Net/Pop3/Pop3Engine.cs +++ b/MailKit/Net/Pop3/Pop3Engine.cs @@ -251,12 +251,12 @@ void ParseGreeting (string greeting) State = Pop3EngineState.Connected; } - public NetworkOperation StartNetworkOperation (NetworkOperationKind kind) + public NetworkOperation StartNetworkOperation (NetworkOperationKind kind, Uri uri = null) { #if NET6_0_OR_GREATER - return NetworkOperation.Start (kind, Uri, Telemetry.Pop3Client.ActivitySource, metrics); + return NetworkOperation.Start (kind, uri ?? Uri, Telemetry.Pop3Client.ActivitySource, metrics); #else - return NetworkOperation.Start (kind, Uri); + return NetworkOperation.Start (kind, uri ?? Uri); #endif }