Giter VIP home page Giter VIP logo

diesel-tracing's Introduction

Maintenance

diesel-tracing

diesel-tracing provides connection structures that can be used as drop in replacements for diesel connections with extra tracing and logging.

Usage should be straightforward if you are already using dynamic trait objects or impl trait for your connections. For example a function such as:

fn use_connection(
    conn: &impl diesel::Connection<Backend = diesel::pg::Pg>,
) -> () {}

Will accept both diesel::PgConnection and the InstrumentedPgConnection provided by this crate and this works similarly for other implementations of Connection if you change the parametized Backend marker in the function signature.

Unfortunately there are some methods specific to backends which are not encapsulated by the diesel::Connection trait, so in those places it is likely that you will just need to replace your connection type with the Instrumented version.

Usage

Just like diesel this crate relies on some feature flags to specify which database driver to support. Just as in diesel configure this in your Cargo.toml

[dependencies]
diesel-tracing = { version = "<version>", features = ["<postgres|mysql|sqlite>", "[statement-fields]"] }

Notes

Fields

Currently the few fields that are recorded are a subset of the OpenTelemetry semantic conventions for databases. This was chosen for compatibility with the tracing-opentelemetry crate, but if it makes sense for other standards to be available this could be set by feature flag later.

Database statements may optionally be recorded by enabling the statement-fields feature. This uses diesel::debug_query to convert the query into a string. As this may expose sensitive information, the feature is not enabled by default.

It would be quite useful to be able to parse connection strings to be able to provide more information, but this may be difficult if it requires use of diesel feature flags by default to access the underlying C bindings.

Levels

All logged traces are currently set to DEBUG level, potentially this could be changed to a different default or set to be configured by feature flags. At them moment this crate is quite new and it's unclear what a sensible default would be.

Errors

Errors in Result objects returned by methods on the connection should be automatically logged through the err directive in the instrument macro.

Sensitive Information

As statements may contain sensitive information they are currently not recorded explicitly, unless you opt in by enabling the statement-fields feature. Finding a way to filter statements intelligently to solve this problem is a TODO.

Similarly connection strings are not recorded in spans as they may contain passwords

TODO

  • Record and log connection information (filtering out sensitive fields)
  • Provide a way of filtering statements, maybe based on regex?

License: MIT

diesel-tracing's People

Contributors

johnchildren avatar mickdekkers avatar colem213 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.