Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[otlp] Add mTLS Support for OTLP Exporter #5918

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 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
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) =>
{
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);
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