Sha256: 2b33f44e505526592690f4999ef43f3490c2c74181964db19359f56d1b0978d9

Contents?: true

Size: 1.51 KB

Versions: 17

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

require 'json'

module OpenTracing
  module Instrumentation
    module Sidekiq
      # Span tags and logs building mixin
      class JobTagger
        LOG_JID_EVENT = 'job_id'
        LOG_ARGS_EVENT = 'job_args'

        DEFAULT_COMPONENT = 'sidekiq'

        attr_accessor :component
        attr_accessor :log_args

        # @param component [String] component name
        # @param log_args [TrueClass, FalseClass] enable attribute logging
        def initialize(
          component: DEFAULT_COMPONENT,
          log_args: false
        )
          @component = component
          @log_args = log_args

          yield self if block_given?
        end

        # build tags from job data and static attributes
        def build_tags(job, span_kind)
          {
            'component' => component,
            'span.kind' => span_kind,
            'sidekiq.queue' => job['queue'],
            'sidekiq.class' => job['class'],
            'sidekiq.retry' => job['retry'],
          }
        end

        # write job jid and args if log_args enabled
        # @param span [OpenTracing::Span] target span
        # @param jid [String] job id
        # @param args [Array<Object>] argument list
        def write_args_log(span, jid, args)
          span.log_kv(
            event: LOG_JID_EVENT,
            jid: jid,
          )

          return unless log_args

          span.log_kv(
            event: LOG_ARGS_EVENT,
            args: JSON.dump(args),
          )
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
opentracing-instrumentation-0.1.16 lib/opentracing/instrumentation/sidekiq/job_tagger.rb
opentracing-instrumentation-0.1.15 lib/opentracing/instrumentation/sidekiq/job_tagger.rb
opentracing-instrumentation-0.1.14 lib/opentracing/instrumentation/sidekiq/job_tagger.rb
opentracing-instrumentation-0.1.13 lib/opentracing/instrumentation/sidekiq/job_tagger.rb
opentracing-instrumentation-0.1.12 lib/opentracing/instrumentation/sidekiq/job_tagger.rb
opentracing-instrumentation-0.1.11 lib/opentracing/instrumentation/sidekiq/job_tagger.rb
opentracing-instrumentation-0.1.10 lib/opentracing/instrumentation/sidekiq/job_tagger.rb
opentracing-instrumentation-0.1.9 lib/opentracing/instrumentation/sidekiq/job_tagger.rb
opentracing-instrumentation-0.1.8 lib/opentracing/instrumentation/sidekiq/job_tagger.rb
opentracing-instrumentation-0.1.7 lib/opentracing/instrumentation/sidekiq/job_tagger.rb
opentracing-instrumentation-0.1.6 lib/opentracing/instrumentation/sidekiq/job_tagger.rb
opentracing-instrumentation-0.1.5 lib/opentracing/instrumentation/sidekiq/job_tagger.rb
opentracing-instrumentation-0.1.4 lib/opentracing/instrumentation/sidekiq/job_tagger.rb
opentracing-instrumentation-0.1.3 lib/opentracing/instrumentation/sidekiq/job_tagger.rb
opentracing-instrumentation-0.1.2 lib/opentracing/instrumentation/sidekiq/job_tagger.rb
opentracing-instrumentation-0.1.1 lib/opentracing/instrumentation/sidekiq/job_tagger.rb
opentracing-instrumentation-0.1.0 lib/opentracing/instrumentation/sidekiq/job_tagger.rb