Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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,37 @@ 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
{
GenevaAfdCorrelationIdStateTracker.Set(true);
return null;
}
}
}
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