Let Rake spans be disabled programmatically #200
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which problem is this PR solving?
When running a Rake task, the Honeycomb integration typically creates the root node of the trace (since the task is the entry point into the program). For short-lived tasks like
rake db:migrate
, this works great. However, tasks might be long-lived. For example,rake resque:work
runs forever, dequeueing background jobs on a loop. Ideally, we'd like a separate trace for each job that gets dequeued. But with the Rake integration enabled, all the jobs' traces point back up at the auto-generated root span, which will be missing until the worker process finally dies. This has been discussed before in Pollinators: https://honeycombpollinators.slack.com/archives/CJR134U2F/p1643989199035879As-is, the only way to disable the Rake integration is to remove it from the
HONEYCOMB_INTEGRATIONS
env var. There's a bug in the implementation ofRake::Application#honeycomb_client
such that setting it tonil
doesn't disable the Rake tracing (same sort of bug as in #60). Moreover, we can't pick & choose which Rake tasks generate a span. So if we disable the Rake integration altogether,rake resque:work
might look good, but something likerake db:migrate
will just generate a bunch of orphans that can't be tied back to a single parent.This PR allows you to programmatically disable the Rake integration both on the application level and the individual task level.
Short description of the changes
Rake::Application#honeycomb_client
so that it will honor when we set it tonil
.Rake::Task#honeycomb_client
so that it can be customized similarly to the application-level client.test:client:access
task.With this, you can selectively disable individual Rake tasks' auto-generated spans by saying
Alternatively, you could disable Rake at the application level and opt-in to the tracing at the task level:
Other thoughts:
Honeycomb::Configuration
option just to keep the change as simple as possible. It's perhaps not the most user-friendly, but it is maximally flexible: use whatever arbitrary logic you want to toggle the client tonil
.