{"id":16499198,"url":"https://github.com/hardbyte/rust-telemetry-example","last_synced_at":"2025-05-04T01:30:26.827Z","repository":{"id":249083748,"uuid":"830285763","full_name":"hardbyte/rust-telemetry-example","owner":"hardbyte","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-01T02:59:48.000Z","size":3048,"stargazers_count":2,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-01T03:34:48.312Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hardbyte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-07-18T01:38:11.000Z","updated_at":"2025-05-01T02:59:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"2add5453-1340-4e74-beb4-ec5cf4befbe3","html_url":"https://github.com/hardbyte/rust-telemetry-example","commit_stats":null,"previous_names":["hardbyte/rust-telemetry-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardbyte%2Frust-telemetry-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardbyte%2Frust-telemetry-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardbyte%2Frust-telemetry-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardbyte%2Frust-telemetry-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hardbyte","download_url":"https://codeload.github.com/hardbyte/rust-telemetry-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252276955,"owners_count":21722447,"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":[],"created_at":"2024-10-11T14:51:31.869Z","updated_at":"2025-05-04T01:30:26.818Z","avatar_url":"https://github.com/hardbyte.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nAn example of cross service telemetry in Rust using OpenTelemetry.\n\n\n### Tracing\n\nThe **tracing** crate is used to instrument the application code. \n\nDemonstrates propagation of trace context across `reqwest` calls,\na generated progenitor client and kafka messages.\n\nIn the case of kafka we create a linked span rather than continuing the parent span. \n\nThe `tracing-opentelemetry` crate exposes a `tracing` subscriber that exports the traces \nto the **OpenTelemetry Collector** using `opentelemetry-otlp`.\n\n**Span metrics** are calculated from the trace data using the otel collector along with exemplars.\n\nVisualized natively in Grafana:\n\n![img.png](.github/spanmetrics.png)\n\n\n### Logs\n\nLog events are both shown on the console and exported to the **OpenTelemetry Collector** using\nthe `OpenTelemetryTracingBridge` - these can be viewed in Loki.\n\n![img.png](.github/loki.png)\n\n### Metrics\n\nIn application metrics are implemented via opentelemetry meter including for http requests\nvia a fork of `axum-otel-metrics`. The otel collector also collects metrics from postgresql and \nkafka exporting them all to Prometheus.\n\n![img.png](.github/metrics.png)\n\n\nYou can carry out metric queries against traces in Grafana:\n\n```promql\n```traceql\n{ event.target =\"sqlx::query\" \u0026\u0026 event.summary =~ \"insert.*\"} | quantile_over_time(duration, 0.95) by (event.summary)\n```\n\n## Running locally\n\n```shell\ndocker compose build\ndocker compose up\n```\n\n\n```http request\n### GET all books\nGET http://localhost:8000/books\nAccept: application/json\n\n```\n\nOpen Grafana at localhost:3000 and login with `admin:admin`\n\n![img.png](.github/img.png)\n\n\n## Load Testing\n\n```shell\nuvx \\\n  --with 'opentelemetry-sdk' \\\n  --with \"opentelemetry-exporter-otlp-proto-grpc \u003e=1.24.0\" \\\n  --with \"opentelemetry-instrumentation-requests==0.46b0\" \\\n  --with \"opentelemetry-instrumentation-urllib3==0.46b0\" \\\n  locust -f requests/locustfile.py\n```\n\n\n![img.png](./.github/locust-screenshot.png)\n\n![img.png](./.github/tempo-drilldown.png)\n\n## Migrations\n\nMigrations are run automatically by the bookapp container, or can manually be run using `sqlx-cli`:\n\n```shell\ndocker compose up -d db\ncargo install sqlx-cli\nsqlx migrate run\nsqlx migrate add \u003cnew migration\u003e\n```\n\n## Compile Time Checked Postgres Queries\n\nThe `sqlx` crate is used with the query! macro to provide compile time checked queries.\n\nIf you change the queries, compile with `DATABASE_URL` set to a valid postgres connection string.\nPrepared metadata is stored in workspace level `.sqlx` directory.\n\n```shell\ncargo sqlx prepare --workspace\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhardbyte%2Frust-telemetry-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhardbyte%2Frust-telemetry-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhardbyte%2Frust-telemetry-example/lists"}