Sha256: cae47f4a299651e680d377c9ed6b3dfa2591a0ba146bc9759b0a06fa5b83d8f3

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

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

# require_relative 'command_serializer'

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

6 entries across 6 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-active_model_serializers-0.16.0 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb
opentelemetry-instrumentation-active_model_serializers-0.15.0 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb
opentelemetry-instrumentation-active_model_serializers-0.14.0 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb
opentelemetry-instrumentation-active_model_serializers-0.13.0 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb
opentelemetry-instrumentation-active_model_serializers-0.12.0 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb
opentelemetry-instrumentation-active_model_serializers-0.11.0 lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb