isEnabled method

bool isEnabled({
  1. SpanKind? kind,
  2. Context? context,
})

Returns whether this tracer is enabled for the provided arguments. This should be checked before performing expensive operations to create spans.

The returned value can change over time; instrumentation authors need to call this each time they create a new span to ensure they have the most up-to-date response.

No parameters are currently required by the spec, but this is a method (not a getter) so parameters such as kind and context can be added later without a breaking change.

Implementation

bool isEnabled({SpanKind? kind, Context? context}) {
  // No factory means nothing can record, and error-handling.md forbids
  // throwing from an API method, so never dereference a null factory here.
  final factory = OTelFactory.otelFactory;
  return factory != null && !factory.isAPIFactory;
}