Sha256: 9e61ac5b8d843337eca5a0a778fe06c0185d8dafc0b86a784e6913b75ada349a

Contents?: true

Size: 1.23 KB

Versions: 10

Compression:

Stored size: 1.23 KB

Contents

# typed: false
# frozen_string_literal: true

require "openapi_first"
require "active_support/parameter_filter"

module PlugApp
  module Middleware
    class TracingAttributes
      extend T::Sig

      sig { returns(T.untyped) }
      attr_reader :app

      HTTP_REQUEST_BODY = "http.request.body"
      PLUG_APP_PATH_PREFIX = "/app/"

      sig { params(app: T.untyped).void }
      def initialize(app)
        @app = T.let(app, T.untyped)
        @filterer = ActiveSupport::ParameterFilter.new(Rails.application.config.filter_parameters)
      end

      sig { params(env: T.untyped).returns(T.untyped) }
      def call(env)
        request = ActionDispatch::Request.new(env.dup)

        OpenTelemetry::Trace.current_span.add_attributes({
          OpenTelemetry::VERSION => PlugApp::Application::GIT_SHA,
          OpenTelemetry::SemanticConventions::Trace::HTTP_REQUEST_CONTENT_LENGTH => env["CONTENT_LENGTH"].to_i,
          HTTP_REQUEST_BODY => filtered_params(request),
        })

        app.call(env)
      end

      def filtered_params(request)
        params = request.params
        if request.path.starts_with?(PLUG_APP_PATH_PREFIX)
          {}
        else
          @filterer.filter(params)
        end.to_json
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hephaestus-0.6.2 templates/app/lib/plug_app/middleware/tracing_attributes.rb
hephaestus-0.6.1 templates/app/lib/plug_app/middleware/tracing_attributes.rb
hephaestus-0.6.0 templates/app/lib/plug_app/middleware/tracing_attributes.rb
hephaestus-0.5.2 templates/app/lib/plug_app/middleware/tracing_attributes.rb
hephaestus-0.5.1 templates/app/lib/plug_app/middleware/tracing_attributes.rb
hephaestus-0.5.0 templates/app/lib/plug_app/middleware/tracing_attributes.rb
hephaestus-0.4.0 templates/app/lib/plug_app/middleware/tracing_attributes.rb
hephaestus-0.3.1 templates/app/lib/plug_app/middleware/tracing_attributes.rb
hephaestus-0.2.3 templates/app/lib/plug_app/middleware/tracing_attributes.rb
hephaestus-0.2.2 templates/app/lib/plug_app/middleware/tracing_attributes.rb