raven-python icon indicating copy to clipboard operation
raven-python copied to clipboard

Setting transport class in logging dict config

Open aspyatkin opened this issue 7 years ago • 1 comments
trafficstars

Hello, I have encountered a problem after upgrading from raven 5.x and not sure how to deal with it better.

In older raven versions it was allowed to set Transport in DSN parameter. Since my applications make use of logging dict config, I used to set Transport there. From now on it produces a warning Transport selection via DSN is deprecated. I was not able to set Transport class explicitly in logging dict config:

handlers:
  default:
    level: DEBUG
    class: logging.StreamHandler
    formatter: default
    stream: ext://sys.stdout
  sentry:
    level: INFO
    class: raven.handlers.logging.SentryHandler
    dsn: http://*****:*****@sentry.*****.local/11
    transport: raven.transport.threaded_requests.ThreadedRequestsHTTPTransport
    environment: development

Judging by the code, SentryHandler won't be instantiated if transport is of type str and not callable. I wonder if there is an other way to set Transport class in logging dict config? Might an extra parameter transport_class be implemented in next versions so as to instruct SentryHandler to load the desired type of Transport by its string identifier?

aspyatkin avatar Feb 14 '18 06:02 aspyatkin

This code block in RemoteConfig __init__ seems to solve the problem, but I guess it only works in Python 2.7:

        self.store_endpoint = store_endpoint

        # begin
        if isinstance(transport, basestring):
            transport_class_module = '.'.join(transport.split('.')[0:-1])
            transport_module = importlib.import_module(transport_class_module)
            transport_class_name = transport.split('.')[-1]
            if hasattr(transport_module, transport_class_name):
                transport = getattr(transport_module, transport_class_name)
        # end

        self._transport_cls = transport or DEFAULT_TRANSPORT

aspyatkin avatar Feb 14 '18 07:02 aspyatkin