Code Monkey home page Code Monkey logo

Comments (5)

JWCook avatar JWCook commented on July 17, 2024 2

Changes are in main and will be included in the next release.

from aiohttp-client-cache.

JWCook avatar JWCook commented on July 17, 2024 2

These changes are available in v0.9.

from aiohttp-client-cache.

JWCook avatar JWCook commented on July 17, 2024

Could you provide a complete code example that reproduces the problem? I am not familiar with how Sentry interfaces with aiohttp's ClientSession.

from aiohttp-client-cache.

TedCassirer avatar TedCassirer commented on July 17, 2024

@JWCook
Hi
I've created a basic example that demonstrates this behavior. It sends two identical requests using, one before initializing Sentry, and a second one after initializing Sentry. The expected behavior is for the client to use the specified request class. But only the first request use CustomRequest as seen by the printed output

Dependencies:

python = "^3.11"
sentry-sdk = "^1.29.2"
aiohttp = "^3.8.5"
aiohttp-client-cache = {extras = ["all"], version = "^0.8.2"}

Code:

import asyncio

import sentry_sdk
from aiohttp import ClientRequest, ClientResponse
from aiohttp.connector import Connection
from aiohttp_client_cache import CachedSession


class CustomRequest(ClientRequest):
    async def send(self, conn: Connection) -> ClientResponse:
        print("Custom request class used!")
        return await super().send(conn)


async def send_request():
    print("Sending a request")
    async with CachedSession(request_class=CustomRequest) as session:
        await session.get('https://example.org/')
    print("Request completed\n")


if __name__ == '__main__':
    asyncio.run(send_request())

    print("Initializing Sentry and sending another request")
    sentry_sdk.init()
    asyncio.run(send_request())

stdout:

Sending a request
Custom request class used!
Request completed

Initializing Sentry and sending another request
Sending a request
Request completed

Hope this helps

from aiohttp-client-cache.

JWCook avatar JWCook commented on July 17, 2024

Thank you for the details!

It's a bit hard to follow exactly how sentry_sdk.init() modifies the session, but I can at least confirm that it changes the init signature to __init__(*args, **kwargs). I think we can handle this during inspection by checking for the Parameter.VAR_KEYWORD type.

from aiohttp-client-cache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.