-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'user/kcoulombe/HandleMeterDisposal' of https://github.c…
…om/stonkie/opentelemetry-dotnet into user/kcoulombe/HandleMeterDisposal
- Loading branch information
Showing
17 changed files
with
301 additions
and
1,026 deletions.
There are no files selected for viewing
445 changes: 0 additions & 445 deletions
445
src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs
This file was deleted.
Oops, something went wrong.
45 changes: 0 additions & 45 deletions
45
...y.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs
This file was deleted.
Oops, something went wrong.
69 changes: 0 additions & 69 deletions
69
...y.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpHttpTraceExportClient.cs
This file was deleted.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
...ry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/ProtobufOtlpExportClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#if NETFRAMEWORK | ||
using System.Net.Http; | ||
#endif | ||
using System.Net.Http.Headers; | ||
using OpenTelemetry.Internal; | ||
|
||
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; | ||
|
||
internal abstract class ProtobufOtlpExportClient : IProtobufExportClient | ||
{ | ||
private static readonly Version Http2RequestVersion = new(2, 0); | ||
|
||
#if NET | ||
private static readonly bool SynchronousSendSupportedByCurrentPlatform; | ||
|
||
static ProtobufOtlpExportClient() | ||
{ | ||
#if NET | ||
// See: https://github.com/dotnet/runtime/blob/280f2a0c60ce0378b8db49adc0eecc463d00fe5d/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.cs#L767 | ||
SynchronousSendSupportedByCurrentPlatform = !OperatingSystem.IsAndroid() | ||
&& !OperatingSystem.IsIOS() | ||
&& !OperatingSystem.IsTvOS() | ||
&& !OperatingSystem.IsBrowser(); | ||
#endif | ||
} | ||
#endif | ||
|
||
protected ProtobufOtlpExportClient(OtlpExporterOptions options, HttpClient httpClient, string signalPath) | ||
{ | ||
Guard.ThrowIfNull(options); | ||
Guard.ThrowIfNull(httpClient); | ||
Guard.ThrowIfNull(signalPath); | ||
|
||
Uri exporterEndpoint = options.Endpoint.AppendPathIfNotPresent(signalPath); | ||
this.Endpoint = new UriBuilder(exporterEndpoint).Uri; | ||
this.Headers = options.GetHeaders<Dictionary<string, string>>((d, k, v) => d.Add(k, v)); | ||
this.HttpClient = httpClient; | ||
} | ||
|
||
internal HttpClient HttpClient { get; } | ||
|
||
internal Uri Endpoint { get; } | ||
|
||
internal IReadOnlyDictionary<string, string> Headers { get; } | ||
|
||
internal abstract MediaTypeHeaderValue MediaTypeHeader { get; } | ||
|
||
internal virtual bool RequireHttp2 => false; | ||
|
||
public abstract ExportClientResponse SendExportRequest(byte[] buffer, int contentLength, DateTime deadlineUtc, CancellationToken cancellationToken = default); | ||
|
||
/// <inheritdoc/> | ||
public bool Shutdown(int timeoutMilliseconds) | ||
{ | ||
this.HttpClient.CancelPendingRequests(); | ||
return true; | ||
} | ||
|
||
protected HttpRequestMessage CreateHttpRequest(byte[] buffer, int contentLength) | ||
{ | ||
var request = new HttpRequestMessage(HttpMethod.Post, this.Endpoint); | ||
|
||
if (this.RequireHttp2) | ||
{ | ||
request.Version = Http2RequestVersion; | ||
|
||
#if NET6_0_OR_GREATER | ||
request.VersionPolicy = HttpVersionPolicy.RequestVersionExact; | ||
#endif | ||
} | ||
|
||
foreach (var header in this.Headers) | ||
{ | ||
request.Headers.Add(header.Key, header.Value); | ||
} | ||
|
||
// TODO: Support compression. | ||
|
||
request.Content = new ByteArrayContent(buffer, 0, contentLength); | ||
request.Content.Headers.ContentType = this.MediaTypeHeader; | ||
|
||
return request; | ||
} | ||
|
||
protected HttpResponseMessage SendHttpRequest(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
#if NET | ||
// Note: SendAsync must be used with HTTP/2 because synchronous send is | ||
// not supported. | ||
return this.RequireHttp2 || !SynchronousSendSupportedByCurrentPlatform | ||
? this.HttpClient.SendAsync(request, cancellationToken).GetAwaiter().GetResult() | ||
: this.HttpClient.Send(request, cancellationToken); | ||
#else | ||
return this.HttpClient.SendAsync(request, cancellationToken).GetAwaiter().GetResult(); | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.