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 "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/0example-org / example-project",
    # Add data like request headers and IP for users, if applicable;
    # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
    send_default_pii=True,
    #  performance
    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for tracing.
    traces_sample_rate=1.0,
    #  performance
    #  profiling
    # To collect profiles for all profile sessions,
    # set `profile_session_sample_rate` to 1.0.
    profile_session_sample_rate=1.0,
    # Profiles will be automatically collected while
    # there is an active span.
    profile_lifecycle="trace",
    #  profiling
    #  logs
    # Enable logs to be sent to Sentry
    enable_logs=True,
    #  logs
)
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
Was this helpful?
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").
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").