Class: OpenTracing::Instrumentation::Sidekiq::JobTagger

Inherits:
Object
  • Object
show all
Defined in:
lib/opentracing/instrumentation/sidekiq/job_tagger.rb

Overview

Span tags and logs building mixin

Constant Summary collapse

LOG_JID_EVENT =
'job_id'
LOG_ARGS_EVENT =
'job_args'
DEFAULT_COMPONENT =
'sidekiq'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component: DEFAULT_COMPONENT, log_args: false) {|_self| ... } ⇒ JobTagger

Returns a new instance of JobTagger.

Parameters:

  • component (String) (defaults to: DEFAULT_COMPONENT)

    component name

  • log_args (TrueClass, FalseClass) (defaults to: false)

    enable attribute logging

Yields:

  • (_self)

Yield Parameters:



20
21
22
23
24
25
26
27
28
# File 'lib/opentracing/instrumentation/sidekiq/job_tagger.rb', line 20

def initialize(
  component: DEFAULT_COMPONENT,
  log_args: false
)
  @component = component
  @log_args = log_args

  yield self if block_given?
end

Instance Attribute Details

#componentObject

Returns the value of attribute component.



15
16
17
# File 'lib/opentracing/instrumentation/sidekiq/job_tagger.rb', line 15

def component
  @component
end

#log_argsObject

Returns the value of attribute log_args.



15
16
17
# File 'lib/opentracing/instrumentation/sidekiq/job_tagger.rb', line 15

def log_args
  @log_args
end

Instance Method Details

#build_tags(job, span_kind) ⇒ Object

build tags from job data and static attributes



31
32
33
34
35
36
37
38
39
# File 'lib/opentracing/instrumentation/sidekiq/job_tagger.rb', line 31

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_args_log(span, jid, args) ⇒ Object

write job jid and args if log_args enabled

Parameters:

  • span (OpenTracing::Span)

    target span

  • jid (String)

    job id

  • args (Array<Object>)

    argument list



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/opentracing/instrumentation/sidekiq/job_tagger.rb', line 45

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