Sha256: 7850216ac6c48a9ea76b88cc6976b765afa09ff9581270588b48b3e3db5b01ca

Contents?: true

Size: 1.37 KB

Versions: 10

Compression:

Stored size: 1.37 KB

Contents

module Hermes
  class DistributedTraceRepository
    attr_reader :config, :distributed_trace_database, :distributes_tracing_mapper, :database_error_handler
    private     :config, :distributed_trace_database, :distributes_tracing_mapper, :database_error_handler

    def initialize(config:, distributed_trace_database:, distributes_tracing_mapper:, database_error_handler:)
      @config = config
      @distributed_trace_database = distributed_trace_database
      @distributes_tracing_mapper = distributes_tracing_mapper
      @database_error_handler = database_error_handler
    end

    def create(event)
      if config.store_distributed_traces?
        attributes = attributes_for_trace_context(event, event.trace_context)
        store_trace(attributes)
      end
    end

    private

    def attributes_for_trace_context(event, trace_context)
      {
        trace: trace_context.trace,
        span: trace_context.span,
        parent_span: trace_context.parent_span,
        service: trace_context.service,
        event_class: event.class.to_s,
        routing_key: event.routing_key,
        event_body: distributes_tracing_mapper.call(event.as_json),
        event_headers: event.to_headers
      }
    end

    def store_trace(attributes)
      distributed_trace_database.create!(attributes)
    rescue StandardError => error
      database_error_handler.call(error)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hermes-rb-0.10.1 lib/hermes/distributed_trace_repository.rb
hermes-rb-0.10.0 lib/hermes/distributed_trace_repository.rb
hermes-rb-0.9.1 lib/hermes/distributed_trace_repository.rb
hermes-rb-0.9.0 lib/hermes/distributed_trace_repository.rb
hermes-rb-0.8.0 lib/hermes/distributed_trace_repository.rb
hermes-rb-0.7.5 lib/hermes/distributed_trace_repository.rb
hermes-rb-0.7.4 lib/hermes/distributed_trace_repository.rb
hermes-rb-0.7.3 lib/hermes/distributed_trace_repository.rb
hermes-rb-0.7.2 lib/hermes/distributed_trace_repository.rb
hermes-rb-0.7.1 lib/hermes/distributed_trace_repository.rb