Skip to content
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

FastAPI requests handled by middleware are always "generic ASGI request" #2263

Closed
antonpirker opened this issue Jul 19, 2023 · 1 comment · Fixed by #2341
Closed

FastAPI requests handled by middleware are always "generic ASGI request" #2263

antonpirker opened this issue Jul 19, 2023 · 1 comment · Fixed by #2341

Comments

@antonpirker
Copy link
Member

I have a problem, that requests in FastAPI that get handled by a middleware, such as 404s or OPTIONS for CORS, are reported as "generic ASGI request" for transaction name. It seems like there should be an fix - all of these requests have enough information to name them at least a bit more specific, such as by the name of the middleware, the URI + method, or similar.

@antonpirker antonpirker self-assigned this Jul 19, 2023
@antonpirker
Copy link
Member Author

Related to #1599

antonpirker added a commit that referenced this issue Sep 6, 2023
Set the url as a transaction name instead of 'generic ASGI request' in the beginning, so traces_sampler has something to work with that is more meaningful than 'generic ASGI request'.

Closes #2262
Closes #2263
New Behaviour:

Note: transaction names can be two styles, "url" or "endpoint". (set by the transaction_style parameter of the Integrations)

Note 2: See also @pytest.mark.parametrize decorator in the new tests as reference.

    vanilla ASGI: set URL instead of always "generic ASGI request"
    Starlette:
        normal request: transaction name is function name or route (depending on transaction_style setting)
        traces_sampler: always receives the raw URL as the transaction name (no matter the transaction_style setting. because we do not know more at the time the traces_sampler is called.)
        requests that end in a middleware (like 404, CORS): the functions name or the raw URL (depending on transaction_style setting)
    FastAPI
        normal request: transaction name is function name or route (depending on transaction_style setting)
        traces_sampler: always receives the raw URL as the transaction name (no matter the transaction_style setting. because we do not know more at the time the traces_sampler is called.)
        requests that end in a middleware (like 404, CORS): the functions name or the raw URL (depending on transaction_style setting)
    There used to be "generic ASGI request" transactions being created at the server startup (when a "lifespan" ASGI message was received.) Those transactions are not created anymore. (we can think of creating propper "Server was started/stopped" transactions in the future)
sentrivana pushed a commit that referenced this issue Sep 18, 2023
Set the url as a transaction name instead of 'generic ASGI request' in the beginning, so traces_sampler has something to work with that is more meaningful than 'generic ASGI request'.

Closes #2262
Closes #2263
New Behaviour:

Note: transaction names can be two styles, "url" or "endpoint". (set by the transaction_style parameter of the Integrations)

Note 2: See also @pytest.mark.parametrize decorator in the new tests as reference.

    vanilla ASGI: set URL instead of always "generic ASGI request"
    Starlette:
        normal request: transaction name is function name or route (depending on transaction_style setting)
        traces_sampler: always receives the raw URL as the transaction name (no matter the transaction_style setting. because we do not know more at the time the traces_sampler is called.)
        requests that end in a middleware (like 404, CORS): the functions name or the raw URL (depending on transaction_style setting)
    FastAPI
        normal request: transaction name is function name or route (depending on transaction_style setting)
        traces_sampler: always receives the raw URL as the transaction name (no matter the transaction_style setting. because we do not know more at the time the traces_sampler is called.)
        requests that end in a middleware (like 404, CORS): the functions name or the raw URL (depending on transaction_style setting)
    There used to be "generic ASGI request" transactions being created at the server startup (when a "lifespan" ASGI message was received.) Those transactions are not created anymore. (we can think of creating propper "Server was started/stopped" transactions in the future)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants