Sha256: eb1434e00c2915d660a693fcf7e09750bcf51ceb3081adb3bbd629048084456f

Contents?: true

Size: 1.27 KB

Versions: 10

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

require_relative '../../metadata/ext'
require_relative '../analytics'
require_relative 'ext'

module Datadog
  module Tracing
    module Contrib
      module Hanami
        # Hanami Instrumentation for `hanami.action`
        class ActionTracer
          def initialize(app, action)
            @app = app
            @action = action
          end

          def call(env)
            Tracing.trace(
              Ext::SPAN_ACTION,
              resource: @action.to_s,
              service: configuration[:service_name],
              type: Tracing::Metadata::Ext::HTTP::TYPE_INBOUND
            ) do |span_op, trace_op|
              span_op.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
              span_op.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_ACTION)

              if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
                Contrib::Analytics.set_sample_rate(span_op, configuration[:analytics_sample_rate])
              end

              trace_op.resource = span_op.resource

              @app.call(env)
            end
          end

          private

          def configuration
            Datadog.configuration.tracing[:hanami]
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
datadog-2.7.0 lib/datadog/tracing/contrib/hanami/action_tracer.rb
datadog-2.6.0 lib/datadog/tracing/contrib/hanami/action_tracer.rb
datadog-2.5.0 lib/datadog/tracing/contrib/hanami/action_tracer.rb
datadog-2.4.0 lib/datadog/tracing/contrib/hanami/action_tracer.rb
datadog-2.3.0 lib/datadog/tracing/contrib/hanami/action_tracer.rb
datadog-2.2.0 lib/datadog/tracing/contrib/hanami/action_tracer.rb
datadog-2.1.0 lib/datadog/tracing/contrib/hanami/action_tracer.rb
datadog-2.0.0 lib/datadog/tracing/contrib/hanami/action_tracer.rb
datadog-2.0.0.beta2 lib/datadog/tracing/contrib/hanami/action_tracer.rb
datadog-2.0.0.beta1 lib/datadog/tracing/contrib/hanami/action_tracer.rb