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
Constant Summary collapse
- QUANTIZE_SHOW_ALL =
{ args: { show: :all } }.freeze
Instance Method Summary collapse
-
#call(worker, job, queue) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize.
-
#initialize(options = {}) ⇒ ServerTracer
constructor
A new instance of ServerTracer.
Constructor Details
#initialize(options = {}) ⇒ ServerTracer
Returns a new instance of ServerTracer.
20 21 22 23 |
# File 'lib/datadog/tracing/contrib/sidekiq/server_tracer.rb', line 20 def initialize( = {}) @sidekiq_service = [:service_name] || configuration[:service_name] @error_handler = [:error_handler] || configuration[:error_handler] end |
Instance Method Details
#call(worker, job, queue) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
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 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/datadog/tracing/contrib/sidekiq/server_tracer.rb', line 27 def call(worker, job, queue) resource = job_resource(job) if configuration[:distributed_tracing] trace_digest = propagation.extract(job) Datadog::Tracing.continue_trace!(trace_digest) end service = worker_config(resource, :service_name) || @sidekiq_service # DEV-2.0: Remove `tag_args`, as `quantize` can fulfill the same contract tag_args = worker_config(resource, :tag_args) || configuration[:tag_args] quantize = worker_config(resource, :quantize) || configuration[:quantize] Datadog::Tracing.trace( Ext::SPAN_JOB, service: service, span_type: Datadog::Tracing::Metadata::Ext::AppTypes::TYPE_WORKER, on_error: @error_handler ) 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? quantize = tag_args ? QUANTIZE_SHOW_ALL : quantize span.set_tag(Ext::TAG_JOB_ARGS, quantize_args(quantize, args)) end yield end # rubocop:enable Metrics/MethodLength # rubocop:enable Metrics/AbcSize end |