Sha256: 683e1ec906eb4ad0615d01145f48654a8da527bada874ffd47309c85e2b14f56

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require "minato/trace/version"
require "minato/trace/middleware"

if defined? Rails::Railtie
  require "google/cloud/trace/rails"
  require "minato/trace/railtie"
end

module Minato
  module Trace
    BLACKLIST_PATHS = ["/health/alive", "/health/ready"].freeze

    def self.init(app)
      if Minato::Trace.enabled?
        Minato::Trace.configure_loggging(app)
        Minato::Trace.configure_trace
      end

      app
    end

    def self.enabled?
      ENV["MINATO_TRACE_DISABLED"] != "true"
    end

    def self.configure_trace
      Google::Cloud.configure do |config|
        config.use_trace = true
        config.trace.sampler = Google::Cloud::Trace::TimeSampler.new(path_blacklist: BLACKLIST_PATHS.dup)
      end
    end

    def self.configure_loggging(app)
      Google::Cloud.configure do |config|
        config.use_logging = false
      end

      app.configure do
        config.minato_logger.middleware.use Minato::Trace::Middleware::IntegrateWithCloudLogging
      end
    end

    def self.skip_trace?(trace)
      BLACKLIST_PATHS.any? { |path| trace.name.start_with?(path) }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
minato-trace-0.1.7 lib/minato/trace.rb
minato-trace-0.1.6.pre.8 lib/minato/trace.rb
minato-trace-0.1.6.pre.7 lib/minato/trace.rb
minato-trace-0.1.6.pre.6 lib/minato/trace.rb