Skip to content

Starlette instrumentation not working #113

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

Open
Vuenc opened this issue Mar 24, 2025 · 0 comments
Open

Starlette instrumentation not working #113

Vuenc opened this issue Mar 24, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@Vuenc
Copy link

Vuenc commented Mar 24, 2025

Describe the bug
We noticed that our instrumented Starlette application does not show up in Dynatrace. The issue seems to be in the instrumentation code at autodynatrace/wrappers/starlette/wrapper.py:

def instrument():
    @wrapt.patch_function_wrapper("starlette.responses", "Response.__init__")
    def starlette_parsing_dynatrace(wrapped, instance, args, kwargs):

        # FastAPI creates a empty response at the beginning of a request, ignore it
        if kwargs.get("status_code") is None:
            return wrapped(*args, **kwargs)

        logger.debug("Tracing starlette.Response.__init__")
        with sdk.trace_custom_service("Response.render", "starlette"):
            return wrapped(*args, **kwargs)

The first if statement checks for a status_code argument in kwargs on initialization of a Response, but this is not reliable, since the status code may also be passed as normal argument. In our case, the Starlette JSONResponse passes its constructor arguments to its superclass as positional arguments, not keyword arguments. Because of this, the tracing code is never reached.

@Vuenc Vuenc added the bug Something isn't working label Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant