-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate only when the object has been initialized
Previous integrations in the SDK were done by importing rollbar.contrib.'framework'. Since `rollbar._build_person_data()` needs to import Starlette integration, this sets the Starlette hook for the SDK even if not explicility integrated. Under certain cicrumstances, this can result in erroneously add Starlette framework information to the payload and associate occurence with Starlette integration. For now, integration with SDK is make only if integration function/class is called. Fix [ch85137]
- Loading branch information
Showing
18 changed files
with
174 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,3 @@ | ||
__all__ = ['ReporterMiddleware'] | ||
|
||
import rollbar | ||
|
||
from .middleware import ReporterMiddleware | ||
|
||
|
||
def _hook(request, data): | ||
data['framework'] = 'asgi' | ||
|
||
|
||
rollbar.BASE_DATA_HOOK = _hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,8 @@ | ||
__all__ = ['add_to', 'ReporterMiddleware', 'LoggerMiddleware', 'get_current_request'] | ||
|
||
from fastapi import __version__ | ||
|
||
import rollbar | ||
from .middleware import ReporterMiddleware | ||
from .logger import LoggerMiddleware | ||
from .routing import add_to | ||
|
||
# Do not modify the returned request object | ||
from rollbar.contrib.starlette import get_current_request | ||
|
||
|
||
def _hook(request, data): | ||
data['framework'] = f'fastapi {__version__}' | ||
|
||
|
||
rollbar.BASE_DATA_HOOK = _hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
__all__ = ['LoggerMiddleware'] | ||
|
||
import logging | ||
from fastapi import __version__ | ||
|
||
from rollbar.contrib.asgi.integration import integrate | ||
from rollbar.contrib.starlette import LoggerMiddleware as StarletteLoggerMiddleware | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
@integrate(framework_name=f'fastapi {__version__}') | ||
class LoggerMiddleware(StarletteLoggerMiddleware): | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
__all__ = ['ReporterMiddleware'] | ||
|
||
from fastapi import __version__ | ||
|
||
from rollbar.contrib.asgi.integration import integrate | ||
from rollbar.contrib.starlette import ReporterMiddleware as StarletteReporterMiddleware | ||
|
||
|
||
@integrate(framework_name=f'fastapi {__version__}') | ||
class ReporterMiddleware(StarletteReporterMiddleware): | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,7 @@ | ||
__all__ = ['ReporterMiddleware', 'LoggerMiddleware', 'get_current_request'] | ||
|
||
from starlette import __version__ | ||
|
||
import rollbar | ||
from .middleware import ReporterMiddleware | ||
from .logger import LoggerMiddleware | ||
|
||
# Do not modify the returned request object | ||
from .requests import get_current_request | ||
|
||
|
||
def _hook(request, data): | ||
data['framework'] = f'starlette {__version__}' | ||
|
||
|
||
rollbar.BASE_DATA_HOOK = _hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
import importlib | ||
import sys | ||
from rollbar.test import BaseTest | ||
|
||
try: | ||
from unittest import mock | ||
except ImportError: | ||
import mock | ||
|
||
import unittest2 | ||
class IntegrationTest(BaseTest): | ||
def test_should_integrate_if__integrate_defined(self): | ||
from rollbar.contrib.asgi.integration import IntegrationBase | ||
|
||
import rollbar | ||
import rollbar.contrib.asgi | ||
from rollbar.test import BaseTest | ||
called = False # cannot patch local objects | ||
|
||
class Integration(IntegrationBase): | ||
def _integrate(self): | ||
nonlocal called | ||
called = True | ||
|
||
self.assertTrue(hasattr(Integration, '_integrate')) | ||
|
||
obj = Integration() | ||
|
||
self.assertTrue(called) | ||
self.assertTrue(hasattr(obj, '_integrate')) | ||
|
||
def test_should_not_fail_if__integrate_not_exists(self): | ||
from rollbar.contrib.asgi.integration import IntegrationBase | ||
|
||
ALLOWED_PYTHON_VERSION = sys.version_info >= (3, 5) | ||
class WrongIntegration(IntegrationBase): | ||
... | ||
|
||
self.assertFalse(hasattr(WrongIntegration, '_integrate')) | ||
|
||
@unittest2.skipUnless(ALLOWED_PYTHON_VERSION, 'ASGI implementation requires Python3.5+') | ||
class ASGIIntegrationTest(BaseTest): | ||
def setUp(self): | ||
importlib.reload(rollbar.contrib.asgi) | ||
obj = WrongIntegration() | ||
|
||
def test_should_set_asgi_hook(self): | ||
self.assertEqual(rollbar.BASE_DATA_HOOK, rollbar.contrib.asgi._hook) | ||
self.assertFalse(hasattr(obj, '_integrate')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.