Sha256: 80728239d3f8a295ef67b615d5506f699cd8506d4ae1388aae8768db28dc2b65

Contents?: true

Size: 1.05 KB

Versions: 7

Compression:

Stored size: 1.05 KB

Contents

module Skylight
  module Normalizers
    module Coach
      class HandlerFinish < Normalizer
        register "coach.handler.finish"

        CAT = "app.coach.handler".freeze

        # See information on the events Coach emits here:
        # https://github.com/gocardless/coach#instrumentation

        # Run when the handler first starts, we need to set the trace endpoint to be the
        # handler name.
        #
        # We can expect the payload to have the :middleware key.
        def normalize(trace, name, payload)
          trace.endpoint = payload[:middleware]
          [ CAT, payload[:middleware], nil ]
        end

        def normalize_after(trace, span, name, payload)
          return unless config.enable_segments?

          segments = []

          response_status = payload.fetch(:response, {}).fetch(:status, '').to_s
          segments << "error" if response_status.start_with?('4', '5')

          if segments.any?
            trace.endpoint += "<sk-segment>#{segments.join("+")}</sk-segment>"
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
skylight-1.7.2 lib/skylight/normalizers/coach/handler_finish.rb
skylight-1.7.1 lib/skylight/normalizers/coach/handler_finish.rb
skylight-1.7.0 lib/skylight/normalizers/coach/handler_finish.rb
skylight-1.6.1 lib/skylight/normalizers/coach/handler_finish.rb
skylight-1.6.0 lib/skylight/normalizers/coach/handler_finish.rb
skylight-1.5.1 lib/skylight/normalizers/coach/handler_finish.rb
skylight-1.5.0 lib/skylight/normalizers/coach/handler_finish.rb