Skip to content

feat(csharp): wire telemetry into connection/statement lifecycle with E2E tests#308

Merged
jadewang-db merged 26 commits intomainfrom
stack/itr5-pr-e2e-tests
Mar 10, 2026
Merged

feat(csharp): wire telemetry into connection/statement lifecycle with E2E tests#308
jadewang-db merged 26 commits intomainfrom
stack/itr5-pr-e2e-tests

Conversation

@jadewang-db
Copy link
Collaborator

@jadewang-db jadewang-db commented Mar 5, 2026

🥞 Stacked PR

Use this link to review incremental changes.


Summary

  • Connection lifecycle: Wire telemetry initialization into DatabricksConnection (feature flag check, per-host client management, session context creation) and graceful disposal with reference counting
  • Statement instrumentation: Override ExecuteQuery, ExecuteQueryAsync, ExecuteUpdate, and ExecuteUpdateAsync in DatabricksStatement to capture telemetry context (statement type, result format, compression, statement ID, errors) and emit one telemetry event per statement execution
  • Activity tags: Add telemetry-specific tags across connection, polling, composite reader, and CloudFetch components (poll count, result format, chunk count, bytes downloaded, compression)
  • HttpClientFactory: Add CreateTelemetryHttpClient using full auth/proxy handler chain for telemetry export
  • CapturingTelemetryExporter: Test double that captures exported telemetry logs for assertion without hitting real endpoints
  • E2E tests: Comprehensive tests validating all telemetry fields match JDBC driver output, including snake_case proto serialization, statement ID capture, error handling, and performance overhead

Test Plan

  • Unit tests for Activity tag definitions
  • E2E tests validating all telemetry fields per design doc
  • E2E tests for connection lifecycle (init, dispose, multi-connection sharing)
  • E2E tests for statement telemetry (query, update, error paths)
  • snake_case field name assertions matching proto wire format
  • Performance overhead test
  • Build passes with 0 warnings, 0 errors (net8.0)

@jadewang-db jadewang-db force-pushed the stack/itr5-pr-e2e-tests branch from 9853bc1 to 085cb62 Compare March 5, 2026 17:30
@jadewang-db jadewang-db force-pushed the stack/itr5-pr-e2e-tests branch from 085cb62 to 3e0f27c Compare March 5, 2026 18:31
@jadewang-db jadewang-db force-pushed the stack/itr5-pr-e2e-tests branch from 3e0f27c to 6459a5a Compare March 5, 2026 18:44
@jadewang-db jadewang-db force-pushed the stack/itr5-pr-e2e-tests branch from 6459a5a to 7f53ea8 Compare March 5, 2026 22:42
@jadewang-db jadewang-db force-pushed the stack/itr5-pr-e2e-tests branch from 7f53ea8 to 30178db Compare March 5, 2026 23:08
@jadewang-db jadewang-db force-pushed the stack/itr5-pr-e2e-tests branch from 30178db to 67239e6 Compare March 5, 2026 23:38
@jadewang-db jadewang-db force-pushed the stack/itr5-pr-e2e-tests branch from 67239e6 to c9453b4 Compare March 5, 2026 23:53
@jadewang-db jadewang-db force-pushed the stack/itr5-pr-e2e-tests branch from c9453b4 to 06e6163 Compare March 6, 2026 00:26
@jadewang-db jadewang-db marked this pull request as ready for review March 6, 2026 01:11
@jadewang-db
Copy link
Collaborator Author

[High] Static mutable ExporterOverride on singleton is a test-safety concern

csharp/src/Telemetry/TelemetryClientManager.cs:55

ExporterOverride is a static mutable field on the singleton TelemetryClientManager. This means:

  1. If xUnit runs test classes in parallel, tests will interfere with each other (one test's SetupCapturingExporter() will affect another's)
  2. Production code now carries test-only infrastructure

Suggestion: Consider one of:

  • Use a non-static instance-level property and inject a test-specific TelemetryClientManager instance (you already have the internal TelemetryClientManager(bool forTesting) constructor)
  • At minimum, make the E2E test collection serialized with [Collection("Telemetry")] to prevent parallel execution conflicts
  • Document thread-safety expectations in the property doc comment

This comment was generated with GitHub MCP.

@jadewang-db
Copy link
Collaborator Author

[High] Blocking async in Dispose risks deadlock

csharp/src/DatabricksConnection.cs:1069

DisposeTelemetryAsync().GetAwaiter().GetResult();

This pattern can deadlock when called from a synchronization context that captures the current thread (e.g., ASP.NET classic, UI threads). While the .ConfigureAwait(false) inside DisposeTelemetryAsync helps, if any awaited method inside the chain doesn't use ConfigureAwait(false), it will deadlock.

Suggestion: Consider implementing IAsyncDisposable alongside IDisposable so callers in async contexts can use await using. The sync Dispose path can remain as a fallback but should be documented with the deadlock risk.


This comment was generated with GitHub MCP.

@jadewang-db
Copy link
Collaborator Author

[Medium] Performance test name misleading — asserts 50%, not 1%

csharp/test/E2E/Telemetry/ClientTelemetryE2ETests.cs:925

The test is named Telemetry_PerformanceOverhead_LessThanOnePercent but the actual assertion is:

Assert.True(overheadPercent < 50.0,
    $"Telemetry overhead {overheadPercent:F2}% exceeds acceptable threshold of 50%");

Either rename the test to match the threshold (e.g., Telemetry_PerformanceOverhead_WithinAcceptableRange) or tighten the assertion to match the name.


This comment was generated with GitHub MCP.

@jadewang-db
Copy link
Collaborator Author

[Medium] Comment typos — missing /// and // prefixes

csharp/src/DatabricksConnection.cs:1077 and csharp/src/DatabricksConnection.cs:1089

/// Follows the graceful shutdown sequence: flush → release client → release feature flags.

is actually:

/ Follows the graceful shutdown sequence: flush → release client → release feature flags.

And line 1089:

/ Step 1: Flush pending metrics

Both are missing a slash — should be /// and // respectively.


This comment was generated with GitHub MCP.

Jade Wang added 5 commits March 10, 2026 03:46
Remove WithFormatEnumsAsIntegers and WithFormatDefaultValues from the
proto JsonFormatter so enums serialize as uppercase string names
(e.g., "THRIFT", "PAT", "QUERY") instead of integers, matching the
JDBC driver's telemetry output.

Co-authored-by: Isaac
@jadewang-db jadewang-db added this pull request to the merge queue Mar 10, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 10, 2026
@jadewang-db jadewang-db added this pull request to the merge queue Mar 10, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 10, 2026
@jadewang-db jadewang-db added this pull request to the merge queue Mar 10, 2026
@jadewang-db jadewang-db added the integration-test Trigger integration tests in internal repo label Mar 10, 2026
@github-actions
Copy link

🚀 Integration tests triggered! View workflow run

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 10, 2026
@github-actions github-actions bot removed the integration-test Trigger integration tests in internal repo label Mar 10, 2026
@github-actions
Copy link

🔒 Integration test approval reset

New commits were pushed to this PR. The integration-test label has been automatically removed for security.

A maintainer must re-review the changes and re-add the label to trigger tests again.

Why is this necessary?
  • New code requires fresh security review
  • Prevents approved PRs from adding malicious code later
  • Ensures all tested code has been explicitly approved

Latest commit: 14a80df

@jadewang-db jadewang-db enabled auto-merge March 10, 2026 20:30
@jadewang-db jadewang-db added the integration-test Trigger integration tests in internal repo label Mar 10, 2026
@github-actions
Copy link

🚀 Integration tests triggered! View workflow run

@jadewang-db jadewang-db added this pull request to the merge queue Mar 10, 2026
Merged via the queue into main with commit 54d6a0f Mar 10, 2026
27 of 29 checks passed
@jadewang-db jadewang-db deleted the stack/itr5-pr-e2e-tests branch March 10, 2026 21:07
@jadewang-db jadewang-db restored the stack/itr5-pr-e2e-tests branch March 11, 2026 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-test Trigger integration tests in internal repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants