---
title: Diesel
description: Learn how to integrate Allure with Diesel to record executed queries and transactions as steps in your Rust test reports.
---

# Getting started with Allure Diesel

[![allure-diesel crates.io latest version](https://img.shields.io/crates/v/allure-diesel?style=flat "allure-diesel crates.io latest version")](https://crates.io/crates/allure-diesel)

Record executed [Diesel](https://diesel.rs) queries as steps in your
[Allure Report](https://allurereport.org/docs/) test reports. It hooks into Diesel's
`Instrumentation` API, so it's wired up once in test or setup code and never touches production
query call sites.

`allure-diesel` records against whichever Allure context is bound to the current thread when a
query runs — the same thread-bound context [Rust Cargo Test](/docs/rust/) sets up automatically
inside `#[allure_test]`. Outside an active Allure context (for example, in application code, or in
tests that don't use `#[allure_test]`), every instrumentation event is a silent no-op — nothing is
recorded and nothing fails.

Info:
The official `allure-rust` repository also publishes [`allure-reqwest`](/docs/reqwest/) for
capturing `reqwest` HTTP calls as Allure attachments.

## Setting up

1. Make sure you have an Allure integration set up for your test runner. See
   [Rust Cargo Test](/docs/rust/).

1. Add the dependency:

   ```bash
   cargo add allure-diesel --dev
   ```

1. Attach the instrumentation. Two ways to do it:

   **Per connection** — attach it right after establishing each connection you want captured:

   ```rust
   use diesel::prelude::*;
   use diesel::sqlite::SqliteConnection;

   fn connect() -> ConnectionResult<SqliteConnection> {
       let mut conn = SqliteConnection::establish(":memory:")?;
       conn.set_instrumentation(allure_diesel::AllureInstrumentation::new());
       Ok(conn)
   }
   ```

   **Globally** — register it once during test setup, and every connection established
   afterward in the process is captured with no call-site changes:

   ```rust
   fn setup() -> diesel::QueryResult<()> {
       allure_diesel::install_default()
   }
   ```

1. Run your tests and generate a report the same way as you would normally — see
   [Rust Cargo Test](/docs/rust/#_3-generate-a-report).

## What gets captured

- Each executed statement becomes a step named after its rendered SQL (see
  [Reference](/docs/diesel-reference/#step-naming) for how long statements are shortened), and by
  default carries the full SQL as a nested `query.sql` attachment step.
- `BEGIN`/`COMMIT`/`ROLLBACK` boundaries become a `transaction` step that nests the queries run
  inside that transaction, including the boundary statements themselves. See
  [Reference](/docs/diesel-reference/#transactions) for exactly how nesting and failure are
  represented.
- A query that returns a database error marks its step (and, for a failing transaction boundary,
  the enclosing `transaction` step) failed, with the Diesel error message.

## What's not captured

Diesel's instrumentation exposes the SQL of each statement but not the rows a query returns — no
non-invasive Diesel hook does. This crate therefore records queries and transactions, not result
sets.

Warning:
There is no redaction. The recorded SQL — in both the step name and the `query.sql` attachment —
can include bind values exactly as Diesel renders them (for example, via a `-- binds: [...]`
comment on parameterized queries), so a captured statement can contain the same sensitive data
your query was parameterized to avoid logging in plain text. Keep this in mind before publishing
reports built from tests that touch real data.
