LogDrop
Backend TracingRust

Custom Spans

Add spans for business operations in a Rust service traced by LogDrop.

The traced libraries already record incoming requests and calls to databases and other services. For business operations you want to see as their own step in a trace, use tracing spans: the LogDrop layer records every span at INFO level and above.

Add a span

Create a span at INFO level around the operation and run the operation inside it:

use tracing::Instrument;

let span = tracing::info_span!("checkout.price", order.kind = "delivery"); // custom keys need LOGDROP_ALLOWED_ATTRIBUTE_KEYS=order.kind
let total = async { pricing::total(&order).await }.instrument(span).await;

Calls made inside the span (database statements, outgoing requests, other spans) appear under it in the same trace. For synchronous code use span.in_scope(|| ...). DEBUG and TRACE spans are not recorded.

Special fields set what OpenTelemetry records:

FieldMeaning
otel.name = %nameThe span name, when it is not the static name in the macro. Use templates, never request or user data
otel.kind = "client"internal (the default), server, client, producer or consumer
otel.status_code = "ERROR"Marks the span as failed (OK or ERROR)

Attributes and errors

An attribute is a key and value on a span; in tracing it is a span field, such as order.kind = "delivery". An error is recorded from an ERROR event inside the span. These rules apply to both, and to span names:

  • A custom attribute is sent only when its key is listed in LOGDROP_ALLOWED_ATTRIBUTE_KEYS (comma-separated, at most 128 keys). A key starts with a letter and has at most 128 letters, digits, _, . or -. Every other field of a span stays in the process.
  • Keys that contain authorization, cookie, token, secret, password, credential, api_key, apikey or api-key are always dropped, even when listed.
  • Values are a string, a bool, an integer or a float; other values are ignored. Text is cut to LOGDROP_MAX_STRING_LENGTH characters (256 by default).
  • Log events inside a span (tracing::info! and others) are never sent: their messages can carry anything. An ERROR event becomes an exception event with only the allowed fields, for example tracing::error!(error.type = "PaymentDeclined", "declined"); its message stays in the process.
  • Span names are at most 256 characters.

Other calls

Besides spans, the crate has calls to send queued spans, read its state and switch the ingest key without a restart. A batch job, for example, calls logdrop::flush before it exits.

CallWhat it does
logdrop::flush(timeout)Sends the spans that ended before the call, for example before a batch job exits. Returns false when it did not finish in time, an export failed, or tracing does not run. The timeout is more than 0 and at most one minute
logdrop::export_status()Counts of exported, failed, rejected (refused as invalid, or dropped before sending because LogDrop would refuse them), pending, refused (over the active-span limit) and active spans, and whether tracing runs (agent_attached)
logdrop::update_ingest_credential(key)Uses this key for later requests, without a restart, until the key file changes again. Returns CredentialError::NotAttached, InvalidCredential or Closed when it cannot
logdrop::is_agent_attached()Whether tracing runs in this process
logdrop::shutdown()Sends the spans still queued, for at most 10 seconds, and stops tracing. ShutdownGuard calls it when dropped

Without tracing

Without settings every call is safe and records nothing: spans still run your code, flush returns false, export_status() reports that tracing does not run, and update_ingest_credential returns NotAttached.

On this page