Skip to content

Commit

Permalink
Add context to metrics reporting of buffer-full events (#1566)
Browse files Browse the repository at this point in the history
* add context to metrics reporting of buffer-full events

* Update sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb

Co-authored-by: Francis Bogsanyi <[email protected]>

* Use semantic convention for code function label

* Kwargs are better; use kwargs

* stray paren

* use __method__ to access current method

* code better

* method to string

* pass spans as arg to report_dropped_spans

* cleanup

---------

Co-authored-by: Francis Bogsanyi <[email protected]>
  • Loading branch information
plantfansam and fbogsany authored Jan 22, 2024
1 parent d08bc1a commit 9da08e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def on_finish(span)
reset_on_fork
n = spans.size + 1 - max_queue_size
if n.positive?
spans.shift(n)
report_dropped_spans(n, reason: 'buffer-full')
dropped_spans = spans.shift(n)
report_dropped_spans(dropped_spans, reason: 'buffer-full', function: __method__.to_s)
end
spans << span
@condition.signal if spans.size > batch_size
Expand Down Expand Up @@ -122,8 +122,8 @@ def force_flush(timeout: nil) # rubocop:disable Metrics/MethodLength
lock do
n = spans.size + snapshot.size - max_queue_size
if n.positive?
snapshot.shift(n)
report_dropped_spans(n, reason: 'buffer-full')
dropped_spans = snapshot.shift(n)
report_dropped_spans(dropped_spans, reason: 'buffer-full', function: __method__.to_s)
end
spans.unshift(snapshot) unless snapshot.empty?
@condition.signal if spans.size > max_queue_size / 2
Expand All @@ -146,8 +146,8 @@ def shutdown(timeout: nil)

thread&.join(timeout)
force_flush(timeout: OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time))
dropped_spans = lock { spans.size }
report_dropped_spans(dropped_spans, reason: 'terminating') if dropped_spans.positive?
dropped_spans = lock { spans.shift(spans.length) }
report_dropped_spans(dropped_spans, reason: 'terminating') if dropped_spans.any?
@exporter.shutdown(timeout: OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time))
end

Expand Down Expand Up @@ -200,12 +200,12 @@ def report_result(result_code, batch)
else
OpenTelemetry.handle_error(exception: ExportError.new("Unable to export #{batch.size} spans"))
@metrics_reporter.add_to_counter('otel.bsp.export.failure')
report_dropped_spans(batch.size, reason: 'export-failure')
report_dropped_spans(batch, reason: 'export-failure')
end
end

def report_dropped_spans(count, reason:)
@metrics_reporter.add_to_counter('otel.bsp.dropped_spans', increment: count, labels: { 'reason' => reason })
def report_dropped_spans(dropped_spans, reason:, function: nil)
@metrics_reporter.add_to_counter('otel.bsp.dropped_spans', increment: dropped_spans.size, labels: { 'reason' => reason, OpenTelemetry::SemanticConventions::Trace::CODE_FUNCTION => function }.compact)
end

def fetch_batch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def to_span_data
_(test_exporter.failed_batches.size).must_equal(0)
_(test_exporter.batches.size).must_equal(0)

_(bsp.instance_variable_get(:@spans).size).must_equal(1)
_(bsp.instance_variable_get(:@spans).size).must_equal(0)
end

it 'works if the thread is not running' do
Expand Down

0 comments on commit 9da08e4

Please sign in to comment.