Skip to content

Warn when ignoring on_error argument due to it not being a proc#4611

Merged
p-datadog merged 2 commits into
masterfrom
tracing-span-on-error-warning
Apr 29, 2025
Merged

Warn when ignoring on_error argument due to it not being a proc#4611
p-datadog merged 2 commits into
masterfrom
tracing-span-on-error-warning

Conversation

@p-datadog

@p-datadog p-datadog commented Apr 28, 2025

Copy link
Copy Markdown
Member

What does this PR do?

Adds a warning when customer provides on_error argument which is not a Proc. Previously the argument was silently ignored.

Motivation:

Better diagnostics of unexpected/incorrect usage of the library

Change log entry
Yes: warn when on_error argument is not a Proc (and would therefore be ignored)

Additional Notes:

The existing tests for on_error behavior had incorrect setup and did not actually test the path when on_error argument was not a proc.

How to test the change?
Repaired unit tests in this PR.

@p-datadog
p-datadog requested a review from a team as a code owner April 28, 2025 17:48
@p-datadog
p-datadog force-pushed the tracing-span-on-error-warning branch from 958c18e to dd00409 Compare April 28, 2025 17:55
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.73%. Comparing base (b9e1364) to head (7d9788b).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4611      +/-   ##
==========================================
- Coverage   97.74%   97.73%   -0.02%     
==========================================
  Files        1412     1412              
  Lines       86256    86260       +4     
  Branches     4354     4357       +3     
==========================================
- Hits        84315    84310       -5     
- Misses       1941     1950       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@datadog-datadog-prod-us1

Copy link
Copy Markdown
Contributor

Datadog Report

Branch report: tracing-span-on-error-warning
Commit report: 7d9788b
Test service: dd-trace-rb

✅ 0 Failed, 20838 Passed, 1376 Skipped, 3m 31.22s Total Time

@pr-commenter

pr-commenter Bot commented Apr 28, 2025

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2025-04-28 18:20:32

Comparing candidate commit 7d9788b in PR branch tracing-span-on-error-warning with baseline commit b9e1364 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 31 metrics, 2 unstable metrics.

@p-datadog
p-datadog merged commit 1cac121 into master Apr 29, 2025
@p-datadog
p-datadog deleted the tracing-span-on-error-warning branch April 29, 2025 12:05
@github-actions github-actions Bot added this to the 2.16.0 milestone Apr 29, 2025
p-datadog pushed a commit to p-datadog/dd-trace-rb that referenced this pull request Apr 30, 2025
* master: (25 commits)
  Continue on error
  Comment on Gemfile
  Run CI
  Avoid example redefinition warning in test suite (DataDog#4612)
  [NO-TICKET] Decouple environment variable from programmatic config precedence (DataDog#4610)
  Update rack/rails/sinatra to use security events
  Rewrite Event.record logic for non-attack events
  Warn when ignoring on_error argument due to it not being a proc (DataDog#4611)
  Bump the gh-actions-packages group across 3 directories with 6 updates
  Update Event to use SecurityEvent class
  Replace events with new SecurityEvent class
  Add new class SecurityEvent
  Rename AppSec API security method
  Rewrite Event#record public interface
  Add attack headers test to the rails contib
  Remove unused keys from the events
  Add new test scenarios for security event
  Change visibility of Event internal methods
  Rewrite Event#record specs
  Return complete rule files into assets
  ...
@Strech Strech mentioned this pull request May 19, 2025
@totus

totus commented May 21, 2025

Copy link
Copy Markdown

@p-datadog, @marcotc, with this change it seems that when there's no on_error configuration is provided, the warning is thrown like crazy, effectively polluting the log with nonsensical warnings!

@totus

totus commented May 21, 2025

Copy link
Copy Markdown

#4670 is a direct consequence

@p-datadog

Copy link
Copy Markdown
Member Author

@totus We are looking into the generated warnings, thank you very much for pointing them out.

The warnings however should only be produced when on_error is called with some (non-nil) argument, can you clarify what you mean by

when there's no on_error configuration is provided, the warning is thrown like crazy, effectively polluting the log with nonsensical warnings!

Do you mean when you did not provide an on_error argument, the library itself was producing the warnings?

@totus

totus commented May 21, 2025

Copy link
Copy Markdown

@p-datadog, exactly. When a gem is simply being included without any specific configuration, it produces the warnings.

To be more specific, even in our test repo with a configuration like this:

# Datadog tracing
require "datadog/auto_instrument" if ENV["DD_ENV"] == "ci"

Datadog.configure do |c|
  c.ci.enabled = ENV.fetch("DD_ENV", false) == "ci"
  c.tracing.enabled = ENV.fetch("DD_ENV", false) == "ci"
  c.service = ENV.fetch("DD_SERVICE", nil)
  c.ci.instrument :cucumber
end

The test execution is polluted with log entries:

W, [2025-05-21T03:47:15.590188 #1998]  WARN -- datadog: [datadog] on_error argument to SpanOperation ignored because is not a Proc: #<Method: Net::HTTP(Datadog::Tracing::Contrib::HTTP::Instrumentation::InstanceMethods)#annotate_span_with_error!(span, error) /home/runner/work/repo-name/repo-name/vendor/bundle/ruby/3.4.0/gems/datadog-2.16.0/lib/datadog/tracing/contrib/http/instrumentation.rb:115>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants