Sha256: d36925d88df4f19fec193fe994a6db361008794ee13457dc2c1ea794c972c41c

Contents?: true

Size: 1.29 KB

Versions: 12

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

module OpenTelemetry
  module Instrumentation
    module ActiveModelSerializers
      # Event handler singleton for ActiveModelSerializers
      module EventHandler
        extend self

        def handle(start_timestamp, end_timestamp, payload)
          tracer.start_span(span_name(payload),
                            start_timestamp: start_timestamp,
                            attributes: build_attributes(payload),
                            kind: :internal)
                .finish(end_timestamp: end_timestamp)
        end

        protected

        def span_name(payload)
          "#{demodulize(payload[:serializer].name)} render"
        end

        def build_attributes(payload)
          {
            'serializer.name' => payload[:serializer].name,
            'serializer.renderer' => 'active_model_serializers',
            'serializer.format' => payload[:adapter]&.class&.name || 'default'
          }
        end

        def tracer
          ActiveModelSerializers::Instrumentation.instance.tracer
        end

        def demodulize(string)
          string = string.to_s
          i = string.rindex('::')
          i ? string[(i + 2)..-1] : string
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-active_model_serializers-0.20.2 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb
opentelemetry-instrumentation-active_model_serializers-0.20.1 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb
opentelemetry-instrumentation-active_model_serializers-0.20.0 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb
opentelemetry-instrumentation-active_model_serializers-0.19.1 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb
opentelemetry-instrumentation-active_model_serializers-0.19.0 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb
opentelemetry-instrumentation-active_model_serializers-0.18.5 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb
opentelemetry-instrumentation-active_model_serializers-0.18.4 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb
opentelemetry-instrumentation-active_model_serializers-0.18.3 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb
opentelemetry-instrumentation-active_model_serializers-0.18.2 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb
opentelemetry-instrumentation-active_model_serializers-0.18.1 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb
opentelemetry-instrumentation-active_model_serializers-0.18.0 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb
opentelemetry-instrumentation-active_model_serializers-0.17.0 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb