Expand description
ForgeOps error tracking client for a ForgeOps instance:
forge_ops_tracker::init(|c| {
c.dsn = Some("https://<api_key>@your-forgeops-host/api/v1/events".to_string());
});See the README for what gets captured automatically vs. what needs an explicit
capture_error call. A from-scratch port of gems/forge_ops_tracker (the Rails client):
see that gem’s README for the shared design rationale behind the pieces this crate is built
from (Configuration, EventBuilder, DeliveryQueue, Reporter, Client).
Macros§
- context
- Builds a
HashMap<String, Value>fromkey => valuepairs, the same literal-context ergonomics every other client in this repo gets for free from its own language (a Python dict, a JS object literal, a PHP array):
Structs§
- Breadcrumb
- One entry in a trail. Matches the wire shape gems/forge_ops_tracker’s own BreadcrumbBuffer#add already builds, and the same four keys Api::V1::EventsController permits.
- Configuration
- Holds a single ForgeOps DSN plus everything else the client needs to build and deliver events. Mirrors gems/forge_ops_tracker’s Configuration: a single DSN string carries both the ingestion URL and the project’s API key: “https://<api_key>@host/api/v1/events”.
- Event
- Frame
Enums§
- Value
- A JSON-like value: what context/tags are built out of. Hand-rolled rather than depending on serde_json’s Value: this crate already needs regex/backtrace/ureq for things Rust’s standard library genuinely lacks (see README.md’s “Dependencies” section), and a fourth dependency purely for a value type this small isn’t worth it.
Traits§
- Result
Report Ext - Extension trait for
Result, so a fallible call can report its own error and still propagate it in one step:
Functions§
- add_
breadcrumb - Records one entry into the current thread’s breadcrumb trail: a query, an outbound call, or
anything worth remembering right up to the moment something actually goes wrong.
categorydefaults to"custom"andlevelto"info"when passed an empty string. A no-op, not an error, whenConfiguration.track_breadcrumbsisfalse. - capture_
error - Reports an error you’ve already handled. Call it right at the point you’d otherwise just log it:
- capture_
error_ with_ class - The same as
capture_error, but for a&dyn std::error::Error(aBox<dyn Error>, a trait object) whose concrete type isn’t known at the call site, soexception_classhas to be supplied explicitly rather than inferred. - capture_
infrastructure_ metric - Records one infrastructure reading (CPU, memory, disk, anything else a program of yours reads)
from one of your own hosts.
hostnamedefaults toConfiguration.server_namewhenNone, so a script running on the box it reports about needs no argument. Same buffered-batch delivery and no-op-when-disabled contract ascapture_metric. - capture_
metric - Records a named business metric (a signup, a payment, anything you want to name), buffered and
flushed periodically as one batch rather than one network call per capture. Pass
1.0for a bare counter-style call (“a signup happened”) or a real magnitude (“a $49 payment”); it may be negative (a refund). A no-op when the client isn’t enabled (no DSN, or this environment isn’t inenabled_environments), and a NaN or infinite value is dropped. - clear_
breadcrumbs - Clears the current thread’s breadcrumb trail. See
add_breadcrumb’s own doc for why calling this yourself, at the start of each request, is this crate’s responsibility to ask of you rather than something it can do on its own. - flush_
metrics - Delivers every buffered metric and infrastructure reading right now, instead of waiting for the next flush interval. The background flush thread is a daemon and Rust has no exit hook, so call this before a short-lived program ends.
- flush_
performance - Delivers whatever has been tallied so far right now, instead of waiting for the next
performance_flush_intervaltick. The background flush thread is a daemon: it does not run on a normal process exit the way the Ruby gem’sat_exithook does (Rust has no equivalent), so a short-lived program, or one about to shut down, should call this itself to avoid losing the last partial window. - init
- Configures the client. Call once at startup, before your server starts accepting requests.
Pass a closure to set any
Configurationfield: - install_
panic_ hook - Installs a global panic hook that reports any panic on any thread, then calls whatever hook
was previously installed (Rust’s own default, which prints to stderr, unless something else
already replaced it): never changing panic behavior itself, the same “report, then don’t
change program behavior” rule the .NET middleware and Python
excepthookwrapper both follow. - record_
performance - Records one timed call’s duration, in milliseconds, under
transaction_name: tallied in-process (count, total, max) and flushed periodically as one small aggregate report, for the Performance page’s per-transaction table, not one network call per call. A no-op whenConfiguration.track_performanceisfalseor reporting isn’t enabled for this environment. - record_
span - Records a span you timed yourself under the current one; a no-op outside a
trace. - set_
user - Manually attaches an affected user to whatever gets reported from here on, on this thread
(an explicit
capture_error/capture_error_with_classcall with nouserargument, or a panic the installed hook catches): there’s no way to automatically detect “the current user” the way a server-side web framework with its own session/auth middleware can, so call this yourself, e.g. right after sign-in.id/email/usernameare all independently optional; call with an empty map to clear whatever was set, e.g. on sign-out. See this crate’s ownCURRENT_USERthread-local (in the source) for why this is thread-local, and the real caveat that comes with that choice under an async runtime. - span
- Times
fas a child span of whatever span is open on this thread (or of the trace’s root), returning whatfreturned. Outside atraceit just runsf. Recorded even iffpanics.kindis one of"controller","service","database","redis","http","job","other"(anything else is sent as"other"). - time_
transaction - Runs
f, records how long it took undertransaction_name(seerecord_performance), and returns whateverfreturned. Recorded even iffpanics: the duration up to the panic is still a real duration, and a handler that panics is exactly one worth seeing on the Performance page. - trace
- Runs
fas a trace namedroot_name(for example"GET /checkout"or"job:reindex"): everyspanandrecord_spaninside it, on this thread, nests beneath this root. Whenftook at leastConfiguration.trace_capture_threshold(1 second by default) the whole trace is sent to ForgeOps, so fast calls cost nothing on the wire. Sent even iffpanics. Called inside an already-open trace it just records a span instead.