Class: AceMQ::AMQP::Telemetry::OpenTelemetry::Scope
- Inherits:
-
Object
- Object
- AceMQ::AMQP::Telemetry::OpenTelemetry::Scope
- Defined in:
- lib/acemq/amqp/telemetry/open_telemetry.rb
Overview
One span, and the context it was made current in.
Closing detaches the context before ending the span, in that order: the other way round leaves a fiber pointing at a span that has already finished, and anything opened afterwards is parented to a corpse.
Instance Attribute Summary collapse
-
#span ⇒ OpenTelemetry::Trace::Span
readonly
For a caller that wants to add an attribute this library does not know about.
Instance Method Summary collapse
-
#close ⇒ Object
Ends the span.
- #closed? ⇒ Boolean
-
#failed(failure) ⇒ Scope
Records a failure, and says so in the vocabulary every other signal uses.
-
#initialize(span, token) ⇒ Scope
constructor
A new instance of Scope.
-
#outcome(outcome) ⇒ Scope
Records what happened, and marks the span an error when it was one.
Constructor Details
#initialize(span, token) ⇒ Scope
Returns a new instance of Scope.
476 477 478 479 480 481 |
# File 'lib/acemq/amqp/telemetry/open_telemetry.rb', line 476 def initialize(span, token) @span = span @token = token @closed = false @named = false end |
Instance Attribute Details
#span ⇒ OpenTelemetry::Trace::Span (readonly)
Returns for a caller that wants to add an attribute this library does not know about.
474 475 476 |
# File 'lib/acemq/amqp/telemetry/open_telemetry.rb', line 474 def span @span end |
Instance Method Details
#close ⇒ Object
Ends the span. Calling it twice does nothing the second time.
523 524 525 526 527 528 529 530 |
# File 'lib/acemq/amqp/telemetry/open_telemetry.rb', line 523 def close return if @closed @closed = true ::OpenTelemetry::Context.detach(@token) if @token @span.finish nil end |
#closed? ⇒ Boolean
532 |
# File 'lib/acemq/amqp/telemetry/open_telemetry.rb', line 532 def closed? = @closed |
#failed(failure) ⇒ Scope
Records a failure, and says so in the vocabulary every other signal uses.
The exception and the error status are not enough on their own: they
say something went wrong without saying what became of the
operation, and a span that said nothing where the counter said
failed is the same disagreement between a metric and a trace that
this library treats as a defect everywhere else — a dashboard shows
the failures and the trace backend, asked for
messaging.acemq.outcome = "failed", finds none of the spans behind
them. The Java adapter was fixed for exactly this and Python already
did it.
An outcome already named wins, because a caller who named one knows
more than "it threw": a request that ran out of time is timed_out,
which is the absence of an answer rather than a failure here.
515 516 517 518 519 520 |
# File 'lib/acemq/amqp/telemetry/open_telemetry.rb', line 515 def failed(failure) @span.record_exception(failure) if failure.is_a?(Exception) @span.set_attribute(OUTCOME, FAILED) unless @named @span.status = ::OpenTelemetry::Trace::Status.error(describe(failure)) self end |
#outcome(outcome) ⇒ Scope
Records what happened, and marks the span an error when it was one.
487 488 489 490 491 492 493 494 |
# File 'lib/acemq/amqp/telemetry/open_telemetry.rb', line 487 def outcome(outcome) @named = true @span.set_attribute(OUTCOME, outcome.to_s) if FAILING_OUTCOMES.include?(outcome.to_s) @span.status = ::OpenTelemetry::Trace::Status.error(outcome.to_s) end self end |