Sha256: 172e256c76c37219c9beef2b8db9e348d559efde01c564e677d4575495a6f613

Contents?: true

Size: 1.3 KB

Versions: 57

Compression:

Stored size: 1.3 KB

Contents

# typed: false
# frozen_string_literal: true

require "opentelemetry"
require "active_support/parameter_filter"

module Hephaestus
  module Middleware
    class TracingAttributes
      attr_reader :app

      HTTP_REQUEST_CONTENT_LENGTH = "http.request_content_length"
      HTTP_REQUEST_BODY = "http.request.body"

      def initialize(app)
        @app = app
        @filterer = ActiveSupport::ParameterFilter.new(Rails.application.config.filter_parameters)
      end

      def call(env)
        request = ActionDispatch::Request.new(env.dup)

        OpenTelemetry::Trace.current_span.add_attributes({
          "version" => Hephaestus::Engine::GIT_SHA,
          HTTP_REQUEST_CONTENT_LENGTH => env["CONTENT_LENGTH"].to_i,
          HTTP_REQUEST_BODY => process_tracing_body(request),
        })

        app.call(env)
      end

      def process_tracing_body(request)
        if Rails.configuration.respond_to?(:tracing_body_filters)
          Rails.configuration.tracing_body_filters.each do |path, filter|
            next unless request.path.starts_with?(path)

            result = filter.call(request)

            return result if result.is_a?(String)

            return result.to_json
          end
        end

        params = request.params
        @filterer.filter(params).to_json
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
hephaestus-0.8.15.5 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.15.4 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.15.3 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.15.2 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.15.1 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.15 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.14 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.13 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.12.2 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.12.1 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.12 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.11 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.10 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.9.2 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.9.1 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.9 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.8 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.7.5 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.7.4 lib/hephaestus/middleware/tracing_attributes.rb
hephaestus-0.8.7.3 lib/hephaestus/middleware/tracing_attributes.rb