{"id":29675762,"url":"https://github.com/oxidecomputer/diesel-dtrace","last_synced_at":"2025-10-10T11:13:43.347Z","repository":{"id":39990408,"uuid":"435681614","full_name":"oxidecomputer/diesel-dtrace","owner":"oxidecomputer","description":"A diesel connection with DTrace probes for connections and queries","archived":false,"fork":false,"pushed_at":"2025-07-07T16:29:23.000Z","size":196,"stargazers_count":8,"open_issues_count":4,"forks_count":1,"subscribers_count":20,"default_branch":"main","last_synced_at":"2025-07-07T17:48:33.856Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oxidecomputer.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"zenodo":null}},"created_at":"2021-12-06T23:35:34.000Z","updated_at":"2025-07-07T16:29:26.000Z","dependencies_parsed_at":"2024-05-02T21:37:57.737Z","dependency_job_id":"263c5d25-d032-4c51-9c8d-99772b0f99a2","html_url":"https://github.com/oxidecomputer/diesel-dtrace","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/oxidecomputer/diesel-dtrace","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxidecomputer%2Fdiesel-dtrace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxidecomputer%2Fdiesel-dtrace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxidecomputer%2Fdiesel-dtrace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxidecomputer%2Fdiesel-dtrace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oxidecomputer","download_url":"https://codeload.github.com/oxidecomputer/diesel-dtrace/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxidecomputer%2Fdiesel-dtrace/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266591233,"owners_count":23953082,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-07-22T23:38:28.364Z","updated_at":"2025-10-10T11:13:38.315Z","avatar_url":"https://github.com/oxidecomputer.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# diesel-dtrace\n\nAdd DTrace probes to Diesel connections.\n\n## Overview\n\nThe `diesel-dtrace` crate provides a diesel [`Connection`][1] that includes\nDTrace DTrace probe points. Probes are fired when we establish a connection to\nthe database; for each query; and each transaction. There are start / done\nprobes for each of these -- those fire when we start the operation (e.g., start\nto establish a connection) and when the operation is completed (e.g., when we\nfinish establishing a connection). This lets users trace the latency of those\noperations, or conditionally trace other operations while those are in progress.\n\nYour program must invoke [`usdt::register_probes`] for the probe points to be\navailable for tracing. See the documentation of that method for more details.\n\n## Probes\n\n```ignore\n/// Fires right before we attempt to establish a connection.\nconnection-establish-start(id: \u0026UniqueId, conn_id: Uuid, url: \u0026str)\n/// Fires when we finish establishing a connection, with a flag indicating\n/// whether it succeeded or failed.\nconnection-establish-done(id: \u0026UniqueId, conn_id: Uuid, success: u8)\n/// Fires just before issuing a SQL query.\nquery-start(id: \u0026UniqueId, conn_id: Uuid, query: \u0026str)\n/// Fires when a query completes.\nquery-done(id: \u0026UniqueId, conn_id: Uuid)\n/// Fires when we start a transaction.\n///\n/// This includes the connection ID as well as the depth of the transaction.\n/// As transactions can be nested, _both_ of these are required to uniquel\n/// identify a transaction.\n///\n/// The depth is `0` if there is no outer transaction, meaning this is not\n/// nested inside another transaction. In the internal implementation, querying\n/// the transaction depth can fail, in which case `depth == -1`. This indicates\n/// an unknown, internal error.\ntransaction-start(conn_id: Uuid, depth: i64)\n/// Fires when a transaction completes.\n///\n/// This includes the connection ID as well as the depth of the transaction.\n/// As transactions can be nested, _both_ of these are required to uniquely\n/// identify a transaction.\n///\n/// The depth is `0` if there is no outer transaction, meaning this is not\n/// nested inside another transaction. In the internal implementation, querying\n/// the transaction depth can fail, in which case `depth == -1`. This indicates\n/// an unknown, internal error.\n///\n/// This also includes a flag indicating whether the transaction was\n/// committed (`committed == 1`) or rolled back (`committed == 0`).\ntransaction-done(conn_id: Uuid, depth: i64, committed: u8)\n```\n\n## Transaction probes\n\nIt's important to note that the transaction-related probes include a connection\nID and a depth. As transactions can be nested on the same connection, _both_ of\nthese are required to uniquely identify transactions. For example, here is how\none could trace the latency of each transaction:\n\n```console\ndiesel_db*:::transaction-start\n{\n    txn[copyinstr(arg0), arg1] = timestamp;\n}\n\ndiesel_db*:::transaction-done\n/txn[copyinstr(arg0), arg1]/\n{\n    this-\u003ekey = copyinstr(arg0);\n    this-\u003econn_id = json(this-\u003ekey, \"ok\");\n    this-\u003edepth = arg1;\n    this-\u003elatency = (timestamp - txn[this-\u003ekey, this-\u003edepth]) / 1000;\n    this-\u003ecommit = arg2;\n    printf(\n        \"%s on conn '%s' (depth=%d), %d us\\n\",\n        this-\u003ecommit ? \"COMMIT\" : \"ROLLBACK\",\n        this-\u003econn_id,\n        this-\u003edepth,\n        this-\u003elatency\n    );\n    txn[this-\u003ekey, this-\u003edepth] = 0;\n}\n```\n\nAnd here is what some of the output might look like:\n\n```console\nCOMMIT on conn '094df7ba-8965-4f47-885a-96d79be24ff6' (depth=1), 21944 us\nCOMMIT on conn '6b70374e-6fd8-48ab-aa32-ed846ae513b8' (depth=1), 217627 us\nCOMMIT on conn '6232eae8-49f4-409d-bda1-103967035fca' (depth=1), 212682 us\nCOMMIT on conn 'a78e735d-b965-4e2f-b7bd-b10cebda3abc' (depth=1), 7028 us\nCOMMIT on conn '0a656b97-a990-41cd-9cb4-c819f4d82234' (depth=1), 245949 us\nCOMMIT on conn 'a78e735d-b965-4e2f-b7bd-b10cebda3abc' (depth=1), 5246 us\nCOMMIT on conn 'a78e735d-b965-4e2f-b7bd-b10cebda3abc' (depth=1), 8440 us\nCOMMIT on conn '207e4221-40a8-455e-85f1-24b68fb2efb4' (depth=1), 21737 us\nCOMMIT on conn 'a78e735d-b965-4e2f-b7bd-b10cebda3abc' (depth=1), 8512 us\nCOMMIT on conn 'a78e735d-b965-4e2f-b7bd-b10cebda3abc' (depth=1), 5998 us\nCOMMIT on conn '0a656b97-a990-41cd-9cb4-c819f4d82234' (depth=1), 47322 us\nCOMMIT on conn 'b6a0d6b4-51c9-4f48-a8b9-9f48bd7615d6' (depth=1), 38717 us\n```\n\n## Example\n\nThe example at `examples/conn.rs` attempts to connect to a PostgreSQL database at the URL\nprovided (or localhost:5432), and run a few simple queries. The probes fired by the example can\nbe seen with:\n\n```console\n# dtrace -Zqn 'diesel*::: { printf(\"%s (%d)\\n\", probename, arg0) }'\nconnection-establish-start (4294967297)\nconnection-establish-end (4294967297)\nquery-start (4294967298)\nquery-end (4294967298)\nquery-start (4294967299)\nquery-end (4294967299)\n```\n\n## Notes\n\nThis crate relies on the [`usdt`][2] crate. On macOS systems, a nightly\ncompiler is required prior to Rust 1.67. On other systems a nightly compiler is\nrequired prior to Rust 1.59.\n\n[1]: https://docs.rs/diesel/latest/diesel/connection/trait.Connection.html\n[2]: https://crates.io/crates/usdt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxidecomputer%2Fdiesel-dtrace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foxidecomputer%2Fdiesel-dtrace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxidecomputer%2Fdiesel-dtrace/lists"}