Skip to content
Closed
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
3 changes: 3 additions & 0 deletions csharp/src/DatabricksStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ public override void SetOption(string key, string value)
throw new ArgumentOutOfRangeException(key, value, $"The value '{value}' for option '{key}' is invalid. Must be a numeric value greater than zero.");
}
break;
case AdbcOptions.Telemetry.TraceParent:
((IActivityTracer)this).Trace.TraceParent = string.IsNullOrWhiteSpace(value) ? null : value;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why set to null if non-exist? Should it set to the existing traceParent for connection?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think callers will need to remember to set the TraceParent on the Connection, as well.

break;
default:
base.SetOption(key, value);
break;
Expand Down
46 changes: 46 additions & 0 deletions csharp/test/E2E/StatementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.Json;
Expand All @@ -31,6 +32,7 @@
using Apache.Arrow.Adbc;
using Apache.Arrow.Adbc.Drivers.Apache;
using Apache.Arrow.Adbc.Tests.Drivers.Apache.Common;
using Apache.Arrow.Adbc.Tracing;
using Apache.Arrow.Types;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -1228,6 +1230,50 @@ public async Task PKFK_EmptyResult_SchemaMatches_RealMetadataResponse()
}
}

[SkippableFact]
public void SetOptionTraceParent()
{
// Create a statement
using var connection = NewConnection();
using var statement = connection.CreateStatement();

const string traceId = "4bf92f3577b34da6a3ce929d0e0e4736";
const string spanId = "00f067aa0ba902b7";
const string traceParent = $"00-{traceId}-{spanId}-01";

// Set the trace parent via SetOption
statement.SetOption(AdbcOptions.Telemetry.TraceParent, traceParent);

// Ensure the trace parent sets the TraceId on subsequent activities ...
IActivityTracer? statementTracer = statement as IActivityTracer;
Assert.NotNull(statementTracer);
Assert.Equal(traceParent, statementTracer.TraceParent);

// Ensure we have a listener to validate the activity
using ActivityListener listener = new()
{
Sample = (ref ActivityCreationOptions<ActivityContext> options) => ActivitySamplingResult.AllDataAndRecorded,
ShouldListenTo = (activitySource) => true /* activitySource.Name == tracer.Trace.ActivitySourceName */,
ActivityStopped = (activity) =>
{
Assert.NotNull(activity);
Assert.Equal(traceParent, activity.ParentId);
Assert.Equal(traceId, activity.TraceId.ToString());
Assert.NotEqual(spanId, activity.SpanId.ToString());
}
};
ActivitySource.AddActivityListener(listener);

// Trace some activity and validate
statementTracer.TraceActivity(activity =>
{
Assert.NotNull(activity);
Assert.Equal(traceParent, activity.ParentId);
Assert.Equal(traceId, activity.TraceId.ToString());
Assert.NotEqual(spanId, activity.SpanId.ToString());
});
}

private void AssertField(Field field, string expectedName, IArrowType expectedType, bool expectedNullable)
{
Assert.True(expectedName.Equals(field.Name), $"Field name mismatch: expected {expectedName}, got {field.Name}");
Expand Down
Loading