using EonaCat.LogStack.Core;
using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace EonaCat.LogStack.Boosters;

// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/License for full license details.

/// <summary>
/// Adds correlation ID from Activity or custom source
/// </summary>
public sealed class CorrelationIdBooster : BoosterBase
{
    public CorrelationIdBooster() : base("CorrelationId") { }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public override bool Boost(ref LogEventBuilder builder)
    {
        var activity = Activity.Current;
        if (activity != null)
        {
            builder.WithProperty("CorrelationId", activity.Id ?? activity.TraceId.ToString());
        }
        return true;
    }
}
