{"id":13822506,"url":"https://github.com/CQCL/diesel-tracing","last_synced_at":"2025-05-16T17:30:58.138Z","repository":{"id":37969132,"uuid":"286520434","full_name":"CQCL/diesel-tracing","owner":"CQCL","description":"Connection telemetry middleware for diesel and tracing","archived":false,"fork":false,"pushed_at":"2024-11-11T15:04:49.000Z","size":43,"stargazers_count":20,"open_issues_count":10,"forks_count":19,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-05-10T07:11:29.780Z","etag":null,"topics":["databases","diesel","rust","telemetry","tracing"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CQCL.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-10T16:05:14.000Z","updated_at":"2025-02-18T01:57:06.000Z","dependencies_parsed_at":"2023-12-19T12:08:19.782Z","dependency_job_id":"2427cff8-093d-44db-85e6-ced48132bbb4","html_url":"https://github.com/CQCL/diesel-tracing","commit_stats":{"total_commits":16,"total_committers":3,"mean_commits":5.333333333333333,"dds":0.125,"last_synced_commit":"a7b77e32dd83cebe8c3099a2856ad303a31fe74c"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fdiesel-tracing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fdiesel-tracing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fdiesel-tracing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fdiesel-tracing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CQCL","download_url":"https://codeload.github.com/CQCL/diesel-tracing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254576414,"owners_count":22094365,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["databases","diesel","rust","telemetry","tracing"],"created_at":"2024-08-04T08:02:03.373Z","updated_at":"2025-05-16T17:30:57.875Z","avatar_url":"https://github.com/CQCL.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"![Maintenance](https://img.shields.io/badge/maintenance-experimental-blue.svg)\n\n# diesel-tracing\n\n`diesel-tracing` provides connection structures that can be used as drop in\nreplacements for diesel connections with extra tracing and logging.\n\n## Usage\n\n### Feature flags\n\nJust like diesel this crate relies on some feature flags to specify which\ndatabase driver to support. Just as in diesel configure this in your\n`Cargo.toml`\n\n```toml\n[dependencies]\ndiesel-tracing = { version = \"\u003cversion\u003e\", features = [\"\u003cpostgres|mysql|sqlite\u003e\"] }\n```\n\n## Establishing a connection\n\n`diesel-tracing` has several instrumented connection structs that wrap the underlying\n`diesel` implementations of the connection. As these structs also implement the\n`diesel::Connection` trait, establishing a connection is done in the same way as\nthe `diesel` crate. For example, with the `postgres` feature flag:\n\n```rust\n#[cfg(feature = \"postgres\")]\n{\n    use diesel_tracing::pg::InstrumentedPgConnection;\n\n    let conn = InstrumentedPgConnection::establish(\"postgresql://example\");\n}\n```\n\nThis connection can then be used with diesel dsl methods such as\n`diesel::prelude::RunQueryDsl::execute` or `diesel::prelude::RunQueryDsl::get_results`.\n\n## Code reuse\n\nIn some applications it may be desirable to be able to use both instrumented and\nuninstrumented connections. For example, in the tests for a library. To achieve this\nyou can use the `diesel::Connection` trait.\n\n```rust\nfn use_connection(\n    conn: \u0026impl diesel::Connection\u003cBackend = diesel::pg::Pg\u003e,\n) -\u003e () {}\n```\n\nWill accept both `diesel::PgConnection` and the `InstrumentedPgConnection`\nprovided by this crate and this works similarly for other implementations\nof `Connection` if you change the parametized Backend marker in the\nfunction signature.\n\nUnfortunately there are some methods specific to backends which are not\nencapsulated by the `diesel::Connection` trait, so in those places it is\nlikely that you will just need to replace your connection type with the\nInstrumented version.\n\n### Connection Pooling\n\n`diesel-tracing` supports the `r2d2` connection pool, through the `r2d2`\nfeature flag. See `diesel::r2d2` for details of usage.\n\n## Notes\n\n### Fields\n\nCurrently the few fields that are recorded are a subset of the `OpenTelemetry`\nsemantic conventions for [databases](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/database.md).\nThis was chosen for compatibility with the `tracing-opentelemetry` crate, but\nif it makes sense for other standards to be available this could be set by\nfeature flag later.\n\nDatabase statements may optionally be recorded by enabling the\n`statement-fields` feature. This uses [`diesel::debug_query`](https://docs.rs/diesel/latest/diesel/fn.debug_query.html)\nto convert the query into a string. As this may expose sensitive information,\nthe feature is not enabled by default.\n\nIt would be quite useful to be able to parse connection strings to be able\nto provide more information, but this may be difficult if it requires use of\ndiesel feature flags by default to access the underlying C bindings.\n\n### Levels\n\nAll logged traces are currently set to DEBUG level, potentially this could be\nchanged to a different default or set to be configured by feature flags. At\nthem moment this crate is quite new and it's unclear what a sensible default\nwould be.\n\n### Errors\n\nErrors in Result objects returned by methods on the connection should be\nautomatically logged through the `err` directive in the `instrument` macro.\n\n### Sensitive Information\n\nAs statements may contain sensitive information they are currently not recorded\nexplicitly, unless you opt in by enabling the `statement-fields` feature.\nFinding a way to filter statements intelligently to solve this problem is a\nTODO.\n\nSimilarly connection strings are not recorded in spans as they may contain\npasswords\n\n### TODO\n\n- [ ] Record and log connection information (filtering out sensitive fields)\n- [ ] Provide a way of filtering statements, maybe based on regex?\n\n\nLicense: MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCQCL%2Fdiesel-tracing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCQCL%2Fdiesel-tracing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCQCL%2Fdiesel-tracing/lists"}