add rails.application to process tags when available#5468
Conversation
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: a2c819d | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
BenchmarksBenchmark execution time: 2026-03-25 21:44:54 Comparing candidate commit ba91576 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 46 metrics, 0 unstable metrics.
|
…il causing underscore to fail.
…nd update tests and utils to fail safely.
Co-authored-by: Sergey Fedorov <oni.strech@gmail.com>
p-datadog
left a comment
There was a problem hiding this comment.
Nice work overall.
That said — it feels like process.rb picking up a Rails dependency might work against the grain of Core. Right now Process is entirely framework-agnostic (just $0, Dir.pwd, File), and the require of Core::Contrib::Rails is the first thing to break that. Left a thought inline.
… other features like profiling only apps can get the rails app name, remove the interaction of rails specific logic inside the process tags logic and clean up tests
…ils::Railtie:Class error
|
Note: I just created #5504 as a follow up to this PR because ProcessDiscovery publishes before the rails app is initialized. |
p-datadog
left a comment
There was a problem hiding this comment.
👍 Really like where this landed. The setter on Process is exactly the right decoupling — and the core-level Railtie is a really nice touch. That solves the profiling-only and AppSec-only cases marcotc raised, which the patcher approach wouldn't have covered. Clean solution all around.
Two small suggestions inline.
Co-authored-by: Oleg Pudeyev <156273877+p-datadog@users.noreply.github.com>
Co-authored-by: Oleg Pudeyev <156273877+p-datadog@users.noreply.github.com>
What does this PR do?
Adds the Rails application name to the process tags list to give Rails users a way to differentiate the application, listed as
rails.application. However, we need this information on ALL products (DI, Profiling, Tracing) regardless of whether tracing is enabled so that service renaming can occur consistently.Attempt 1: This PR also adds a "recompute" functionality in the process.rb because it turns out that Rails apps don't have access to their name until AFTER initialization. I found this out because I up a real Rails app and noticed the process tags with the default Rails utils was returning no name.Update: the approach above failed so it's crossed out now because it turns out that profiles never run through the
after_initializelogic if someone doesn't use tracing, so now there's a new approach.lib/datadog/core/environment/process.rbhas been updated to allow settingself.rails_application_name=(name)anywhere else in codelib/datadog/core/configuration/components.rbhas been updated to load inlib/datadog/core/contrib/rails/railtie.rbwhen a Rails app startslib/datadog/core/contrib/rails/railtie.rbis used to add after_initialize logic for any product when a Rails app is active. Within this we update the Rails application name.Now we'll recompute the process tags after Rails initialization, and here's an example of how it will appear in the Profiles under "Runtime Info":

Motivation:
This came about from an investigation with @marcotc and @raphaelgavache into the way the default Rails Dockerfile stores apps. (Anything using that base Dockerfile will store the app in the same app folder, so the existing process tags are not unique enough).
Change log entry
Yes. Add
rails.applicationto the process tags.Additional Notes:
This reuses the existing Rails utils and updates the process tags, but the utils had to be refactored. You may ask, "why"?
Reason 1: CI was failing on not being able to call underscore on a nil
Example: https://github.com/DataDog/dd-trace-rb/actions/runs/23263729755/job/67639506905?pr=5468
I updated the utils to skip trying to do call underscore if the parent namespace is missing.
Reason 2: But then I ran into an exception error because sometimes the CI doesn't have access to the app name yet?
To deal with this, some error handling was added and tests.
Example run: https://github.com/DataDog/dd-trace-rb/actions/runs/23265763535/job/67646150038?pr=5468
Both errors showed that there were some Rails/CI specific ordering that prevent the Rails app name from being obtained.
How to test the change?
I tested with a Rails 8 that I sent data to the backend for.
TODOS
rails.applicationvs something more general? -> Answer: we'll keep it as rails.application for now.