Sha256: 0fc792d4fa548a0b0ab02d3cb56d5d92ecc8e6efcaf69610f5010430e4b62465

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

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

require_relative '../middlewares/tracer_middleware'

module OpenTelemetry
  module Instrumentation
    module Sinatra
      module Extensions
        # Sinatra extension that installs TracerMiddleware and provides
        # tracing for template rendering
        module TracerExtension
          # Contants patches for `render` method
          module RenderPatches
            def render(_engine, data, *)
              template_name = data.is_a?(Symbol) ? data : :literal

              Sinatra::Instrumentation.instance.tracer.in_span(
                'sinatra.render_template',
                attributes: { 'sinatra.template_name' => template_name.to_s }
              ) do
                super
              end
            end
          end

          # Sinatra hook after extension is registered
          def self.registered(app)
            # Create tracing `render` method
            ::Sinatra::Base.prepend(RenderPatches)
            Sinatra::Instrumentation.instance.install_middleware(app)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-sinatra-0.24.1 lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb
opentelemetry-instrumentation-sinatra-0.24.0 lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb