Skip to content

No way to tell if there isn't a current span. #1906

@samuel-williams-shopify

Description

def current_span(context = nil)

I need to know if there is a valid span or not.

Is the best we can do:

::OpenTelemetry::Trace.current_span == ::OpenTelemetry::Trace::Span::INVALID

This seems pretty clunky to me.

Maybe we can fix this:

  1. Introduce ::OpenTelemetry::Trace.current_span? which returns nil if no context/current span (? suffix means optional).
  2. Introduce a keyword argument def current_span(default: Span::INVALID) so we could invoke current_span(default: nil).
  3. Introduce Span#valid? or something like that, e.g. ::OpenTelemetry::Trace.current_span.valid?.

For now, I'll use ::OpenTelemetry::Trace.current_span == ::OpenTelemetry::Trace::Span::INVALID because that's the best option that currently works, but I think using a sentinel value is a bit ugly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions