-
Notifications
You must be signed in to change notification settings - Fork 890
Expand file tree
/
Copy pathOtlpHttpExportClient.cs
More file actions
52 lines (44 loc) · 2.17 KB
/
OtlpHttpExportClient.cs
File metadata and controls
52 lines (44 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NETFRAMEWORK
using System.Net.Http;
#endif
using System.Net.Http.Headers;
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient;
/// <summary>Class for sending OTLP trace export request over HTTP.</summary>
internal sealed class OtlpHttpExportClient : OtlpExportClient
{
internal static readonly MediaTypeHeaderValue MediaHeaderValue = new("application/x-protobuf");
private static readonly ExportClientHttpResponse SuccessExportResponse = new(success: true, deadlineUtc: default, response: null, exception: null);
internal OtlpHttpExportClient(OtlpExporterOptions options, HttpClient httpClient, string signalPath)
: base(options, httpClient, signalPath)
{
}
internal override MediaTypeHeaderValue MediaTypeHeader => MediaHeaderValue;
/// <inheritdoc/>
public override ExportClientResponse SendExportRequest(byte[] buffer, int contentLength, DateTime deadlineUtc, CancellationToken cancellationToken = default)
{
try
{
using var httpRequest = this.CreateHttpRequest(buffer, contentLength);
using var httpResponse = this.SendHttpRequest(httpRequest, cancellationToken);
try
{
httpResponse.EnsureSuccessStatusCode();
}
catch (HttpRequestException ex)
{
var response = TryGetResponseBody(httpResponse, cancellationToken);
OpenTelemetryProtocolExporterEventSource.Log.HttpRequestFailed(this.Endpoint, response, ex);
return new ExportClientHttpResponse(success: false, deadlineUtc: deadlineUtc, response: httpResponse, ex);
}
OpenTelemetryProtocolExporterEventSource.Log.ExportSuccess(this.Endpoint, "Export completed successfully.");
return SuccessExportResponse;
}
catch (HttpRequestException ex)
{
OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Endpoint, ex);
return new ExportClientHttpResponse(success: false, deadlineUtc: deadlineUtc, response: null, exception: ex);
}
}
}