Sha256: 1b030f827794c81c22e6d006ffdf03b8c59d75c5bc04ad4a677cf5d890f145c9

Contents?: true

Size: 939 Bytes

Versions: 1

Compression:

Stored size: 939 Bytes

Contents

# frozen_string_literal: true

module Minato
  module Trace
    module Middleware
      class IntegrateWithCloudLogging
        def call(log)
          return log unless ::Rails.env.production? && Minato::Trace.enabled?

          add_trace_to_logs(log)
        end

        private

        def add_trace_to_logs(log)
          return log if current_cloud_trace.nil?

          trace_log = "projects/#{current_cloud_trace.trace.project_id}/traces/#{current_cloud_trace.trace.trace_id}"

          log.merge({ "logging.googleapis.com/trace": trace_log,
                      "logging.googleapis.com/spanId": current_cloud_trace.span_id.to_s })
        end

        def current_cloud_trace
          @current_cloud_trace ||= current_trace_from_google_cloud
        end

        def current_trace_from_google_cloud
          _trace_client = Google::Cloud::Trace.new
          Google::Cloud::Trace.get
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
minato-trace-0.1.6.pre.5 lib/minato/trace/middleware/integrate_with_cloud_logging.rb