Class: Labkit::Tracing::TracingUtils
- Inherits:
-
Object
- Object
- Labkit::Tracing::TracingUtils
- Defined in:
- lib/labkit/tracing/tracing_utils.rb
Overview
Internal methods for tracing. This is not part of the LabKit public API. For internal usage only
Class Method Summary collapse
-
.kv_tags_for_exception(exception) ⇒ Object
Generate key-value tags for an exception.
-
.log_exception_on_span(span, exception) ⇒ Object
Add exception logging to a span.
-
.postnotify_span(operation_name, start_time, end_time, tags: nil, child_of: nil, exception: nil) ⇒ Object
Generate a span retrospectively.
-
.tracer ⇒ Object
Obtain a tracer instance.
-
.with_tracing(operation_name:, tags:, child_of: nil) ⇒ Object
Convience method for running a block with a span.
Class Method Details
.kv_tags_for_exception(exception) ⇒ Object
Generate key-value tags for an exception
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/labkit/tracing/tracing_utils.rb', line 50 def self.(exception) case exception when Exception { :"event" => "error", :"error.kind" => exception.class.to_s, :"message" => Labkit::Logging::Sanitizer.sanitize_field(exception.), :"stack" => exception.backtrace&.join('\n'), } else { :"event" => "error", :"error.kind" => exception.class.to_s, :"error.object" => Labkit::Logging::Sanitizer.sanitize_field(exception.to_s) } end end |
.log_exception_on_span(span, exception) ⇒ Object
Add exception logging to a span
44 45 46 47 |
# File 'lib/labkit/tracing/tracing_utils.rb', line 44 def self.log_exception_on_span(span, exception) span.set_tag("error", true) span.log_kv((exception)) end |
.postnotify_span(operation_name, start_time, end_time, tags: nil, child_of: nil, exception: nil) ⇒ Object
Generate a span retrospectively
35 36 37 38 39 40 41 |
# File 'lib/labkit/tracing/tracing_utils.rb', line 35 def self.postnotify_span(operation_name, start_time, end_time, tags: nil, child_of: nil, exception: nil) span = OpenTracing.start_span(operation_name, start_time: start_time, tags: , child_of: child_of) log_exception_on_span(span, exception) if exception span.finish(end_time: end_time) end |
.tracer ⇒ Object
Obtain a tracer instance
30 31 32 |
# File 'lib/labkit/tracing/tracing_utils.rb', line 30 def self.tracer OpenTracing.global_tracer end |
.with_tracing(operation_name:, tags:, child_of: nil) ⇒ Object
Convience method for running a block with a span
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/labkit/tracing/tracing_utils.rb', line 11 def self.with_tracing(operation_name:, tags:, child_of: nil) scope = tracer.start_active_span(operation_name, child_of: child_of, tags: ) span = scope.span # Add correlation details to the span if we have them correlation_id = Labkit::Correlation::CorrelationId.current_id span.set_tag("correlation_id", correlation_id) if correlation_id begin yield span rescue StandardError => e log_exception_on_span(span, e) raise e ensure scope.close end end |