Open adriangb opened 3 years ago
You've correctly discovered that instrumentation must be applied/activated before importing any the libraries that are to be instrumented. It may work for some apps even if it is applied post-import but by design it is supposed to be applied pre-import.
There are a few things being raised here.
instrument_app()
method like Flask so that users can use the auto-inject mechanism on a single app/api instance.app = MyFalconApp()
FalconInstrumentor.instrument_app(app)
My only concern is about 2. I think it can be useful to make the middleware available for direct use but using the middleware directly might not always result in the same telemetry data as generated by auto-instrumentation but I suppose if that is documented, it should be fine.
I don't see why we cannot do these but I'd suggest to open a different issue for each topic.
This problem is one of the reasons option 3 was used in the Flask instrumentation, I suggest we follow the same approach to fix this one.
Yep that does seem like a good first step at least.
@srikanthccv Does this issue still needs working? If it's a beginner friendly issue I'd like to work on it please.
This could be considered a bug, poorly documented behavior or just fragility of monkey patching.
This can be fixed by instrumenting before
from falcon import App
andfrom app import MyApp
:But:
I understand the desire to provide users with "auto-instrumentation" by means a single function call / even running
opentelemetry-instrument
on unmodified code. It's super cool! But it can't be the only way to do things. As demonstrated here there are a lot of rough edges to this.It would be nice if the API was presented in a layered fashion:
opentelemetry-instrument
FalconInstrumentor.instrument()
This way, users can just go with
opentelemtry-instrument
if that works for them. But if that doesn't work, they have the option to peel back the onion, read a bit deeper into the docs and understand how to add the middleware themselves and such. This also decreases the burden of functionality of auto-instrumentation: if in certain situations it is too hard / fragile / hacky to get something working via auto-instrumentation, but it is possible with a bit more work (e.g. a WSGI wrapper), this can be documented as "if you want XYZ advanced feature, you can instrument yourself and configure it following this example".