Skip to content

Commit 9055c05

Browse files
committed
chore(): Added explicit logging for mTLS HttpClient creation failures via a new event source entry
1 parent 70a5ce4 commit 9055c05

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OpenTelemetryProtocolExporterEventSource.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,5 +309,21 @@ internal void MtlsServerCertificateValidationFailed(string subject, string error
309309
Level = EventLevel.Informational)]
310310
internal void MtlsConfigurationEnabled(string clientCertificateSubject) =>
311311
this.WriteEvent(33, clientCertificateSubject);
312+
313+
[NonEvent]
314+
internal void MtlsHttpClientCreationFailed(Exception ex)
315+
{
316+
if (Log.IsEnabled(EventLevel.Error, EventKeywords.All))
317+
{
318+
this.MtlsHttpClientCreationFailed(ex.ToInvariantString());
319+
}
320+
}
321+
322+
[Event(
323+
34,
324+
Message = "Failed to create mTLS HttpClient. Exception: {0}",
325+
Level = EventLevel.Error)]
326+
internal void MtlsHttpClientCreationFailed(string exception) =>
327+
this.WriteEvent(34, exception);
312328
#endif
313329
}

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpMtlsHttpClientFactory.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ public static HttpClient CreateMtlsHttpClient(
2828

2929
if (!mtlsOptions.IsEnabled)
3030
{
31-
throw new InvalidOperationException(
32-
"mTLS options must include a client or CA certificate path."
33-
);
31+
throw new InvalidOperationException("mTLS options must include a client or CA certificate path.");
3432
}
3533

3634
HttpClientHandler? handler = null;
@@ -122,6 +120,7 @@ public static HttpClient CreateMtlsHttpClient(
122120
// Dispose handler if something went wrong
123121
handler?.Dispose();
124122

123+
OpenTelemetryProtocolExporterEventSource.Log.MtlsHttpClientCreationFailed(ex);
125124
OpenTelemetryProtocolExporterEventSource.Log.ExportMethodException(ex);
126125
throw;
127126
}

0 commit comments

Comments
 (0)