clickhouse-driver

Learn about importing the clickhouse-driver integration and how it captures queries from clickhouse-driver as breadcrumbs.

The clickhouse-driver integration captures queries from clickhouse-driver as breadcrumbs and spans. The integration is available for clickhouse-driver 0.2.0 or later.

Install sentry-sdk with the clickhouse-driver extra.

Copied
pip install --upgrade 'sentry-sdk[clickhouse-driver]'

If you have the clickhouse-driver package in your dependencies, the clickhouse-driver integration will be enabled automatically when you initialize the Sentry SDK.

Copied
import sentry_sdk

sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for tracing.
    traces_sample_rate=1.0,
    # Set profiles_sample_rate to 1.0 to profile 100%
    # of sampled transactions.
    # We recommend adjusting this value in production.
    profiles_sample_rate=1.0,
)

By default, the parameters of the query are not retrieved. To see the query parameters in Sentry, enable send_default_pii. See Basic Options for details.

Copied
from clickhouse_driver import Client

def main():
    sentry_init(...)  # same as above

    with sentry_sdk.start_transaction(name="testing_sentry"):
        client = Client(host=DATABASE_HOST)
        client.execute("DROP TABLE IF EXISTS sentry_test")
        client.execute("CREATE TABLE sentry_test (x Int32) ENGINE = Memory")
        client.execute("INSERT INTO sentry_test (x) VALUES", [{"x": 100}])

main()

This will create a transaction called testing_sentry in the Performance section of sentry.io, and create spans for the database operations.

It takes a couple of moments for the data to appear in sentry.io.

  • clickhouse-driver >= 0.2.0
  • python >= 3.8
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").