-
-
Notifications
You must be signed in to change notification settings - Fork 125
feat(observability): optional tracing instrumentation (off by default, OTel-ready) #733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
62aa3d8
feat(observability): optional tracing instrumentation, off by default…
jlucaso1 0d8088a
fix(observability): keyed phone token, preserve agent, doc path (PR r…
jlucaso1 dc83a33
fix(observability): redact legacy group creator-phone prefix (Codex P2)
jlucaso1 20a0fdb
feat(observability): close coverage gaps, redact log PII, tune levels…
jlucaso1 02a1838
fix(observability): honor tracing-pii in address/str redaction; redac…
jlucaso1 8c6d4be
fix(observability): redact JIDs in error messages (Codex P2)
jlucaso1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| //! Wiring observability for `whatsapp-rust`. | ||
| //! | ||
| //! Run with: | ||
| //! cargo run --example observability --features tracing | ||
| //! | ||
| //! The library only *emits* `tracing` spans/events (and keeps its existing `log` | ||
| //! calls). It never installs a subscriber and never depends on OpenTelemetry — | ||
| //! that is the application's job, shown here. | ||
| //! | ||
| //! Two things happen below: | ||
| //! | ||
| //! 1. A `tracing-subscriber` is installed. Its default `tracing-log` feature | ||
| //! bridges the library's existing `log::{info,warn,error}!` calls into | ||
| //! tracing, so they become events attached to the active `wa.*` span. | ||
| //! 2. Span/level/target filtering is driven by `RUST_LOG` (EnvFilter), e.g. | ||
| //! `RUST_LOG="info,whatsapp_rust=debug,wacore=debug"`. The library groups | ||
| //! spans under `wa.*` names and reuses its `target: "Client/AppState"`-style | ||
| //! targets, so you can filter per area. | ||
| //! | ||
| //! IMPORTANT: do NOT enable the `log` feature on the `tracing` crate together | ||
| //! with a log->tracing bridge — that recurses. This crate already pins | ||
| //! `tracing` with `default-features = false` so the hazard cannot happen. | ||
| //! | ||
| //! PII note: the bridged `log` lines surface alongside the redacted `wa.*` spans. | ||
| //! The library renders JIDs and Signal addresses in its own log messages through | ||
| //! `Jid::observe()` / `observe_protocol_address()` (phone numbers become | ||
| //! `pn#<keyed-token>`), so the `whatsapp_rust`/`wacore` log lines carry the same | ||
| //! redaction as the span fields. Your own application code is a separate leak | ||
| //! path: any raw JID/phone you log reaches the exporter under your own targets, | ||
| //! and dropping the library targets does nothing for it — scrub your app's logs | ||
| //! with `Jid::observe()` too. The `tracing-pii` cargo feature (off) renders raw | ||
| //! numbers for local debugging only. | ||
|
|
||
| fn main() { | ||
| use tracing_subscriber::prelude::*; | ||
|
|
||
| let filter = tracing_subscriber::EnvFilter::try_from_default_env() | ||
| .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info,whatsapp_rust=debug")); | ||
|
|
||
| tracing_subscriber::registry() | ||
| .with(filter) | ||
| .with(tracing_subscriber::fmt::layer()) | ||
| // ── OpenTelemetry (OTLP) ──────────────────────────────────────────── | ||
| // Add the application deps `opentelemetry`, `opentelemetry-otlp` and | ||
| // `tracing-opentelemetry`, then append a layer here: | ||
| // | ||
| // let tracer = opentelemetry_otlp::new_pipeline() | ||
| // .tracing() | ||
| // .with_exporter(opentelemetry_otlp::new_exporter().tonic()) | ||
| // .install_batch(opentelemetry_sdk::runtime::Tokio)?; | ||
| // .with(tracing_opentelemetry::layer().with_tracer(tracer)) | ||
| // | ||
| // Every `wa.*` span is then exported as an OTLP span with its fields | ||
| // (chat/peer/msg_id are already privacy-redacted via `Jid::observe()`). | ||
| .init(); | ||
|
|
||
| tracing::info!("observability initialized — RUST_LOG drives filtering"); | ||
|
|
||
| // From here you would build and run a `whatsapp_rust::Client` as usual; all | ||
| // connect / recv / decrypt / send / iq / appstate / pair / media spans and | ||
| // the bridged log events will flow into the subscriber above. | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an app copies this OTLP example with tracing enabled,
.init()installs the defaulttracing-logbridge, so the existinglog!messages are exported alongside the new redacted span fields. Those legacy logs still format JIDs with normalDisplayrather thanJid::observe()(for examplesrc/client/sessions.rs:247/:256logsjiddirectly), so a phone-number JID can be emitted as raw PII even though the surroundingwa.*fields are redacted. Disable the log bridge for production tracing or scrub the existing log messages before recommending this wiring.Useful? React with 👍 / 👎.