Sha256: 0f2c6bccd8dfa44816148a268225cd59f5f3ac7c9663ce7ecf1e705c48089e9f

Contents?: true

Size: 849 Bytes

Versions: 1

Compression:

Stored size: 849 Bytes

Contents

# frozen_string_literal: true

module Minato
  module Stackdriver
    module Middleware
      class DistributedTraceContext
        TRACE_HEADER_KEY = "X-Cloud-Trace-Context"

        def initialize(app)
          @app = app
        end

        def call(env)
          add_trace_context_header(env)

          @app.call(env)
        end

        private

        def add_trace_context_header(env)
          return unless Rails.env.production?

          env.request_headers.merge!({ "#{TRACE_HEADER_KEY}": "#{current_cloud_trace.trace.trace_id};o=1" })
        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-stackdriver-0.1.0.pre.5 lib/minato/stackdriver/middleware/distributed_trace_context.rb