Sha256: a1df632b3bb3572f17d0e2b034079c98bd023420c4534643b334736f95fe05c3

Contents?: true

Size: 890 Bytes

Versions: 3

Compression:

Stored size: 890 Bytes

Contents

module SyncMachine
  module TracerAdapters
    # Adapt OpenTracing for use with SyncMachine.
    module OpenTracingAdapter
      def self.start_active_span(name, &block)
        scope = tracer.start_active_span(
          name,
          child_of: parent_span.context,
          tags: tags
        )
        block.call
      rescue Exception => exception
        log_errors(scope.span, exception) if scope
        raise exception
      ensure
        scope.close if scope
      end

      def self.log_errors(span, exception)
        span.set_tag('error', true)
        span.log_kv(event: 'error', :'error.object' => exception)
      end

      def self.parent_span
        OpenTracing.active_span
      end

      def self.tags
        { 'component' => 'SyncMachine', 'span.kind' => 'server' }
      end

      def self.tracer
        OpenTracing.global_tracer
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sync_machine-1.4.0 lib/sync_machine/tracer_adapters/open_tracing_adapter.rb
sync_machine-1.3.0 lib/sync_machine/tracer_adapters/open_tracing_adapter.rb
sync_machine-1.2.0 lib/sync_machine/tracer_adapters/open_tracing_adapter.rb