Skip to content

Commit

Permalink
add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshnj committed Dec 17, 2024
1 parent ad0aa60 commit eabf0b0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tracer/src/Datadog.Trace/LibDatadog/TraceExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,27 @@
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Datadog.Trace.Agent;
using Datadog.Trace.Logging;

namespace Datadog.Trace.LibDatadog;

internal class TraceExporter : SafeHandle, IApi
{
private static readonly IDatadogLogger StaticLog = DatadogLogging.GetLoggerFor<TraceExporter>();

private readonly TraceExporterConfiguration _configuration;
private readonly IDatadogLogger _log;

public TraceExporter(TraceExporterConfiguration configuration)
public TraceExporter(
TraceExporterConfiguration configuration,
IDatadogLogger log = null)
: base(IntPtr.Zero, true)
{
_log = log ?? StaticLog;
_configuration = configuration;
var errPtr = TraceExporterNative.ddog_trace_exporter_new(out var ptr, configuration);

_log.Debug("Creating new TraceExporter");
var errPtr = TraceExporterNative.ddog_trace_exporter_new(out var ptr, _configuration);
errPtr.ThrowIfError();
SetHandle(ptr);
}
Expand All @@ -27,6 +36,8 @@ public TraceExporter(TraceExporterConfiguration configuration)

public Task<bool> SendTracesAsync(ArraySegment<byte> traces, int numberOfTraces, bool statsComputationEnabled, long numberOfDroppedP0Traces, long numberOfDroppedP0Spans, bool appsecStandaloneEnabled)
{
_log.Debug<int>("Sending {Count} traces to the Datadog Agent.", numberOfTraces);

// Pin the array to get a pointer to the data
// This is recommended if using UnsafeAddrOfPinnedArrayElement to avoid the GC moving the array
var tracesHandle = GCHandle.Alloc(traces.Array, GCHandleType.Pinned);
Expand All @@ -46,6 +57,7 @@ public Task<bool> SendTracesAsync(ArraySegment<byte> traces, int numberOfTraces,

public Task<bool> SendStatsAsync(StatsBuffer stats, long bucketDuration)
{
_log.Debug("No-op: stats computation happens in the data pipeline.");
return Task.FromResult(true);
}

Expand Down

0 comments on commit eabf0b0

Please sign in to comment.