Skip to content
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

[geneva] Add support for exporting otlp metrics via user_events on Linux #2113

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7fe894e
Support export of metrics via user_events on Linux.
CodeBlanch Sep 26, 2024
470d0c9
Tweak.
CodeBlanch Sep 26, 2024
395fe67
Tweak.
CodeBlanch Sep 26, 2024
7a6f003
Tweaks and test implementation.
CodeBlanch Sep 27, 2024
df6b1f0
CHANGELOG patch.
CodeBlanch Sep 27, 2024
7d5f8b8
Merge from main.
CodeBlanch Sep 30, 2024
4841357
Tweak.
CodeBlanch Sep 30, 2024
80bedb3
Fixes.
CodeBlanch Sep 30, 2024
e5c67f7
Merge from main.
CodeBlanch Oct 1, 2024
f86b41f
Merge remote-tracking branch 'upstream/main' into geneva-metric-user_…
CodeBlanch Oct 1, 2024
6e2e027
Fix.
CodeBlanch Oct 1, 2024
94f2970
Merge remote-tracking branch 'upstream/main' into geneva-metric-user_…
CodeBlanch Oct 3, 2024
f0d78b3
Merge remote-tracking branch 'upstream/main' into geneva-metric-user_…
CodeBlanch Oct 7, 2024
26ad46e
Code review.
CodeBlanch Oct 7, 2024
f1a0d90
Tweaks.
CodeBlanch Oct 7, 2024
0c5ed5a
Add a step for verifying user_events are available in tests.
CodeBlanch Oct 8, 2024
6bd6b17
Merge branch 'main' into geneva-metric-user_event-transport
CodeBlanch Oct 10, 2024
22af231
Code review.
CodeBlanch Oct 11, 2024
cc07953
Code review and doc updates.
CodeBlanch Oct 11, 2024
6fbf465
Merge branch 'main' into geneva-metric-user_event-transport
CodeBlanch Oct 11, 2024
7adda1d
Merge branch 'main' into geneva-metric-user_event-transport
CodeBlanch Oct 11, 2024
75583cd
Code review.
CodeBlanch Oct 11, 2024
10d66cf
Nits.
CodeBlanch Oct 11, 2024
0dd12ce
Merge branch 'main' into geneva-metric-user_event-transport
CodeBlanch Oct 11, 2024
ca92300
Tweak.
CodeBlanch Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
* Drop support for .NET 6 as this target is no longer supported.
([#2117](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2117))

* Added support for exporting metrics via
[user_events](https://docs.kernel.org/trace/user_events.html) on Linux when
OTLP protobuf encoding is enabled via the
`PrivatePreviewEnableOtlpProtobufEncoding=true` connection string switch.
([#2113](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2113))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this, PrivatePreviewEnableOtlpProtobufEncoding=true is now supported in both Widows and Linux. Windows uses ETW as transport, while Linux uses user-events as transport.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodeBlanch can you add this to changelog before merge

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated CHANGELOG and REDME where this stuff was mentioned


## 1.9.0

Released 2024-Jun-21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ internal sealed class ExporterEventSource : EventSource
private const int EVENT_ID_ERROR = 4; // Other common exporter exceptions
private const int EVENT_ID_OTLP_PROTOBUF_METRIC = 5; // Failed to serialize metric
private const int EVENT_ID_COMPLETED_EXPORT = 6; // Completed export
private const int EVENT_ID_TRANSPORT_ERROR = 7; // Transport error
private const int EVENT_ID_TRANSPORT_EXCEPTION = 8; // Transport exception

[NonEvent]
public void FailedToSendTraceData(Exception ex)
Expand Down Expand Up @@ -76,6 +78,16 @@ public void FailedToSerializeMetric(string metricName, Exception ex)
}
}

[NonEvent]
public void TransportException(string transportType, string message, Exception ex)
{
if (Log.IsEnabled(EventLevel.Error, EventKeywords.All))
{
// TODO: Do not hit ETW size limit even for external library exception stack.
this.TransportException(transportType, message, ex.ToInvariantString());
}
}

[Event(EVENT_ID_TRACE, Message = "Exporter failed to send trace data. Exception: {0}", Level = EventLevel.Error)]
public void FailedToSendTraceData(string error)
{
Expand Down Expand Up @@ -111,4 +123,16 @@ public void ExportCompleted(string exporterName)
{
this.WriteEvent(EVENT_ID_COMPLETED_EXPORT, exporterName);
}

[Event(EVENT_ID_TRANSPORT_ERROR, Message = "Transport '{0}' error. Message: {1}", Level = EventLevel.Error)]
public void TransportError(string transportType, string error)
{
this.WriteEvent(EVENT_ID_TRANSPORT_ERROR, transportType, error);
}

[Event(EVENT_ID_TRANSPORT_EXCEPTION, Message = "Transport '{0}' error. Message: {1}, Exception: {2}", Level = EventLevel.Error)]
public void TransportException(string transportType, string error, string ex)
{
this.WriteEvent(EVENT_ID_TRANSPORT_EXCEPTION, transportType, error, ex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private bool Connect()
}
catch (Exception ex)
{
ExporterEventSource.Log.ExporterException("UDS Connect failed.", ex);
ExporterEventSource.Log.TransportException(nameof(UnixDomainSocketDataTransport), "Connection failure", ex);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Include something like "will retry connecting in background", to indicate this may be recovered.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics;
using System.Runtime.InteropServices;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
Expand All @@ -15,17 +16,32 @@ internal sealed class OtlpProtobufMetricExporter : IDisposable

private readonly Func<Resource> getResource;

public OtlpProtobufMetricExporter(Func<Resource> getResource, ConnectionStringBuilder connectionStringBuilder, IReadOnlyDictionary<string, object> prepopulatedMetricDimensions)
public OtlpProtobufMetricExporter(
Func<Resource> getResource,
ConnectionStringBuilder connectionStringBuilder,
IReadOnlyDictionary<string, object> prepopulatedMetricDimensions)
{
Debug.Assert(getResource != null, "getResource was null");

this.getResource = getResource;

#if NET6_0_OR_GREATER
IMetricDataTransport transport = !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? MetricUnixUserEventsDataTransport.Instance
: MetricWindowsEventTracingDataTransport.Instance;
#else
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Temporary until we add support for user_events.
throw new NotSupportedException("Exporting data in protobuf format is not supported on Linux.");
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
}

this.getResource = getResource;
var transport = MetricWindowsEventTracingDataTransport.Instance;
#endif

this.otlpProtobufSerializer = new OtlpProtobufSerializer(MetricWindowsEventTracingDataTransport.Instance, connectionStringBuilder, prepopulatedMetricDimensions);
this.otlpProtobufSerializer = new OtlpProtobufSerializer(
transport,
connectionStringBuilder,
prepopulatedMetricDimensions);
}

public ExportResult Export(in Batch<Metric> batch)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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)
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
{
ExporterEventSource.Log.TransportError(
nameof(MetricUnixUserEventsDataTransport),
$"Tracepoint for 'otlp_metrics' user events could not be registered: '{this.metricsTracepoint.RegisterResult}'");
CodeBlanch marked this conversation as resolved.
Show resolved Hide resolved
}
}

public static MetricUnixUserEventsDataTransport Instance { get; } = new();
cijothomas marked this conversation as resolved.
Show resolved Hide resolved

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);
}
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
}

public void Dispose()
{
this.metricsTracepoint.Dispose();
}
}

#endif
Loading
Loading