Skip to content

feat(clickhouse_driver): Support span streaming#6508

Open
alexander-alderman-webb wants to merge 5 commits into
masterfrom
webb/clickhouse-driver/span-first
Open

feat(clickhouse_driver): Support span streaming#6508
alexander-alderman-webb wants to merge 5 commits into
masterfrom
webb/clickhouse-driver/span-first

Conversation

@alexander-alderman-webb
Copy link
Copy Markdown
Contributor

@alexander-alderman-webb alexander-alderman-webb commented Jun 5, 2026

Description

In the streaming path, use

  • db.namespace instead of db.name
  • db.system.name instead of db.system

Dropped attributes:

  • db.params
  • db.result
  • query
  • db.query_id

Tests for adding breadcrumbs based on spans have not been parametrized as breadcrumbs are not automatically created from spans with the new streaming lifecycle.

Adapting Tests

sed commands used for converting transaction context managers:

  • sed -i '' 's/start_transaction(name="test_clickhouse_transaction") as transaction:/sentry_sdk.traces.start_span(name="custom parent") as span:/g'
  • sed -i '' 's/start_transaction(name="test_clickhouse_transaction"):/sentry_sdk.traces.start_span(name="custom parent"):/g'

sed commands used for converting event capture:

  • sed -i '' 's/capture_events,/capture_items,/g'
  • sed -i '' 's/events = capture_events()/items = capture_items("event", "transaction", "span")/g'
  • sed -i '' 's/event["spans"]/spans/g'

sed commands used for converting op:

  • sed -i '' 's/"op"/"sentry.op"/g'

sed commands used for converting origin:

  • sed -i '' 's/"origin"/"sentry.origin"/g'

sed commands used for converting description:

sed -i '' 's/"description"/"name"/g'

sed commands used for converting data to attributes:

  • sed -i '' 's/"data"/"attributes"/g'

sed commands used for converting timestamps:

other test changes:

  • sed -i '' 's/transaction_trace_id/trace_id/g'
  • sed -i '' 's/transaction_span_id/span_id/g'
  • sed -i '' 's/transaction.trace_id/span.trace_id/g'
  • sed -i '' 's/transaction.span_id/span.span_id/g'
  • sed -i '' '/same_process_as_parent/d'
  • sed -i '' '/db.result/d'
  • sed -i '' '/db.params/d'
  • sed -i '' 's/"timestamp"/"end_timestamp"/g'
  • sed -i '' 's/"db.system"/"db.system.name"/g'
  • sed -i '' 's/"db.name"/"db.namespace"/g'

Issues

Closes #6011

Reminders

@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review June 5, 2026 12:40
@alexander-alderman-webb alexander-alderman-webb requested a review from a team as a code owner June 5, 2026 12:40
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Codecov Results 📊

88791 passed | ⏭️ 6025 skipped | Total: 94816 | Pass Rate: 93.65% | Execution Time: 291m 24s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +15
Passed Tests 📈 +15
Failed Tests
Skipped Tests

All tests are passing successfully.

✅ Patch coverage is 91.89%. Project has 2357 uncovered lines.
✅ Project coverage is 89.9%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/integrations/clickhouse_driver.py 91.89% ⚠️ 3 Missing and 3 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    89.90%    89.90%        —%
==========================================
  Files          192       192         —
  Lines        23321     23340       +19
  Branches      8020      8030       +10
==========================================
+ Hits         20967     20983       +16
- Misses        2354      2357        +3
- Partials      1326      1328        +2

Generated by Codecov Action

Comment thread tests/integrations/clickhouse_driver/test_clickhouse_driver.py
Comment thread tests/integrations/clickhouse_driver/test_clickhouse_driver.py
Comment thread sentry_sdk/integrations/clickhouse_driver.py
Comment thread tests/integrations/clickhouse_driver/test_clickhouse_driver.py
Comment thread sentry_sdk/integrations/clickhouse_driver.py
Comment thread sentry_sdk/integrations/clickhouse_driver.py
Copy link
Copy Markdown
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

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

See comments, feels like we could migrate more data to attributes?



def _wrap_start(f: "Callable[P, T]") -> "Callable[P, T]":
@ensure_integration_enabled(ClickhouseDriverIntegration, f)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IIRC the decorator also wraps the decorated func in functools.wraps(), so we should add that here manually

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, a few other integrations are also affected so I'll go ahead and update them as well. 30ffaad

)

connection._sentry_span = span # type: ignore[attr-defined]
span.set_data("query", query)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

db.query.text should have placeholders according to the description, and the query passed to Connection.send_query already contains substituted values.

You can observe this in the tests for the span descriptions (there are no assertions on the query attribute):

"description": "SELECT sum(x) FROM test WHERE x > 150",

Comment on lines +105 to +106
if params and should_send_default_pii():
span.set_data("db.params", params)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We didn't add the attribute in SQLAlchemy because it was unclear how parameters for batched queries are reported. The same applies to this driver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate clickhouse_driver to span first

2 participants