setAttribute static method

void setAttribute(
  1. String key,
  2. Object? attribute
)

Records an attribute on the current span, if there is one.

Safe to call from anywhere, including code that does not know whether tracing is installed — which is what lets a repository annotate a span without taking a dependency on the layer.

Implementation

static void setAttribute(String key, Object? attribute) =>
    value?.setAttribute(key, attribute);