-
Notifications
You must be signed in to change notification settings - Fork 136
Make app field optional in Flask, Starlette and FastAPI instrumentations #1228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Deploying logfire-docs with
|
Latest commit: |
8e22479
|
Status: | ✅ Deploy successful! |
Preview URL: | https://566fc505.logfire-docs.pages.dev |
Branch Preview URL: | https://kludex-feat-no-need-for-app.logfire-docs.pages.dev |
@@ -48,7 +48,7 @@ def find_mounted_apps(app: FastAPI) -> list[FastAPI]: | |||
|
|||
def instrument_fastapi( | |||
logfire_instance: Logfire, | |||
app: FastAPI, | |||
app: FastAPI | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment about how this differs from public signature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please suggest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that
Logfire.instrument_fastapi
requires this argument. It's only omitted when called via thelogfire run
CLI. This is becauseFastApiInstrumentor.instrument()
has to be called beforefrom fastapi import FastAPI
which is easy to get wrong.
**opentelemetry_kwargs, | ||
) | ||
if app is None: | ||
FastAPIInstrumentor().instrument( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it seems too hard to also apply the other fastapi instrumentation, at least comment about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have the app instance, how would I go about it to make the custom logic work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if request.app not in registry
then check for a 'global' FastAPIInstrumentation
next.
@alexmojaki As I told you, this only works if instrumentation happens before import.