Skip to content

Commit

Permalink
Allow rails runner to eval when an active span can't be detected
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerwillingham committed Oct 11, 2024
1 parent cdfc685 commit 1430cbc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/rails/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def runner(code_or_file = nil, *_command_argv)
# Capture the executed source code when provided from STDIN.
def eval(*args)
span = Datadog::Tracing.active_span
if span.name == Ext::SPAN_RUNNER_STDIN
if span&.name == Ext::SPAN_RUNNER_STDIN
source = args[0]
span.set_tag(
Ext::TAG_RUNNER_SOURCE,
Expand Down
8 changes: 8 additions & 0 deletions spec/datadog/tracing/contrib/rails/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@
expect(span.get_tag('operation')).to eq('runner.inline')
end

context "when a current span isn't detected" do
it "doesn't error when a span can't be identified to set the source tag on" do
allow(Datadog::Tracing).to receive(:active_span).and_return(nil)

expect { run }.to output('OK').to_stdout
end
end

include_context 'with a custom service name'
include_context 'with source code too long'

Expand Down

0 comments on commit 1430cbc

Please sign in to comment.