Skip to content

Official support for span-based tracing #2867

@uuushiro

Description

@uuushiro

First of all, thank you for all your work maintaining SeaORM.

Motivation

SeaORM’s official documentation currently focuses on debug logging (enabling SQL logs via RUST_LOG, etc.). This is helpful for local debugging, but it’s mostly logging-oriented, and it doesn’t provide strong support for span-based tracing (e.g., parent/child spans under an HTTP request span, standardized DB span attributes, timing, error status, etc.).

In practice, many teams want distributed tracing style visibility: “this HTTP request → these DB operations → which query was slow / failed”. Logs alone make this much harder.Spans provide hierarchy and timing (“which DB calls happened under this request?”), which is difficult to achieve with logging-only approaches.

There is clear ecosystem interest in OpenTelemetry-compatible spans

  • sqlx-tracing instruments SQLx operations by wrapping pools/executors and emitting OpenTelemetry-style span fields.
  • sea-orm-tracing (community crate) implements a traced wrapper around DatabaseConnection / ConnectionTrait and emphasizes automatic nesting of DB spans under the current active span (HTTP middleware, etc.).

These examples show demand, but the lack of an official hook forces users into “external wrapper” strategies or ad-hoc solutions.

Proposed Solutions

Introduce a small, optional instrumentation hook in SeaORM core that can be used to create spans around DB operations.

Concept

An ObservabilityHook (name bikesheddable) that is invoked around query execution paths

  • called for execute, query_one, query_all, stream, execute_unprepared
  • also used in transaction flows (begin/commit/rollback where applicable)

This hook would allow SeaORM to remain backend-agnostic while enabling

Design goals

  • Opt-in / zero overhead by default (no hook → no extra allocations/spans)
  • Minimal API surface (don’t bake OpenTelemetry types into SeaORM; just enable tracing integration)
  • Works for existing backends (Postgres/MySQL/SQLite)

Related: Proxy / extension points

I saw recent work improving proxy-related behavior (e.g., ProxyDatabase support in transaction impl).

That’s great progress—separately, it would be helpful to discuss whether proxy/hook patterns could become a stable extension point for observability (not only testing/mocking).

Questions for maintainers

Does the overall direction make sense to you — i.e., strengthening SeaORM’s span-based tracing instrumentation (OpenTelemetry-friendly) in addition to the existing debug logging? If you agree with the goal, what do you think is the best approach in SeaORM’s architecture?

A lightweight hook/middleware around execution paths (driver / connection / transaction), orSome other extension point you’d recommend?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions