Sha256: d092cc6457ca2ce955581336d4abde2948d704c257a01fc9e6a99999bf2e82fc

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

# typed: true
module Datadog
  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)
            original_custom_options = super(event)

            # Retrieves trace information for current thread
            correlation = Datadog.tracer.active_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: ['ruby']
            }

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ddtrace-0.54.2 lib/ddtrace/contrib/lograge/instrumentation.rb
ddtrace-0.54.1 lib/ddtrace/contrib/lograge/instrumentation.rb
ddtrace-0.54.0 lib/ddtrace/contrib/lograge/instrumentation.rb
ddtrace-0.53.0 lib/ddtrace/contrib/lograge/instrumentation.rb
ddtrace-0.52.0 lib/ddtrace/contrib/lograge/instrumentation.rb