Instrument Snowflake: see every query your app runs
See the queries your app sends to Snowflake alongside the code that triggered them. Logfire records each query as a span (one unit of work: a single operation, with a name, a start, and a duration). Related spans appear in the same trace (the full journey of one request, made of nested spans), so you can find slow and failed queries in context.
Instrumenting Snowflake means adding the Logfire integration so it can see what your database
code is doing. The integration wraps the Snowflake Connector for Python,
the client library that snowflake-snowpark-python and most other Snowflake tools also run their
queries through, so queries issued via Snowpark’s DataFrame API get spans too.
- Each call to
connect()as a span, with the target account, warehouse, database, schema, and role. Connection secrets (password, token, private key, etc.) are never captured. - Each call to
execute()/executemany()as a span, with the SQL text, row count, and Snowflake’s own query ID (sfqid), with Logfire’s standard scrubbing (automatically finding and hiding sensitive values in your telemetry, on your machine, before anything is sent) applied.
Snowflake’s compute cost for a query (credits consumed, bytes scanned, warehouse queuing)
is not available at query time; Snowflake only exposes it minutes later through account-usage
views. To bring that data into Logfire, run the OpenTelemetry Collector
(a separate program that sits between your apps and Logfire, gathering telemetry and forwarding
it) with its snowflakereceiver, and use the sfqid attribute this
integration records to match a query span to its later cost data.
You’ll need a Logfire project. Open Add data in your project (top navigation) and follow the
setup for your language: it signs your machine in with logfire auth (a browser sign-in, no token
to copy) and, for production or other languages, creates a write token (the credential your app
uses to send data). New to Logfire? Start with Getting Started.
Install logfire:
pip install logfire
uv add logfire
conda install -c conda-forge logfire
Install the separately distributed snowflake-connector-python package:
pip install snowflake-connector-python
Call logfire.instrument_snowflake() before connecting.
With no arguments, it records queries from every connection in the process, including ones made
later. Import the module as snowflake.connector and call snowflake.connector.connect().
A connect name imported before instrumenting (from snowflake.connector import connect) still
points at the original function, so its snowflake connect span is missing. Query spans are
recorded either way.
import snowflake.connector
import logfire
logfire.configure()
logfire.instrument_snowflake()
conn = snowflake.connector.connect(
account='<account>',
user='<user>',
password='<password>',
warehouse='<warehouse>',
database='<database>',
schema='<schema>',
)
cursor = conn.cursor()
cursor.execute('select current_version()')
Run it with python main.py.
Query parameters may contain sensitive data. Logfire does not capture them by default. To include
them in spans, pass capture_parameters=True:
import logfire
logfire.instrument_snowflake(capture_parameters=True)
Logfire’s standard scrubbing still applies, but it may not identify every sensitive value.
Instrumenting the same module or connection again has no effect; the first call determines whether
parameters are captured, and a later call with a different value emits a warning. A connection
instrumented with capture_parameters=True keeps capturing parameters even if you later instrument
the module with the default.
Open the Live view. Within a few seconds, you should see spans
named snowflake connect, snowflake execute, or snowflake execute async. Click a span to see
its duration and attributes, including sfqid and rowcount.
Pass a connection instance to record queries from only that connection. Call
logfire.instrument_snowflake(conn) after connecting:
import snowflake.connector
import logfire
logfire.configure()
conn = snowflake.connector.connect(account='<account>', user='<user>', password='<password>')
logfire.instrument_snowflake(conn)
cursor = conn.cursor()
cursor.execute('select current_version()')
- Importing
snowflake.connectorfails: install the client separately withpip install snowflake-connector-python. - No spans appear: call
logfire.configure()first. For module-wide instrumentation, calllogfire.instrument_snowflake()before connecting, and connect throughsnowflake.connector.connect()rather than aconnectname imported earlier. For one connection, connect first, then calllogfire.instrument_snowflake(conn). - No data appears in Logfire: check that your write token is set. Run
logfire projects use <your-project>locally, or set theLOGFIRE_TOKENenvironment variable in production. See Getting Started.