Sha256: e0175fec73501e9ecc5a56900ee097b1a196a4cf5254f41e0d176482b571d7b2

Contents?: true

Size: 951 Bytes

Versions: 6

Compression:

Stored size: 951 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_cloud_trace_from_google_cloud
        end

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

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/minato-trace-0.2.0/lib/minato/trace/middleware/integrate_with_cloud_logging.rb
minato-trace-0.2.0 lib/minato/trace/middleware/integrate_with_cloud_logging.rb
minato-trace-0.1.7 lib/minato/trace/middleware/integrate_with_cloud_logging.rb
minato-trace-0.1.6.pre.8 lib/minato/trace/middleware/integrate_with_cloud_logging.rb
minato-trace-0.1.6.pre.7 lib/minato/trace/middleware/integrate_with_cloud_logging.rb
minato-trace-0.1.6.pre.6 lib/minato/trace/middleware/integrate_with_cloud_logging.rb