-
Notifications
You must be signed in to change notification settings - Fork 790
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
[Exporter.OpenTelemetryProtocol] Clients for profiling exporter #5759
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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
45 changes: 45 additions & 0 deletions
45
...xporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcProfilesExportClient.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,45 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using Grpc.Core; | ||
using OtlpCollector = OpenTelemetry.Proto.Collector.Profiles.V1Experimental; | ||
|
||
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; | ||
|
||
/// <summary>Class for sending OTLP Logs export request over gRPC.</summary> | ||
internal sealed class OtlpGrpcProfilesExportClient : BaseOtlpGrpcExportClient<OtlpCollector.ExportProfilesServiceRequest> | ||
{ | ||
private readonly OtlpCollector.ProfilesService.ProfilesServiceClient profilesClient; | ||
|
||
public OtlpGrpcProfilesExportClient(OtlpExporterOptions options, OtlpCollector.ProfilesService.ProfilesServiceClient? profilesServiceClient = null) | ||
: base(options) | ||
{ | ||
if (profilesServiceClient != null) | ||
{ | ||
this.profilesClient = profilesServiceClient; | ||
} | ||
else | ||
{ | ||
this.Channel = options.CreateChannel(); | ||
this.profilesClient = new OtlpCollector.ProfilesService.ProfilesServiceClient(this.Channel); | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override ExportClientResponse SendExportRequest(OtlpCollector.ExportProfilesServiceRequest request, DateTime deadlineUtc, CancellationToken cancellationToken = default) | ||
{ | ||
try | ||
{ | ||
this.profilesClient.Export(request, headers: this.Headers, deadline: deadlineUtc, cancellationToken: cancellationToken); | ||
|
||
// We do not need to return back response and deadline for successful response so using cached value. | ||
return SuccessExportResponse; | ||
} | ||
catch (RpcException ex) | ||
{ | ||
OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Endpoint, ex); | ||
|
||
return new ExportClientGrpcResponse(success: false, deadlineUtc: deadlineUtc, exception: ex); | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...xporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpHttpProfilesExportClient.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,69 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System.Net; | ||
#if NETFRAMEWORK | ||
using System.Net.Http; | ||
#endif | ||
using System.Net.Http.Headers; | ||
using System.Runtime.CompilerServices; | ||
using Google.Protobuf; | ||
using OtlpCollector = OpenTelemetry.Proto.Collector.Profiles.V1Experimental; | ||
|
||
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; | ||
|
||
/// <summary>Class for sending OTLP log export request over HTTP.</summary> | ||
internal sealed class OtlpHttpProfilesExportClient : BaseOtlpHttpExportClient<OtlpCollector.ExportProfilesServiceRequest> | ||
{ | ||
internal const string MediaContentType = "application/x-protobuf"; | ||
private const string LogsExportPath = "v1experimental/profiles"; | ||
|
||
public OtlpHttpProfilesExportClient(OtlpExporterOptions options, HttpClient httpClient) | ||
: base(options, httpClient, LogsExportPath) | ||
{ | ||
} | ||
|
||
protected override HttpContent CreateHttpContent(OtlpCollector.ExportProfilesServiceRequest exportRequest) | ||
{ | ||
return new ExportRequestContent(exportRequest); | ||
} | ||
|
||
internal sealed class ExportRequestContent : HttpContent | ||
{ | ||
private static readonly MediaTypeHeaderValue ProtobufMediaTypeHeader = new(MediaContentType); | ||
|
||
private readonly OtlpCollector.ExportProfilesServiceRequest exportRequest; | ||
|
||
public ExportRequestContent(OtlpCollector.ExportProfilesServiceRequest exportRequest) | ||
{ | ||
this.exportRequest = exportRequest; | ||
this.Headers.ContentType = ProtobufMediaTypeHeader; | ||
} | ||
|
||
#if NET | ||
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 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Kielek - What all things you would need to copy if we don't do this?