Skip to content

Conversation

@eric-wang-1990
Copy link
Contributor

Summary

Enable setting trace parent at the statement level for connection pooling scenarios like Power BI, where multiple queries reuse the same connection but need different trace IDs for distributed tracing.

Changes

  • TracingStatement: Add _statementTraceParent field and SetTraceParent() method
  • TracingStatement: TraceParent property now returns statement override or falls back to connection's trace parent
  • HiveServer2Statement: Add SetOption case for AdbcOptions.Telemetry.TraceParent
  • Add comprehensive test coverage for statement-level trace parent functionality

Motivation

This brings C# implementation to parity with Go drivers which already support statement-level trace parent via SetOption.

Power BI Use Case

Power BI uses connection pooling where multiple queries reuse the same connection. Each Power BI query has its own trace ID for distributed tracing correlation. Without statement-level trace parent support, all queries from a pooled connection would share the same trace context, making it impossible to correlate individual query traces.

With this change, Power BI can:

var connection = pool.GetConnection();

// Query 1 with Trace ID A
var stmt1 = connection.CreateStatement();
stmt1.SetOption("adbc.telemetry.trace_parent", powerBiQueryTraceIdA);
stmt1.ExecuteQuery();

// Query 2 with Trace ID B (same connection!)
var stmt2 = connection.CreateStatement();
stmt2.SetOption("adbc.telemetry.trace_parent", powerBiQueryTraceIdB);
stmt2.ExecuteQuery();

Test Plan

Added CanSetTraceParentOnStatement test that verifies:

  1. Statement inherits connection's trace parent by default
  2. Statement can override with its own trace parent via SetOption
  3. Activities created by the statement use the statement's trace parent
  4. Setting trace parent to null falls back to connection's trace parent

All existing tests pass.

🤖 Generated with Claude Code

Enable setting trace parent at the statement level for connection
pooling scenarios like Power BI, where multiple queries reuse the same
connection but need different trace IDs for distributed tracing.

Changes:
- TracingStatement: Add _statementTraceParent field and SetTraceParent() method
- TracingStatement: TraceParent property now returns statement override or falls back to connection's trace parent
- HiveServer2Statement: Add SetOption case for AdbcOptions.Telemetry.TraceParent
- Add comprehensive test coverage for statement-level trace parent functionality

This brings C# implementation to parity with Go drivers which already
support statement-level trace parent via SetOption.

Fixes support for Power BI scenarios where each query needs its own
trace context while using connection pooling.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy link
Contributor

@CurtHagenlocher CurtHagenlocher left a comment

Choose a reason for hiding this comment

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

Thanks!

@CurtHagenlocher CurtHagenlocher merged commit b99a179 into apache:main Jan 16, 2026
7 checks passed
Copy link
Contributor

@birschick-bq birschick-bq left a comment

Choose a reason for hiding this comment

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

I'm think we want to update the trace parent all objects that use the Trace instance. I don't think we want a separate value for the statement.

public abstract class TracingStatement : AdbcStatement, ITracingStatement
{
private readonly ActivityTrace _trace;
private string? _statementTraceParent;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not convinced we need a separate trace parent for statements.

Because the statement will use the connection to make calls, if the trace parent is not passed to the connection, the connection tracing won't include the trace parent value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just for enable databricks to override the traceparent that passed from PBI for statement level.
I am fine with reverting this and use some other generic approach to support, let me know what you think

birschick-bq added a commit to adbc-drivers/hiveserver2 that referenced this pull request Jan 21, 2026
)

<!--
    Copyright (c) 2025 ADBC Drivers Contributors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->

## What's Changed

- ports `Statement.SetOption` for `TraceParent` change from
[arrow-adbc](apache/arrow-adbc#3896)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants