Sha256: 40a3dc83a6e40555522eb54ab119c222873d00edd84b859aa7f7605486d5769d

Contents?: true

Size: 1.06 KB

Versions: 14

Compression:

Stored size: 1.06 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
          # Sinatra hook after extension is registered
          def self.registered(app)
            # Create tracing `render` method
            ::Sinatra::Base.module_eval do
              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

            app.use Middlewares::TracerMiddleware
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-sinatra-0.20.0 lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb
opentelemetry-instrumentation-sinatra-0.19.4 lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb
opentelemetry-instrumentation-sinatra-0.19.3 lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb
opentelemetry-instrumentation-sinatra-0.19.2 lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb
opentelemetry-instrumentation-sinatra-0.19.1 lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb
opentelemetry-instrumentation-sinatra-0.19.0 lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb
opentelemetry-instrumentation-sinatra-0.18.0 lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb
opentelemetry-instrumentation-sinatra-0.17.0 lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb
opentelemetry-instrumentation-sinatra-0.16.0 lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb
opentelemetry-instrumentation-sinatra-0.15.0 lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb
opentelemetry-instrumentation-sinatra-0.14.0 lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb
opentelemetry-instrumentation-sinatra-0.13.0 lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb
opentelemetry-instrumentation-sinatra-0.12.0 lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb
opentelemetry-instrumentation-sinatra-0.11.0 lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb