Sha256: 184f14397b8b0f41626b8b5b79cb617818b11577b3a84c7f1213662f507c1a1b

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

require_relative '../../../core/logging/ext'

module Datadog
  module Tracing
    module Contrib
      module Lograge
        # Instrumentation for Lograge
        module Instrumentation
          def self.included(base)
            base.prepend(InstanceMethods)
          end

          # Instance methods for configuration
          module InstanceMethods
            def custom_options(event)
              return super unless Datadog.configuration.tracing[:lograge].enabled

              original_custom_options = super(event)

              # Retrieves trace information for current thread
              correlation = Tracing.correlation
              # merge original lambda with datadog context

              datadog_trace_log_hash = {
                # Adds IDs as tags to log output
                dd: {
                  # To preserve precision during JSON serialization, use strings for large numbers
                  trace_id: correlation.trace_id.to_s,
                  span_id: correlation.span_id.to_s,
                  env: correlation.env.to_s,
                  service: correlation.service.to_s,
                  version: correlation.version.to_s
                },
                ddsource: Core::Logging::Ext::DD_SOURCE
              }

              datadog_trace_log_hash.merge(original_custom_options)
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ddtrace-1.12.1 lib/datadog/tracing/contrib/lograge/instrumentation.rb
ddtrace-1.12.0 lib/datadog/tracing/contrib/lograge/instrumentation.rb
ddtrace-1.11.1 lib/datadog/tracing/contrib/lograge/instrumentation.rb
ddtrace-1.11.0 lib/datadog/tracing/contrib/lograge/instrumentation.rb
ddtrace-1.11.0.beta1 lib/datadog/tracing/contrib/lograge/instrumentation.rb