https://github.com/cqcl/diesel-tracing

Connection telemetry middleware for diesel and tracing

https://github.com/cqcl/diesel-tracing

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.8%) to scientific vocabulary

Keywords

databases diesel rust telemetry tracing
Last synced: 5 months ago · JSON representation

Repository

Connection telemetry middleware for diesel and tracing

Basic Info
  • Host: GitHub
  • Owner: CQCL
  • License: mit
  • Language: Rust
  • Default Branch: main
  • Homepage:
  • Size: 42 KB
Statistics
  • Stars: 20
  • Watchers: 4
  • Forks: 20
  • Open Issues: 10
  • Releases: 8
Topics
databases diesel rust telemetry tracing
Created over 5 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog License

README.md

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

Feature flags

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

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

Establishing a connection

diesel-tracing has several instrumented connection structs that wrap the underlying diesel implementations of the connection. As these structs also implement the diesel::Connection trait, establishing a connection is done in the same way as the diesel crate. For example, with the postgres feature flag:

```rust

[cfg(feature = "postgres")]

{ use diesel_tracing::pg::InstrumentedPgConnection;

let conn = InstrumentedPgConnection::establish("postgresql://example");

} ```

This connection can then be used with diesel dsl methods such as diesel::prelude::RunQueryDsl::execute or diesel::prelude::RunQueryDsl::get_results.

Code reuse

In some applications it may be desirable to be able to use both instrumented and uninstrumented connections. For example, in the tests for a library. To achieve this you can use the diesel::Connection trait.

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

Connection Pooling

diesel-tracing supports the r2d2 connection pool, through the r2d2 feature flag. See diesel::r2d2 for details of usage.

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

Owner

  • Name: Cambridge Quantum
  • Login: CQCL
  • Kind: organization
  • Location: Cambridge, UK

Quantum Software and Technologies

GitHub Events

Total
  • Create event: 2
  • Release event: 1
  • Issues event: 1
  • Watch event: 2
  • Issue comment event: 3
  • Push event: 3
  • Pull request event: 3
  • Fork event: 4
Last Year
  • Create event: 2
  • Release event: 1
  • Issues event: 1
  • Watch event: 2
  • Issue comment event: 3
  • Push event: 3
  • Pull request event: 3
  • Fork event: 4

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 37
  • Total Committers: 8
  • Avg Commits per committer: 4.625
  • Development Distribution Score (DDS): 0.297
Past Year
  • Commits: 2
  • Committers: 2
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.5
Top Committers
Name Email Commits
John Children j****n@g****m 26
Mick Dekkers m****l@g****m 3
Marc Coleman m****3@p****e 2
Chris Portela c****s@c****m 2
energit-lcauli l****i@e****t 1
chibicco me@c****v 1
Lucas Sunsi Abreu l****i@p****e 1
Jacob Lee j****b@b****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 13
  • Total pull requests: 27
  • Average time to close issues: 11 months
  • Average time to close pull requests: 4 days
  • Total issue authors: 5
  • Total pull request authors: 8
  • Average comments per issue: 1.31
  • Average comments per pull request: 0.37
  • Merged pull requests: 26
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 5
  • Average time to close issues: about 1 month
  • Average time to close pull requests: 11 days
  • Issue authors: 1
  • Pull request authors: 3
  • Average comments per issue: 1.0
  • Average comments per pull request: 0.8
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • johnchildren (7)
  • lsunsi (2)
  • hawkw (1)
  • ptescher (1)
  • energit-lcauli (1)
Pull Request Authors
  • johnchildren (25)
  • mickdekkers (3)
  • energit-lcauli (2)
  • chibicco (2)
  • colem213 (2)
  • chrisportela (2)
  • lsunsi (2)
  • jakelee8 (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cargo 47,231 total
  • Total dependent packages: 1
  • Total dependent repositories: 6
  • Total versions: 15
  • Total maintainers: 1
crates.io: diesel-tracing

Connection telemetry middleware for diesel and tracing

  • Versions: 15
  • Dependent Packages: 1
  • Dependent Repositories: 6
  • Downloads: 47,231 Total
Rankings
Dependent repos count: 9.7%
Downloads: 13.4%
Dependent packages count: 16.0%
Forks count: 16.3%
Average: 16.6%
Stargazers count: 27.9%
Maintainers (1)
Last synced: 6 months ago

Dependencies

Cargo.toml cargo
  • diesel 1.4 development
  • diesel 1.4
  • ipnetwork >=0.12.2, <0.19.0
  • tracing 0.1
.github/workflows/rust.yml actions
  • actions/checkout v2 composite
  • postgres 11 docker