A discussion on adding a Datadog APM initializer in a custom Discourse plugin. raph wants to use a plugin to configure Datadog APM instrumentation and is looking for a way to load an initializer early in the Discourse app’s lifetime.
sam suggests using the after_initialize method, but raph finds that the ddtrace gem expects to run in before_initialize as well, which is not a valid method in plugin.rb. raph considers folding instrumentation logic into the plugin itself, similar to discourse-prometheus, as an alternative.
jeffbyrnes asks if raph ever got the plugin working, even with automatic instrumentation.
The usual way of configuring a Rails app for APM is to use an initializer - I’m not (yet) deeply familiar with the plugin system in discourse. Is there any way to load such an initializer early in the lifetime of the discourse app using the existing plugin system? If not, what other options exist? I’d prefer not to have to fork the entire app for the purpose of adding a single initializer
@sam I tried that but apparently this particular ddtrace gem expects to be able to run in before_initialize, too. But it doesn’t seem like before_initialize is a valid method in plugin.rb. Are there any other options for a plugin to run earlier in the lifecycle of the app?
My next step would be to not use the automagic instrumentation that is applied with that gem’s “patchers” but instead fold some of the actual instrumentation logic into the plugin itself, similar to how you’ve done it with discourse-prometheus. I guess that would make sense anyway to plug into some of the specifics of discourse. Was just hoping there’s a way to leverage the magic that I haven’t seen yet.