Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
00c903c
feat(): Add mTLS Support for OTLP Exporter
sandy2008 Oct 23, 2024
b10b3fa
Merge branch 'main' into main
sandy2008 Oct 23, 2024
0d0aa98
feat(): feat: Add certificate handling in HttpClientFactory using X50…
sandy2008 Oct 27, 2024
e7c6f5b
feat(): feat: Add certificate handling in HttpClientFactory using X50…
sandy2008 Oct 27, 2024
3b43fd3
feat(): feat: Add certificate handling in HttpClientFactory using X50…
sandy2008 Oct 27, 2024
4b6d3cd
feat(): feat: Add certificate handling in HttpClientFactory using X50…
sandy2008 Oct 27, 2024
5864dbf
feat(): feat: Add certificate handling in HttpClientFactory using X50…
sandy2008 Oct 27, 2024
0e38ba3
Merge branch 'main' into main
sandy2008 Oct 27, 2024
3733dee
Merge branch 'main' into main
sandy2008 Nov 5, 2024
f09a650
Merge branch 'main' into main
sandy2008 Nov 7, 2024
8630876
Merge branch 'main' into main
sandy2008 Nov 11, 2024
2e7e412
feat(): Add mTLS Support for OTLP Exporter
sandy2008 Nov 11, 2024
afc8df6
feat(): Add mTLS Support for OTLP Exporter
sandy2008 Nov 11, 2024
c5101b1
feat(): Add mTLS Support for OTLP Exporter
sandy2008 Nov 11, 2024
84a4d5b
feat(): Add mTLS Support for OTLP Exporter
sandy2008 Nov 11, 2024
716949c
feat(): Add mTLS Support for OTLP Exporter
sandy2008 Nov 11, 2024
2781534
feat(): Add mTLS Support for OTLP Exporter
sandy2008 Nov 11, 2024
31ef9aa
Merge branch 'main' into main
sandy2008 Nov 13, 2024
9df6f06
Merge branch 'main' into main
sandy2008 Nov 15, 2024
6e940d1
Merge branch 'main' into main
sandy2008 Nov 19, 2024
dc39de9
Merge branch 'main' into main
sandy2008 Nov 24, 2024
2006fbf
Merge branch 'main' into main
sandy2008 Nov 28, 2024
87737eb
Merge branch 'main' into main
sandy2008 Dec 11, 2024
4d56a9a
Merge branch 'main' into main
sandy2008 Dec 13, 2024
c4ec895
Merge branch 'main' into main
rajkumar-rangaraj Dec 16, 2024
0ad1e13
Merge branch 'main' into main
sandy2008 Dec 17, 2024
7a378e6
Merge branch 'main' into main
sandy2008 Dec 19, 2024
6bddb6b
Merge branch 'main' into main
sandy2008 Dec 25, 2024
9b44067
Merge branch 'main' into main
sandy2008 Jan 7, 2025
a0bd2f9
Merge branch 'main' into main
sandy2008 Jan 20, 2025
f9fcd24
Merge branch 'main' into main
sandy2008 Feb 4, 2025
6675646
Merge branch 'main' into main
sandy2008 Feb 12, 2025
9b13d2e
Merge branch 'main' into main
sandy2008 Feb 19, 2025
cb5ccdf
Merge branch 'main' into main
sandy2008 Feb 24, 2025
d71b483
fix(): support new grpc client
sandy2008 Feb 24, 2025
8694bb9
fix(): support new grpc client
sandy2008 Feb 24, 2025
9d6e67a
fix(): support new grpc client
sandy2008 Feb 24, 2025
7aa2ea3
fix(): support new grpc client
sandy2008 Feb 24, 2025
a09e608
fix(): otlp exporter
sandy2008 Feb 24, 2025
e77d6e1
fix(): support new grpc client
sandy2008 Feb 24, 2025
797816c
fix(): support new grpc client
sandy2008 Feb 24, 2025
0691873
fix(): support new grpc client
sandy2008 Feb 24, 2025
8471933
fix(): support new grpc client
sandy2008 Feb 25, 2025
a9c0e90
Merge branch 'main' into main
rajkumar-rangaraj Feb 25, 2025
5beccbf
fix(): support new grpc client
sandy2008 Feb 25, 2025
8a9639f
Merge branch 'main' of https://github.com/sandy2008/opentelemetry-dotnet
sandy2008 Feb 25, 2025
97e2ba5
Merge branch 'main' into main
sandy2008 Mar 4, 2025
c0b25b6
Merge branch 'main' into main
sandy2008 Mar 6, 2025
8d0717c
feat(): remove public apis for certs
sandy2008 Mar 6, 2025
e32eb71
Merge branch 'main' into main
sandy2008 Mar 10, 2025
d01ed8f
Merge branch 'main' into main
sandy2008 Mar 13, 2025
9371340
Merge branch 'main' into main
sandy2008 Mar 17, 2025
1700559
Merge branch 'main' into main
sandy2008 Mar 25, 2025
b0c100f
feat(): mtls support >8.0 only
sandy2008 Mar 25, 2025
3f8f077
Merge branch 'main' of https://github.com/sandy2008/opentelemetry-dotnet
sandy2008 Mar 25, 2025
1dcbcd9
fix(): mtls certs should be internal
sandy2008 Mar 25, 2025
b251110
Merge branch 'main' into main
sandy2008 Apr 1, 2025
ef7db36
Merge branch 'main' into main
sandy2008 Apr 6, 2025
090785f
Merge branch 'main' into main
sandy2008 Apr 9, 2025
6ecc522
Update OtlpExporterOptionsExtensions.cs
sandy2008 Apr 9, 2025
0a2c60d
fix(): resolve conflict for OTel Protocol
sandy2008 Apr 9, 2025
29e4dd5
Merge branch 'main' into main
sandy2008 Apr 17, 2025
cfb0c01
feat(): support for mtls
sandy2008 Apr 18, 2025
45c4525
feat(): support for mtls
sandy2008 Apr 18, 2025
5033c4b
feat(): support for mtls
sandy2008 Apr 18, 2025
350e607
feat(): support for mtls
sandy2008 Apr 18, 2025
d76fccb
feat(): support for mtls
sandy2008 Apr 18, 2025
7ec6a5d
feat(): support for mtls
sandy2008 Apr 18, 2025
fac985e
feat(): support for mtls
sandy2008 Apr 18, 2025
d1d392f
feat(): support for mtls
sandy2008 Apr 18, 2025
0b98744
feat(): support for mtls
sandy2008 Apr 18, 2025
3a4f031
feat(): support for mtls
sandy2008 Apr 18, 2025
91ccacd
fix(): clean up doc
sandy2008 Apr 20, 2025
66eafa0
fix(): clean up doc
sandy2008 Apr 20, 2025
7003fe1
Merge branch 'main' into main
sandy2008 Apr 24, 2025
ea6c940
fix(): clean up codes
sandy2008 Apr 29, 2025
31cfe8d
Merge branch 'main' of https://github.com/sandy2008/opentelemetry-dotnet
sandy2008 Apr 29, 2025
5935f0d
fix(): clean up codes
sandy2008 Apr 29, 2025
4ffba98
fix(): clean up codes
sandy2008 Apr 29, 2025
aeacb87
fix(): clean up codes
sandy2008 Apr 29, 2025
71e19fe
fix(): clean up codes
sandy2008 Apr 29, 2025
76fa366
fix(): clean up codes
sandy2008 Apr 29, 2025
0438284
fix(): clean up codes
sandy2008 Apr 29, 2025
dbd5a05
fix(): clean up codes
sandy2008 Apr 29, 2025
f6e0577
fix(): clean up codes
sandy2008 Apr 29, 2025
6821ad1
fix(): clean up codes
sandy2008 Apr 29, 2025
3eab016
fix(): clean up codes
sandy2008 Apr 30, 2025
0b0e0c9
fix(): clean up codes
sandy2008 Apr 30, 2025
d4469f9
fix(): clean up codes
sandy2008 Apr 30, 2025
f56dc6e
Merge branch 'main' into main
sandy2008 Apr 30, 2025
4a50f64
fix(): clean up codes
sandy2008 Apr 30, 2025
b817179
Merge branch 'main' of https://github.com/sandy2008/opentelemetry-dotnet
sandy2008 Apr 30, 2025
fc41e6a
fix(): clean up codes
sandy2008 Apr 30, 2025
a69ed31
fix(): clean up codes
sandy2008 Apr 30, 2025
a27780f
fix(): clean up codes
sandy2008 Apr 30, 2025
7898d99
fix(): clean up codes
sandy2008 Apr 30, 2025
dce4bae
fix(): clean up codes
sandy2008 Apr 30, 2025
ca70e55
fix(): clean up codes
sandy2008 Apr 30, 2025
7c611b7
fix(): clean up codes
sandy2008 Apr 30, 2025
0ee5513
fix(): clean up codes
sandy2008 Apr 30, 2025
88a9f7f
fix(): clean up codes
sandy2008 Apr 30, 2025
1ecabf1
fix(): clean up codes
sandy2008 Apr 30, 2025
5d9751c
fix(): clean up codes
sandy2008 Apr 30, 2025
fc90786
Merge branch 'main' into main
sandy2008 May 14, 2025
b7c34cd
Merge branch 'main' into main
sandy2008 May 21, 2025
72912c2
fix(): fix unit test
sandy2008 May 23, 2025
0571af8
Merge branch 'main' of https://github.com/sandy2008/opentelemetry-dotnet
sandy2008 May 23, 2025
777f530
fix(): fix unit test
sandy2008 May 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
OpenTelemetry.Exporter.OtlpExporterOptions.CertificateFile.get -> string!
OpenTelemetry.Exporter.OtlpExporterOptions.CertificateFile.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.ClientCertificateFile.get -> string!
OpenTelemetry.Exporter.OtlpExporterOptions.ClientCertificateFile.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.ClientKeyFile.get -> string!
OpenTelemetry.Exporter.OtlpExporterOptions.ClientKeyFile.set -> void
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal sealed class OtlpHttpLogExportClient : BaseOtlpHttpExportClient<OtlpCol
private const string LogsExportPath = "v1/logs";

public OtlpHttpLogExportClient(OtlpExporterOptions options, HttpClient httpClient)
: base(options, httpClient, LogsExportPath)
: base(options, ModifyHttpClient(options, httpClient), LogsExportPath)
{
}

Expand All @@ -28,6 +28,26 @@ protected override HttpContent CreateHttpContent(OtlpCollector.ExportLogsService
return new ExportRequestContent(exportRequest);
}

private static HttpClient ModifyHttpClient(OtlpExporterOptions options, HttpClient httpClient)
{
// Create a new handler using the existing method that configures mTLS
var handler = options.CreateDefaultHttpMessageHandler();

// Create a new HttpClient with the mTLS-enabled handler
var newHttpClient = new HttpClient(handler, disposeHandler: true);

// Copy existing headers from the original HttpClient
foreach (var header in httpClient.DefaultRequestHeaders)
{
newHttpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
}

// Copy other properties, such as timeout, if needed
newHttpClient.Timeout = httpClient.Timeout;

return newHttpClient;
}

internal sealed class ExportRequestContent : HttpContent
{
private static readonly MediaTypeHeaderValue ProtobufMediaTypeHeader = new(MediaContentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal sealed class OtlpHttpMetricsExportClient : BaseOtlpHttpExportClient<Otl
private const string MetricsExportPath = "v1/metrics";

public OtlpHttpMetricsExportClient(OtlpExporterOptions options, HttpClient httpClient)
: base(options, httpClient, MetricsExportPath)
: base(options, ModifyHttpClient(options, httpClient), MetricsExportPath)
{
}

Expand All @@ -28,6 +28,26 @@ protected override HttpContent CreateHttpContent(OtlpCollector.ExportMetricsServ
return new ExportRequestContent(exportRequest);
}

private static HttpClient ModifyHttpClient(OtlpExporterOptions options, HttpClient httpClient)
{
// Create a new handler using the existing method that configures mTLS
var handler = options.CreateDefaultHttpMessageHandler();

// Create a new HttpClient with the mTLS-enabled handler
var newHttpClient = new HttpClient(handler, disposeHandler: true);

// Copy existing headers from the original HttpClient
foreach (var header in httpClient.DefaultRequestHeaders)
{
newHttpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
}

// Copy other properties, such as timeout, if needed
newHttpClient.Timeout = httpClient.Timeout;

return newHttpClient;
}

internal sealed class ExportRequestContent : HttpContent
{
private static readonly MediaTypeHeaderValue ProtobufMediaTypeHeader = new(MediaContentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal sealed class OtlpHttpTraceExportClient : BaseOtlpHttpExportClient<OtlpC
private const string TracesExportPath = "v1/traces";

public OtlpHttpTraceExportClient(OtlpExporterOptions options, HttpClient httpClient)
: base(options, httpClient, TracesExportPath)
: base(options, ModifyHttpClient(options, httpClient), TracesExportPath)
{
}

Expand All @@ -28,6 +28,26 @@ protected override HttpContent CreateHttpContent(OtlpCollector.ExportTraceServic
return new ExportRequestContent(exportRequest);
}

private static HttpClient ModifyHttpClient(OtlpExporterOptions options, HttpClient httpClient)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't just throw away the HttpClient and make a new one. Users are able to configure SSL/TLS today using factory:

This change will break any user doing that or doing anything else to the HttpClient they are intending to use here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified a little bit, does it look fine? @CodeBlanch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the design looks ok, I will start to write tests :)

{
// Create a new handler using the existing method that configures mTLS
var handler = options.CreateDefaultHttpMessageHandler();

// Create a new HttpClient with the mTLS-enabled handler
var newHttpClient = new HttpClient(handler, disposeHandler: true);

// Copy existing headers from the original HttpClient
foreach (var header in httpClient.DefaultRequestHeaders)
{
newHttpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
}

// Copy other properties, such as timeout, if needed
newHttpClient.Timeout = httpClient.Timeout;

return newHttpClient;
}

internal sealed class ExportRequestContent : HttpContent
{
private static readonly MediaTypeHeaderValue ProtobufMediaTypeHeader = new(MediaContentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
using OpenTelemetry.Internal;
using OpenTelemetry.Trace;
#if NET6_0_OR_GREATER
using System.Security.Cryptography.X509Certificates;
#endif

namespace OpenTelemetry.Exporter;

Expand All @@ -27,6 +30,9 @@
internal const string DefaultGrpcEndpoint = "http://localhost:4317";
internal const string DefaultHttpEndpoint = "http://localhost:4318";
internal const OtlpExportProtocol DefaultOtlpExportProtocol = OtlpExportProtocol.Grpc;
internal const string CertificateFileEnvVarName = "OTEL_EXPORTER_OTLP_CERTIFICATE";
internal const string ClientKeyFileEnvVarName = "OTEL_EXPORTER_OTLP_CLIENT_KEY";
internal const string ClientCertificateFileEnvVarName = "OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE";

internal static readonly KeyValuePair<string, string>[] StandardHeaders = new KeyValuePair<string, string>[]
{
Expand Down Expand Up @@ -75,6 +81,36 @@
};

this.BatchExportProcessorOptions = defaultBatchOptions!;

// Load CertificateFile from environment variable
if (Environment.GetEnvironmentVariable(CertificateFileEnvVarName) is string certificateFile)
{
this.CertificateFile = certificateFile;
}
else
{
this.CertificateFile = string.Empty;
}

// Load ClientKeyFile from environment variable
if (Environment.GetEnvironmentVariable(ClientKeyFileEnvVarName) is string clientKeyFile)
{
this.ClientKeyFile = clientKeyFile;
}
else
{
this.ClientKeyFile = string.Empty;
}

// Load ClientCertificateFile from environment variable
if (Environment.GetEnvironmentVariable(ClientCertificateFileEnvVarName) is string clientCertificateFile)
{
this.ClientCertificateFile = clientCertificateFile;
}
else
{
this.ClientCertificateFile = string.Empty;
}
}

/// <inheritdoc/>
Expand Down Expand Up @@ -142,6 +178,21 @@
}
}

/// <summary>
/// Gets or sets the trusted certificate to use when verifying a server's TLS credentials.
/// </summary>
public string CertificateFile { get; set; }

/// <summary>
/// Gets or sets the path to the private key to use in mTLS communication in PEM format.
/// </summary>
public string ClientKeyFile { get; set; }

/// <summary>
/// Gets or sets the path to the certificate/chain trust for client's private key to use in mTLS communication in PEM format.
/// </summary>
public string ClientCertificateFile { get; set; }

/// <summary>
/// Gets a value indicating whether or not the signal-specific path should
/// be appended to <see cref="Endpoint"/>.
Expand Down Expand Up @@ -220,6 +271,37 @@
return this;
}

internal HttpMessageHandler CreateDefaultHttpMessageHandler()
{
var handler = new HttpClientHandler();

#if NET6_0_OR_GREATER
if (!string.IsNullOrEmpty(this.CertificateFile))
{
var trustedCertificate = new X509Certificate2(this.CertificateFile);

Check failure on line 281 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net9.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 281 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net8.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 281 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net8.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 281 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net9.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 281 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 281 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 281 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 281 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 281 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 281 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 281 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 281 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 281 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 281 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a custom server certificate validation callback can introduce security risks if not handled properly. Can you list what measures have been taken to mitigate potential risks, such as unintended trust, proper error handling, revocation checks, and restricting trust scope?

{
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net9.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net9.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net8.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net8.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net8.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net8.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net9.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net9.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Dereference of a possibly null reference.

Check failure on line 285 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Dereference of a possibly null reference.
chain.ChainPolicy.CustomTrustStore.Add(trustedCertificate);
return chain.Build(cert);

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net8.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net8.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net8.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net8.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 287 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.
};
}

if (!string.IsNullOrEmpty(this.ClientCertificateFile) && !string.IsNullOrEmpty(this.ClientKeyFile))
{
var clientCertificate = X509Certificate2.CreateFromPemFile(this.ClientCertificateFile, this.ClientKeyFile);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading a client certificate from a PEM file with a private key should be done cautiously. How do you ensure or inform customers that the private key file should be stored securely and access-restricted?

handler.ClientCertificates.Add(clientCertificate);
}
#else
// Implement alternative methods for earlier .NET versions
throw new PlatformNotSupportedException("mTLS support requires .NET 6.0 or later.");
#endif

#pragma warning disable CS0162 // Unreachable code detected
return handler;
}

private static string GetUserAgentString()
{
var assembly = typeof(OtlpExporterOptions).Assembly;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
using LogOtlpCollector = OpenTelemetry.Proto.Collector.Logs.V1;
using MetricsOtlpCollector = OpenTelemetry.Proto.Collector.Metrics.V1;
using TraceOtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1;
#if NET6_0_OR_GREATER
using System.Security.Cryptography.X509Certificates;
#endif

namespace OpenTelemetry.Exporter;

Expand All @@ -33,7 +36,36 @@
throw new NotSupportedException($"Endpoint URI scheme ({options.Endpoint.Scheme}) is not supported. Currently only \"http\" and \"https\" are supported.");
}

#if NETSTANDARD2_1 || NET
#if NET6_0_OR_GREATER
var handler = new HttpClientHandler();

// Set up custom certificate validation if CertificateFile is provided
if (!string.IsNullOrEmpty(options.CertificateFile))
{
var trustedCertificate = new X509Certificate2(options.CertificateFile);

Check failure on line 45 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net9.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 45 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net8.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 45 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net8.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 45 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net9.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 45 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 45 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 45 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 45 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 45 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 45 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 45 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 45 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 45 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)

Check failure on line 45 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

'X509Certificate2.X509Certificate2(string)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)
handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) =>
{
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net9.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net9.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net8.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net8.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net8.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net8.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net9.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net9.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Dereference of a possibly null reference.

Check failure on line 48 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Dereference of a possibly null reference.
chain.ChainPolicy.CustomTrustStore.Add(trustedCertificate);
return chain.Build(cert);

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net8.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net8.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net8.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-latest, net8.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-latest, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.

Check failure on line 50 in src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Possible null reference argument for parameter 'certificate' in 'bool X509Chain.Build(X509Certificate2 certificate)'.
};
}

// Set up client certificate if provided
if (!string.IsNullOrEmpty(options.ClientCertificateFile) && !string.IsNullOrEmpty(options.ClientKeyFile))
{
var clientCertificate = X509Certificate2.CreateFromPemFile(options.ClientCertificateFile, options.ClientKeyFile);
handler.ClientCertificates.Add(clientCertificate);
}

var grpcChannelOptions = new GrpcChannelOptions
{
HttpHandler = handler,
DisposeHttpClient = true,
};

return GrpcChannel.ForAddress(options.Endpoint, grpcChannelOptions);
#elif NETSTANDARD2_1 || NET
return GrpcChannel.ForAddress(options.Endpoint);
#else
ChannelCredentials channelCredentials;
Expand Down
Loading