For a while I’ve been working on a couple shards for instrumenting Crystal apps: Datadog and also OpenTelemetry for vendor-agnostic instrumentation. With both shards, writing integrations is quite simple — you basically monkey patch the methods and wrap them with TheShardName.trace { previous_def }
while setting various span attributes.
The problem is that this leads to pretty frustrating compilation times, at least on macOS (not on Linux for some reason), to the point where I have to disable instrumentation in development with flags like -Ddatadog
or -Dotel
(and stub the calls for manually instrumented code) to get it back down to a reasonable level. My apps normally take 3-6 seconds to compile when I make a change and I’ve seen the build times go up to a full minute just by loading instrumentation.
What I’m wondering is, is there a better pattern for this that won’t hurt compilation time? I remember @bcardiff once mentioned working on patterns for it to avoid monkeypatching (which is great because what the core team recommends often becomes an ecosystem-wide convention) but I also wanted to see if the community has some ideas for it.