Skip to content

Commit 160c40e

Browse files
authored
Scout APM Monitoring (#309)
* add scout-apm package * add scout-apm config * add scout apm middleware
1 parent 37a1ad0 commit 160c40e

File tree

6 files changed

+156
-3
lines changed

6 files changed

+156
-3
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ idna_ssl = {version = "*",markers = "python_version<'3.7'"}
3232
pydantic = {extras = ["dotenv"],version = "*"}
3333
python-dateutil = "*"
3434
requests = "*"
35+
scout-apm = "*"
3536
uvicorn = "*"
3637

3738
[requires]

Pipfile.lock

Lines changed: 135 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class _Settings(BaseSettings):
1111
port: int = 5000
1212
rediscloud_url: AnyUrl = None
1313
local_redis_url: AnyUrl = None
14+
# Scout APM
15+
scout_name: str = None
1416

1517

1618
@functools.lru_cache()

app/main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from fastapi.middleware.cors import CORSMiddleware
1010
from fastapi.middleware.gzip import GZipMiddleware
1111
from fastapi.responses import JSONResponse
12+
from scout_apm.async_.starlette import ScoutMiddleware
1213

1314
from .config import get_settings
1415
from .data import data_source
@@ -39,6 +40,13 @@
3940
# Middleware
4041
#######################
4142

43+
# Scout APM
44+
if SETTINGS.scout_name: # pragma: no cover
45+
LOGGER.info(f"Adding Scout APM middleware for `{SETTINGS.scout_name}`")
46+
APP.add_middleware(ScoutMiddleware)
47+
else:
48+
LOGGER.debug("No SCOUT_NAME config")
49+
4250
# Enable CORS.
4351
APP.add_middleware(
4452
CORSMiddleware, allow_credentials=True, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"],

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ smmap==3.0.2
4343
stevedore==1.32.0
4444
toml==0.10.0
4545
typed-ast==1.4.1
46-
urllib3==1.25.9
46+
urllib3[secure]==1.25.9 ; python_version >= '3.5'
4747
wcwidth==0.1.9
4848
wrapt==1.12.1
4949
zipp==3.1.0

requirements.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ aiocache[redis]==0.11.1
33
aiofiles==0.5.0
44
aiohttp==3.6.2
55
aioredis==1.3.1
6+
asgiref==3.2.7 ; python_version >= '3.5'
67
async-timeout==3.0.1
78
asyncache==0.1.1
89
attrs==19.3.0
910
cachetools==4.1.0
1011
certifi==2020.4.5.1
12+
cffi==1.14.0
1113
chardet==3.0.4
1214
click==7.1.2
15+
cryptography==2.9.2
1316
dataclasses==0.6 ; python_version < '3.7'
1417
fastapi==0.54.1
1518
gunicorn==20.0.4
@@ -19,14 +22,19 @@ httptools==0.1.1 ; sys_platform != 'win32' and sys_platform != 'cygwin' and plat
1922
idna-ssl==1.1.0 ; python_version < '3.7'
2023
idna==2.9
2124
multidict==4.7.5
25+
psutil==5.7.0
26+
pycparser==2.20
2227
pydantic[dotenv]==1.5.1
28+
pyopenssl==19.1.0
2329
python-dateutil==2.8.1
2430
python-dotenv==0.13.0
2531
requests==2.23.0
32+
scout-apm==2.14.1
2633
six==1.14.0
2734
starlette==0.13.2
28-
urllib3==1.25.9
35+
urllib3[secure]==1.25.9 ; python_version >= '3.5'
2936
uvicorn==0.11.5
3037
uvloop==0.14.0 ; sys_platform != 'win32' and sys_platform != 'cygwin' and platform_python_implementation != 'PyPy'
3138
websockets==8.1
39+
wrapt==1.12.1
3240
yarl==1.4.2

0 commit comments

Comments
 (0)