Skip to content

fix: handle force_flush for rake task with arguments #1412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ def tracer
end

def force_flush
OpenTelemetry.tracer_provider.force_flush if ::Rake.application.top_level_tasks.include?(name)
top_level_task_names = ::Rake.application.top_level_tasks.map { |t| t.split('[').first }

if top_level_task_names.include?(name)
OpenTelemetry.tracer_provider.force_flush
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@
_(execute_span.parent_span_id).must_equal(invoke_span.span_id)
end

describe 'with a task argument' do
it 'should call force_flush on OpenTelemetry.tracer_provider' do
mock = Minitest::Mock.new
mock.expect(:force_flush, nil)
mock.expect(:force_flush, nil)

Rake::Task.define_task("#{task_name}[:arg]")
task_string = "#{task_name}[test_arg]"

Rake.application.instance_eval { @top_level_tasks = [task_string] }

OpenTelemetry.stub(:tracer_provider, mock) do
Rake.application.invoke_task(task_string)
end

mock.verify
end
end

describe 'with a prerequisite task' do
before do
Rake::Task.define_task(prerequisite_task_name)
Expand Down
Loading