Class: Langfuse::AppRootTracking::Tracker Private

Inherits:
Object
  • Object
show all
Defined in:
lib/langfuse/app_root_tracking.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defers a finished span until its active ancestors have final export decisions.

Instance Method Summary collapse

Constructor Details

#initializeTracker

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Tracker.



48
49
50
51
# File 'lib/langfuse/app_root_tracking.rb', line 48

def initialize
  @mutex = Mutex.new
  @state_by_span_id = {}
end

Instance Method Details

#empty?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Whether the tracker has no active span trees.

Returns:

  • (Boolean)

    Whether the tracker has no active span trees



88
89
90
# File 'lib/langfuse/app_root_tracking.rb', line 88

def empty?
  @mutex.synchronize { @state_by_span_id.empty? }
end

#finish(span, exportable:) ⇒ Array<ReadySpan>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Resolve finished spans whose ancestor export decisions are final.

Parameters:

  • span (OpenTelemetry::SDK::Trace::Span)

    The finished span

  • exportable (Boolean)

    Whether the final export filter accepted the span

Returns:

  • (Array<ReadySpan>)

    Spans that the batch processor can enqueue



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/langfuse/app_root_tracking.rb', line 74

def finish(span, exportable:)
  @mutex.synchronize do
    state = @state_by_span_id[span.context.span_id]
    return [] unless state

    state.finished = true
    state.exportable = exportable
    ready_spans = resolve_ready_spans
    release_finished_states
    ready_spans
  end
end

#remember(span, trace_claimed:, untracked_parent_root_eligible:) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • span (OpenTelemetry::SDK::Trace::Span)

    The active span

  • trace_claimed (Boolean)

    Whether propagated context already owns the root

  • untracked_parent_root_eligible (Boolean)

    Whether an untracked parent permits a root



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/langfuse/app_root_tracking.rb', line 57

def remember(span, trace_claimed:, untracked_parent_root_eligible:)
  @mutex.synchronize do
    parent_state = @state_by_span_id[span.parent_span_id]
    parent_state.active_child_count += 1 if parent_state
    @state_by_span_id[span.context.span_id] = build_state(
      span,
      trace_claimed: trace_claimed,
      untracked_parent_root_eligible: untracked_parent_root_eligible
    )
  end
end