Class: Datadog::Tracing::Contrib::Sidekiq::ServerTracer
- Inherits:
-
Object
- Object
- Datadog::Tracing::Contrib::Sidekiq::ServerTracer
- Includes:
- Utils
- Defined in:
- lib/datadog/tracing/contrib/sidekiq/server_tracer.rb
Overview
Tracer is a Sidekiq server-side middleware which traces executed jobs
Instance Method Summary collapse
- #call(worker, job, queue) ⇒ Object
-
#initialize(options = {}) ⇒ ServerTracer
constructor
A new instance of ServerTracer.
Constructor Details
#initialize(options = {}) ⇒ ServerTracer
Returns a new instance of ServerTracer.
18 19 20 21 22 23 |
# File 'lib/datadog/tracing/contrib/sidekiq/server_tracer.rb', line 18 def initialize( = {}) @sidekiq_service = [:service_name] || configuration[:service_name] @on_error = [:on_error] || configuration[:on_error] @distributed_tracing = [:distributed_tracing] || configuration[:distributed_tracing] @quantize = [:quantize] || configuration[:quantize] end |
Instance Method Details
#call(worker, job, queue) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/datadog/tracing/contrib/sidekiq/server_tracer.rb', line 25 def call(worker, job, queue) resource = job_resource(job) if @distributed_tracing trace_digest = Sidekiq.extract(job) Datadog::Tracing.continue_trace!(trace_digest) end Datadog::Tracing.trace( Ext::SPAN_JOB, service: @sidekiq_service, type: Datadog::Tracing::Metadata::Ext::AppTypes::TYPE_WORKER, on_error: @on_error ) do |span| span.resource = resource span.set_tag(Contrib::Ext::Messaging::TAG_SYSTEM, Ext::TAG_COMPONENT) span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT) span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_JOB) span.set_tag( Datadog::Tracing::Metadata::Ext::TAG_KIND, Datadog::Tracing::Metadata::Ext::SpanKind::TAG_CONSUMER ) # Set analytics sample rate if Contrib::Analytics.enabled?(configuration[:analytics_enabled]) Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate]) end # Measure service stats Contrib::Analytics.set_measured(span) span.set_tag(Ext::TAG_JOB_ID, job['jid']) span.set_tag(Ext::TAG_JOB_RETRY, job['retry']) span.set_tag(Ext::TAG_JOB_RETRY_COUNT, job['retry_count']) span.set_tag(Ext::TAG_JOB_QUEUE, job['queue']) span.set_tag(Ext::TAG_JOB_WRAPPER, job['class']) if job['wrapped'] span.set_tag(Ext::TAG_JOB_DELAY, 1000.0 * (Time.now.utc.to_f - job['enqueued_at'].to_f)) args = job['args'] if args && !args.empty? span.set_tag(Ext::TAG_JOB_ARGS, Contrib::Utils::Quantization::Hash.format(args, (@quantize[:args] || {}))) end yield end end |