Skip to content

Commit

Permalink
Fixed ImapClient and Pop3Client.Connect/Async() when OTEL is enabled
Browse files Browse the repository at this point in the history
Fixes issue #1765
  • Loading branch information
jstedfast committed Jul 4, 2024
1 parent 55ea189 commit 62f66ef
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions MailKit/Net/Imap/AsyncImapClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions MailKit/Net/Imap/ImapClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions MailKit/Net/Imap/ImapEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions MailKit/Net/Pop3/AsyncPop3Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions MailKit/Net/Pop3/Pop3Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions MailKit/Net/Pop3/Pop3Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 62f66ef

Please sign in to comment.