-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into aws-instrumentation-ci-updates
- Loading branch information
Showing
8 changed files
with
483 additions
and
12 deletions.
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
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
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
70 changes: 70 additions & 0 deletions
70
src/OpenTelemetry.Exporter.Geneva/Metrics/Transport/MetricUnixUserEventsDataTransport.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,70 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#if NET | ||
|
||
#nullable enable | ||
|
||
using System.Text; | ||
using Microsoft.LinuxTracepoints.Provider; | ||
|
||
namespace OpenTelemetry.Exporter.Geneva; | ||
|
||
internal sealed class MetricUnixUserEventsDataTransport : IMetricDataTransport | ||
{ | ||
public const uint MetricsProtocol = 0U; | ||
public const string MetricsVersion = "v0.19.00"; | ||
public const string MetricsTracepointName = "otlp_metrics"; | ||
public const string MetricsTracepointNameArgs = $"{MetricsTracepointName} u32 protocol;char[8] version;__rel_loc u8[] buffer"; | ||
|
||
private static readonly ReadOnlyMemory<byte> MetricsVersionUtf8 = Encoding.UTF8.GetBytes(MetricsVersion); | ||
private readonly PerfTracepoint metricsTracepoint; | ||
|
||
private MetricUnixUserEventsDataTransport() | ||
{ | ||
this.metricsTracepoint = new PerfTracepoint(MetricsTracepointNameArgs); | ||
if (this.metricsTracepoint.RegisterResult != 0) | ||
{ | ||
// ENOENT (2): No such file or directory | ||
if (this.metricsTracepoint.RegisterResult == 2) | ||
{ | ||
throw new NotSupportedException( | ||
$"Tracepoint registration for 'otlp_metrics' failed with result: '{this.metricsTracepoint.RegisterResult}'. Verify your distribution/kernel supports user_events: https://docs.kernel.org/trace/user_events.html."); | ||
} | ||
|
||
ExporterEventSource.Log.TransportInformation( | ||
nameof(MetricUnixUserEventsDataTransport), | ||
$"Tracepoint registration operation for 'otlp_metrics' returned result '{this.metricsTracepoint.RegisterResult}' which is considered recoverable. Entering running state."); | ||
} | ||
} | ||
|
||
public static MetricUnixUserEventsDataTransport Instance { get; } = new(); | ||
|
||
public void Send(MetricEventType eventType, byte[] body, int size) | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
|
||
public void SendOtlpProtobufEvent(byte[] body, int size) | ||
{ | ||
if (this.metricsTracepoint.IsEnabled) | ||
{ | ||
var buffer = new ReadOnlySpan<byte>(body, 0, size); | ||
|
||
var bufferRelLoc = 0u | ((uint)buffer.Length << 16); | ||
|
||
this.metricsTracepoint.Write( | ||
[MetricsProtocol], | ||
MetricsVersionUtf8.Span, | ||
[bufferRelLoc], | ||
buffer); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
this.metricsTracepoint.Dispose(); | ||
} | ||
} | ||
|
||
#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.