-
Notifications
You must be signed in to change notification settings - Fork 882
OtlpExporter: HttpClientFactory option #2696
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
Merged
cijothomas
merged 14 commits into
open-telemetry:main
from
CodeBlanch:otlp-httpclientfactory
Nov 29, 2021
Merged
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d81ad82
Working on exposing HttpClientFactory option in OtlpExporter project.
CodeBlanch 2d58ec4
Added OtlpHttpMetricsExportClient. Added unit tests.
CodeBlanch 836a51c
CHANGELOG update.
CodeBlanch dc9b2f9
Merging latest from main.
CodeBlanch e693a06
Merge fixes.
CodeBlanch caae1e4
Cleanup.
CodeBlanch 26a29b2
README update.
CodeBlanch 2ed9802
Merge branch 'main' into otlp-httpclientfactory
cijothomas fb0fd85
Code review.
CodeBlanch 8bdf9d2
Merge branch 'otlp-httpclientfactory' of https://github.com/CodeBlanc…
CodeBlanch f173f5e
Merge branch 'main' into otlp-httpclientfactory
cijothomas 4b34af1
Merge branch 'main' into otlp-httpclientfactory
CodeBlanch 29e20d1
Code review.
CodeBlanch dc3c21a
Merge branch 'main' into otlp-httpclientfactory
cijothomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
96 changes: 96 additions & 0 deletions
96
...Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpHttpMetricsExportClient.cs
This file contains hidden or 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,96 @@ | ||
| // <copyright file="OtlpHttpMetricsExportClient.cs" company="OpenTelemetry Authors"> | ||
| // Copyright The OpenTelemetry Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // </copyright> | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Net.Http.Headers; | ||
| using System.Runtime.CompilerServices; | ||
| #if NET5_0_OR_GREATER | ||
| using System.Threading; | ||
| #endif | ||
| using System.Threading.Tasks; | ||
| using Google.Protobuf; | ||
| using OtlpCollector = Opentelemetry.Proto.Collector.Metrics.V1; | ||
|
|
||
| namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient | ||
| { | ||
| /// <summary>Class for sending OTLP metrics export request over HTTP.</summary> | ||
| internal sealed class OtlpHttpMetricsExportClient : BaseOtlpHttpExportClient<OtlpCollector.ExportMetricsServiceRequest> | ||
| { | ||
| internal const string MediaContentType = "application/x-protobuf"; | ||
| private readonly Uri exportMetricsUri; | ||
|
|
||
| public OtlpHttpMetricsExportClient(OtlpExporterOptions options, HttpClient httpClient) | ||
| : base(options, httpClient) | ||
| { | ||
| this.exportMetricsUri = this.Options.Endpoint; | ||
| } | ||
|
|
||
| protected override HttpRequestMessage CreateHttpRequest(OtlpCollector.ExportMetricsServiceRequest exportRequest) | ||
| { | ||
| var request = new HttpRequestMessage(HttpMethod.Post, this.exportMetricsUri); | ||
| foreach (var header in this.Headers) | ||
| { | ||
| request.Headers.Add(header.Key, header.Value); | ||
| } | ||
|
|
||
| request.Content = new ExportRequestContent(exportRequest); | ||
|
|
||
| return request; | ||
| } | ||
|
|
||
| internal sealed class ExportRequestContent : HttpContent | ||
| { | ||
| private static readonly MediaTypeHeaderValue ProtobufMediaTypeHeader = new MediaTypeHeaderValue(MediaContentType); | ||
|
|
||
| private readonly OtlpCollector.ExportMetricsServiceRequest exportRequest; | ||
|
|
||
| public ExportRequestContent(OtlpCollector.ExportMetricsServiceRequest exportRequest) | ||
| { | ||
| this.exportRequest = exportRequest; | ||
| this.Headers.ContentType = ProtobufMediaTypeHeader; | ||
| } | ||
|
|
||
| #if NET5_0_OR_GREATER | ||
| protected override void SerializeToStream(Stream stream, TransportContext context, CancellationToken cancellationToken) | ||
| { | ||
| this.SerializeToStreamInternal(stream); | ||
| } | ||
| #endif | ||
|
|
||
| protected override Task SerializeToStreamAsync(Stream stream, TransportContext context) | ||
| { | ||
| this.SerializeToStreamInternal(stream); | ||
| return Task.CompletedTask; | ||
| } | ||
|
|
||
| protected override bool TryComputeLength(out long length) | ||
| { | ||
| // We can't know the length of the content being pushed to the output stream. | ||
| length = -1; | ||
| return false; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| private void SerializeToStreamInternal(Stream stream) | ||
| { | ||
| this.exportRequest.WriteTo(stream); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.