Skip to content

OpenTelemetry attributes for a condition

Source: R/opentelemetry.R ยท Help: ?condition_to_otel_attributes

condition_to_otel_attributes() describes a condition as OpenTelemetry exception attributes, with the names the Python package's exception_to_otel_attributes() uses, so spans from R and Python report failures the same way:

Usage

condition_to_otel_attributes(
  cnd,
  operation_context = NULL,
  include_attributes = TRUE,
  max_depth = 8L,
  include_stacktrace = TRUE,
  include_envelope = FALSE
)

Arguments

cnd
A condition object.
operation_context
An operation context from operation_context(), or NULL.
include_attributes
Include the attributes field?
max_depth
How many levels of chained conditions to render. A cause beyond this depth is replaced by the truncation marker {"truncated": true}.
include_stacktrace
Include exception.stacktrace when the condition has one?
include_envelope
Include the whole envelope as a JSON attribute?

Value

A named list of attributes, each a single string, logical or number, ready for span$record_exception() or span$add_event().

Details

  • exception.type, exception.message and, when available, exception.stacktrace: the standard OpenTelemetry exception attributes.
  • dataexcept.failure.kind, dataexcept.failure.retryable and dataexcept.failure.retry_after_seconds: the failure metadata, flat and typed, present only for what the condition's failure record carries.
  • dataexcept.operation.*: the operation context's labels and run identifiers. trace_id and span_id are left out, because a span already carries them natively.
  • With include_envelope = TRUE, dataexcept.envelope (the envelope as compact JSON with sorted keys) and dataexcept.envelope.schema (its schema id).

exception.type is the envelope's module and type, such as "dataexcept.MissingColumnError" or "base.simpleError"; for a failure read from a Python envelope it is the Python class's qualified name. The message is the envelope's, redacted. The stack trace is an rlang backtrace when the condition has one, and otherwise the condition's call, which is the only stack information a base R condition carries; either is redacted. A condition with neither, such as one read from an envelope, has no stack trace attribute.

This is a pure conversion: invalid input is an error. record_otel_exception() is the fail-open version for use while handling a failure.

Examples

context <- operation_context(system = "batch", operation = "settle_invoices")
err <- with_failure_metadata(
  api_error("https://user:pw@api.example.com/v1/invoices", status_code = 503L),
  failure_metadata("transient", retryable = TRUE, retry_after_seconds = 30)
)
str(condition_to_otel_attributes(err, operation_context = context))

See also

record_otel_exception() to record a condition on a span.