Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* Fixed an issue where accessing an unset `AFDCorrelationId` in `RuntimeContext`
would throw unhandled exceptions.
([#2708](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2708))

## 1.11.2

Released 2025-Apr-16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ namespace OpenTelemetry.Exporter.Geneva;
internal class AFDCorrelationIdLogProcessor : BaseProcessor<LogRecord>
{
private const string AFDCorrelationId = "AFDCorrelationId";
private const string AFDSlotAccessTrackerId = "GenevaAfdCorrelationIdStateTracker";
private static readonly RuntimeContextSlot<bool> GenevaAfdCorrelationIdStateTracker = RuntimeContext.RegisterSlot<bool>(AFDSlotAccessTrackerId);
private bool disposed;

public AFDCorrelationIdLogProcessor()
{
GenevaAfdCorrelationIdStateTracker.Set(false);
}

/// <inheritdoc/>
public override void OnEnd(LogRecord data)
Expand Down Expand Up @@ -42,6 +50,38 @@ public override void OnEnd(LogRecord data)
base.OnEnd(data);
}

protected override void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
GenevaAfdCorrelationIdStateTracker.Dispose();
}

this.disposed = true;
}

base.Dispose(disposing);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static string? GetRuntimeContextValue() => RuntimeContext.GetValue<string>(AFDCorrelationId);
private static string? GetRuntimeContextValue()
{
if (GenevaAfdCorrelationIdStateTracker.Get() == true)
{
return null;
}

try
{
return RuntimeContext.GetValue<string>(AFDCorrelationId);
}
catch (Exception ex)
{
ExporterEventSource.Log.FailedToGetAFDCorrelationId(ex);
GenevaAfdCorrelationIdStateTracker.Set(true);
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal sealed class ExporterEventSource : EventSource
private const int EVENT_ID_TRANSPORT_ERROR = 7; // Transport error
private const int EVENT_ID_TRANSPORT_EXCEPTION = 8; // Transport exception
private const int EVENT_ID_TRANSPORT_INFO = 9; // Transport info
private const int EVENT_ID_AFD_CORRELATION_ID = 10; // Failed to get AFD correlation ID

[NonEvent]
public void FailedToSendTraceData(Exception ex)
Expand Down Expand Up @@ -87,6 +88,16 @@ public void TransportException(string transportType, string message, Exception e
}
}

[NonEvent]
public void FailedToGetAFDCorrelationId(Exception ex)
{
if (Log.IsEnabled(EventLevel.Error, EventKeywords.All))
{
// TODO: Do not hit ETW size limit even for external library exception stack.
this.FailedToGetAFDCorrelationId(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 @@ -140,4 +151,10 @@ public void TransportInformation(string transportType, string error)
{
this.WriteEvent(EVENT_ID_TRANSPORT_INFO, transportType, error);
}

[Event(EVENT_ID_AFD_CORRELATION_ID, Message = "Failed to get AFD correlation ID. Exception: {0}", Level = EventLevel.Error)]
public void FailedToGetAFDCorrelationId(string error)
{
this.WriteEvent(EVENT_ID_AFD_CORRELATION_ID, error);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using Xunit;

namespace OpenTelemetry.Exporter.Geneva.Tests;

[CollectionDefinition(nameof(GenevaCorrelationFixture))]
public class GenevaCorrelationFixture : ICollectionFixture<GenevaCorrelationFixture>
{
}
Loading
Loading