Class: Pyroscope::Otel::SpanProcessor
- Inherits:
-
Object
- Object
- Pyroscope::Otel::SpanProcessor
- Defined in:
- lib/pyroscope/otel.rb
Overview
SpanProcessor annotates otel spans with profile_id, profile urls, baseline urls
Constant Summary collapse
- ZERO_SPAN_ID =
[0, 0, 0, 0, 0, 0, 0, 0].pack("C*")
Instance Attribute Summary collapse
-
#add_span_name ⇒ Object
boolean flag option to annotate pyroscope profiles with span name.
-
#add_url ⇒ Object
boolean flag option to add profiler url to span attributes.
-
#app_name ⇒ Object
pyroscope app name, including “.cpu” suffix.
-
#pyroscope_endpoint ⇒ Object
http address of pyroscope server for span links.
-
#root_span_only ⇒ Object
boolean flag option to annotate spans with profile attributes only on root spans.
Instance Method Summary collapse
- #force_flush(_timeout: nil) ⇒ Object
-
#initialize(app_name, pyroscope_endpoint) ⇒ SpanProcessor
constructor
A new instance of SpanProcessor.
- #on_finish(span) ⇒ Object
- #on_start(span, parent_context) ⇒ Object
- #shutdown(_timeout: nil) ⇒ Object
Constructor Details
#initialize(app_name, pyroscope_endpoint) ⇒ SpanProcessor
Returns a new instance of SpanProcessor.
29 30 31 32 33 34 35 36 |
# File 'lib/pyroscope/otel.rb', line 29 def initialize(app_name, pyroscope_endpoint) @app_name = app_name @pyroscope_endpoint = URI.parse(pyroscope_endpoint) @root_span_only = true @add_span_name = true @add_url = true end |
Instance Attribute Details
#add_span_name ⇒ Object
boolean flag option to annotate pyroscope profiles with span name
23 24 25 |
# File 'lib/pyroscope/otel.rb', line 23 def add_span_name @add_span_name end |
#add_url ⇒ Object
boolean flag option to add profiler url to span attributes
25 26 27 |
# File 'lib/pyroscope/otel.rb', line 25 def add_url @add_url end |
#app_name ⇒ Object
pyroscope app name, including “.cpu” suffix.
16 17 18 |
# File 'lib/pyroscope/otel.rb', line 16 def app_name @app_name end |
#pyroscope_endpoint ⇒ Object
http address of pyroscope server for span links
18 19 20 |
# File 'lib/pyroscope/otel.rb', line 18 def pyroscope_endpoint @pyroscope_endpoint end |
#root_span_only ⇒ Object
boolean flag option to annotate spans with profile attributes only on root spans.
21 22 23 |
# File 'lib/pyroscope/otel.rb', line 21 def root_span_only @root_span_only end |
Instance Method Details
#force_flush(_timeout: nil) ⇒ Object
62 |
# File 'lib/pyroscope/otel.rb', line 62 def force_flush(_timeout: nil) end |
#on_finish(span) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/pyroscope/otel.rb', line 53 def on_finish(span) profile_id = span.attributes["pyroscope.profile.id"] return if profile_id.nil? labels = { "profile_id": profile_id } labels["span"] = span.name if @add_span_name Pyroscope.(Pyroscope.thread_id, labels) end |
#on_start(span, parent_context) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pyroscope/otel.rb', line 38 def on_start(span, parent_context) return if @root_span_only && !root_span?(span, parent_context) profile_id = profile_id(span) labels = { "profile_id": profile_id } labels["span"] = span.name if @add_span_name Pyroscope.(Pyroscope.thread_id, labels) annotate_span(profile_id, span) rescue StandardError => e OpenTelemetry.handle_error(exception: e, message: "unexpected error in span.on_start") end |
#shutdown(_timeout: nil) ⇒ Object
64 |
# File 'lib/pyroscope/otel.rb', line 64 def shutdown(_timeout: nil) end |