Skip to content

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.

What you’ll capture

  • 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.

What this integration does not capture

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.

Before you start

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 and the Snowflake connector

Install logfire:

Terminal
pip install logfire

Install the separately distributed snowflake-connector-python package:

Terminal
pip install snowflake-connector-python

Record every query

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.

main.py
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.

Capture query parameters

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.

Verify it worked

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.

Record one connection

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()')

Troubleshoot missing spans

  • Importing snowflake.connector fails: install the client separately with pip install snowflake-connector-python.
  • No spans appear: call logfire.configure() first. For module-wide instrumentation, call logfire.instrument_snowflake() before connecting, and connect through snowflake.connector.connect() rather than a connect name imported earlier. For one connection, connect first, then call logfire.instrument_snowflake(conn).
  • No data appears in Logfire: check that your write token is set. Run logfire projects use <your-project> locally, or set the LOGFIRE_TOKEN environment variable in production. See Getting Started.