Sha256: 19a74a10fc0a2efa88de115d2d66b3888788aea99bdbe4173c33ab20e576ed59

Contents?: true

Size: 899 Bytes

Versions: 5

Compression:

Stored size: 899 Bytes

Contents

# frozen_string_literal: true

module OpenTelemetry
  module Instrumentation
    module Rake
      module Patches
        # Module to prepend to Rask::Task for instrumentation
        module Task
          def invoke(*args)
            tracer.in_span('rake.invoke', attributes: { 'rake.task' => name }) do
              super
            end
          ensure
            force_flush
          end

          def execute(args = nil)
            tracer.in_span('rake.execute', attributes: { 'rake.task' => name }) do
              super
            end
          ensure
            force_flush
          end

          private

          def tracer
            Rake::Instrumentation.instance.tracer
          end

          def force_flush
            OpenTelemetry.tracer_provider.force_flush if ::Rake.application.top_level_tasks.include?(name)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-rake-0.2.2 lib/opentelemetry/instrumentation/rake/patches/task.rb
opentelemetry-instrumentation-rake-0.2.1 lib/opentelemetry/instrumentation/rake/patches/task.rb
opentelemetry-instrumentation-rake-0.2.0 lib/opentelemetry/instrumentation/rake/patches/task.rb
opentelemetry-instrumentation-rake-0.1.1 lib/opentelemetry/instrumentation/rake/patches/task.rb
opentelemetry-instrumentation-rake-0.1.0 lib/opentelemetry/instrumentation/rake/patches/task.rb