clickhouse-driver for Python
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.
If you're using stream mode, this page's references to "transaction" should be applied to service spans instead. See Streamed Spans for more information.
Install sentry-sdk from PyPI:
pip install sentry-sdk
pip install sentry-sdk
uv add sentry-sdk
If you have the clickhouse-driver package in your dependencies, the clickhouse-driver integration will be enabled automatically when you initialize the Sentry SDK.
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# 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,
# ___PRODUCT_OPTION_START___ performance
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
# ___PRODUCT_OPTION_END___ performance
# ___PRODUCT_OPTION_START___ 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",
# ___PRODUCT_OPTION_END___ profiling
)
import sentry_sdk
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# 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,
# ___PRODUCT_OPTION_START___ performance
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
# ___PRODUCT_OPTION_END___ performance
# ___PRODUCT_OPTION_START___ 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",
# ___PRODUCT_OPTION_END___ profiling
)
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.
from clickhouse_driver import Client
def main():
sentry_init(...) # same as above
# or sentry_sdk.traces.start_span(name="your_span_name", parent_span=None) in stream mode
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()
from clickhouse_driver import Client
def main():
sentry_init(...) # same as above
# or sentry_sdk.traces.start_span(name="your_span_name", parent_span=None) in stream mode
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
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").