apitally-serverless 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- apitally_serverless-0.1.0/.github/workflows/publish.yaml +24 -0
- apitally_serverless-0.1.0/.github/workflows/summary.yaml +16 -0
- apitally_serverless-0.1.0/.github/workflows/tests.yaml +71 -0
- apitally_serverless-0.1.0/.gitignore +56 -0
- apitally_serverless-0.1.0/.pre-commit-config.yaml +19 -0
- apitally_serverless-0.1.0/.tool-versions +1 -0
- apitally_serverless-0.1.0/LICENSE +21 -0
- apitally_serverless-0.1.0/Makefile +16 -0
- apitally_serverless-0.1.0/PKG-INFO +129 -0
- apitally_serverless-0.1.0/README.md +90 -0
- apitally_serverless-0.1.0/apitally_serverless/__init__.py +0 -0
- apitally_serverless-0.1.0/apitally_serverless/common/__init__.py +0 -0
- apitally_serverless-0.1.0/apitally_serverless/common/config.py +30 -0
- apitally_serverless-0.1.0/apitally_serverless/common/consumers.py +24 -0
- apitally_serverless-0.1.0/apitally_serverless/common/headers.py +41 -0
- apitally_serverless-0.1.0/apitally_serverless/common/masking.py +144 -0
- apitally_serverless-0.1.0/apitally_serverless/common/output.py +86 -0
- apitally_serverless-0.1.0/apitally_serverless/fastapi.py +17 -0
- apitally_serverless-0.1.0/apitally_serverless/py.typed +0 -0
- apitally_serverless-0.1.0/apitally_serverless/starlette.py +255 -0
- apitally_serverless-0.1.0/pyproject.toml +85 -0
- apitally_serverless-0.1.0/renovate.json +4 -0
- apitally_serverless-0.1.0/tests/__init__.py +0 -0
- apitally_serverless-0.1.0/tests/conftest.py +14 -0
- apitally_serverless-0.1.0/tests/test_common_consumers.py +20 -0
- apitally_serverless-0.1.0/tests/test_common_headers.py +22 -0
- apitally_serverless-0.1.0/tests/test_common_masking.py +164 -0
- apitally_serverless-0.1.0/tests/test_fastapi.py +143 -0
- apitally_serverless-0.1.0/uv.lock +812 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
on:
|
|
3
|
+
release:
|
|
4
|
+
types: [published]
|
|
5
|
+
permissions:
|
|
6
|
+
id-token: write
|
|
7
|
+
contents: read
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
environment: release
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v6
|
|
14
|
+
with:
|
|
15
|
+
fetch-depth: 0
|
|
16
|
+
- name: Install uv
|
|
17
|
+
uses: astral-sh/setup-uv@v7
|
|
18
|
+
with:
|
|
19
|
+
version: "0.9.21"
|
|
20
|
+
enable-cache: true
|
|
21
|
+
- name: Build package
|
|
22
|
+
run: uv build
|
|
23
|
+
- name: Publish package to PyPI
|
|
24
|
+
run: uv publish
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: Summary
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches-ignore:
|
|
5
|
+
- main
|
|
6
|
+
jobs:
|
|
7
|
+
wait-for-triggered-checks:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
permissions:
|
|
10
|
+
checks: read
|
|
11
|
+
steps:
|
|
12
|
+
- name: Wait for all triggered status checks
|
|
13
|
+
uses: poseidon/wait-for-status-checks@v0.6.0
|
|
14
|
+
with:
|
|
15
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
|
16
|
+
ignore_pattern: ^codecov/.+
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
paths-ignore:
|
|
5
|
+
- .gitignore
|
|
6
|
+
- LICENSE
|
|
7
|
+
- README.md
|
|
8
|
+
concurrency:
|
|
9
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
10
|
+
cancel-in-progress: true
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
check-pre-commit:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v6
|
|
17
|
+
- uses: actions/setup-python@v6
|
|
18
|
+
with:
|
|
19
|
+
python-version: "3.14"
|
|
20
|
+
- uses: pre-commit/action@v3.0.1
|
|
21
|
+
|
|
22
|
+
test-coverage:
|
|
23
|
+
runs-on: ubuntu-latest
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v6
|
|
26
|
+
- name: Install uv
|
|
27
|
+
uses: astral-sh/setup-uv@v7
|
|
28
|
+
with:
|
|
29
|
+
version: "0.9.21"
|
|
30
|
+
enable-cache: true
|
|
31
|
+
- name: Install Python
|
|
32
|
+
run: uv python install 3.14
|
|
33
|
+
- name: Install dependencies
|
|
34
|
+
run: |
|
|
35
|
+
uv sync --all-extras --frozen
|
|
36
|
+
uv pip install drf-spectacular
|
|
37
|
+
- name: Run checks
|
|
38
|
+
run: uv run make check
|
|
39
|
+
- name: Run tests and create coverage report
|
|
40
|
+
run: uv run make test-coverage
|
|
41
|
+
- name: Upload coverage report to Codecov
|
|
42
|
+
uses: codecov/codecov-action@v5
|
|
43
|
+
with:
|
|
44
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
45
|
+
|
|
46
|
+
test-matrix:
|
|
47
|
+
runs-on: ubuntu-latest
|
|
48
|
+
strategy:
|
|
49
|
+
fail-fast: false
|
|
50
|
+
matrix:
|
|
51
|
+
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
|
|
52
|
+
deps:
|
|
53
|
+
- fastapi starlette
|
|
54
|
+
- fastapi==0.116.1 starlette
|
|
55
|
+
steps:
|
|
56
|
+
- uses: actions/checkout@v6
|
|
57
|
+
- name: Install uv
|
|
58
|
+
uses: astral-sh/setup-uv@v7
|
|
59
|
+
with:
|
|
60
|
+
version: "0.9.21"
|
|
61
|
+
enable-cache: true
|
|
62
|
+
- name: Install Python
|
|
63
|
+
run: uv python install ${{ matrix.python }}
|
|
64
|
+
- name: Build Python package wheel
|
|
65
|
+
run: uv build --wheel
|
|
66
|
+
- name: Install test dependencies
|
|
67
|
+
run: uv sync --no-install-project --only-group test --frozen
|
|
68
|
+
- name: Install app dependencies
|
|
69
|
+
run: uv pip install ${{ matrix.deps }} ./dist/apitally_serverless-*.whl
|
|
70
|
+
- name: Run tests
|
|
71
|
+
run: uv run make test
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# Distribution / packaging
|
|
7
|
+
.Python
|
|
8
|
+
build/
|
|
9
|
+
develop-eggs/
|
|
10
|
+
dist/
|
|
11
|
+
downloads/
|
|
12
|
+
eggs/
|
|
13
|
+
.eggs/
|
|
14
|
+
lib/
|
|
15
|
+
lib64/
|
|
16
|
+
parts/
|
|
17
|
+
sdist/
|
|
18
|
+
var/
|
|
19
|
+
wheels/
|
|
20
|
+
share/python-wheels/
|
|
21
|
+
*.egg-info/
|
|
22
|
+
.installed.cfg
|
|
23
|
+
*.egg
|
|
24
|
+
MANIFEST
|
|
25
|
+
|
|
26
|
+
# Unit test / coverage reports
|
|
27
|
+
.coverage
|
|
28
|
+
.cache
|
|
29
|
+
coverage.xml
|
|
30
|
+
.pytest_cache/
|
|
31
|
+
|
|
32
|
+
# Jupyter Notebook
|
|
33
|
+
.ipynb_checkpoints
|
|
34
|
+
|
|
35
|
+
# Environments
|
|
36
|
+
.venv/
|
|
37
|
+
|
|
38
|
+
# mypy
|
|
39
|
+
.mypy_cache/
|
|
40
|
+
.dmypy.json
|
|
41
|
+
dmypy.json
|
|
42
|
+
|
|
43
|
+
# ruff
|
|
44
|
+
.ruff_cache/
|
|
45
|
+
|
|
46
|
+
# LSP config files
|
|
47
|
+
pyrightconfig.json
|
|
48
|
+
|
|
49
|
+
# Visual Studio Code
|
|
50
|
+
.vscode/
|
|
51
|
+
|
|
52
|
+
# Local History for Visual Studio Code
|
|
53
|
+
.history/
|
|
54
|
+
|
|
55
|
+
# macOS
|
|
56
|
+
.DS_Store
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
default_language_version:
|
|
2
|
+
python: "3.14"
|
|
3
|
+
repos:
|
|
4
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
5
|
+
rev: v6.0.0
|
|
6
|
+
hooks:
|
|
7
|
+
- id: end-of-file-fixer
|
|
8
|
+
- id: trailing-whitespace
|
|
9
|
+
- id: mixed-line-ending
|
|
10
|
+
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
|
11
|
+
rev: v0.14.10
|
|
12
|
+
hooks:
|
|
13
|
+
- id: ruff
|
|
14
|
+
args: ["--fix", "--exit-non-zero-on-fix"]
|
|
15
|
+
- id: ruff-format
|
|
16
|
+
- repo: https://github.com/astral-sh/uv-pre-commit
|
|
17
|
+
rev: 0.9.21
|
|
18
|
+
hooks:
|
|
19
|
+
- id: uv-lock
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uv 0.9.21
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Apitally
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.PHONY: format check test test-coverage
|
|
2
|
+
|
|
3
|
+
format:
|
|
4
|
+
uv run ruff check apitally_serverless tests --fix --select I
|
|
5
|
+
uv run ruff format apitally_serverless tests
|
|
6
|
+
|
|
7
|
+
check:
|
|
8
|
+
uv run ruff check apitally_serverless tests
|
|
9
|
+
uv run ruff format --diff apitally_serverless tests
|
|
10
|
+
uv run mypy --install-types --non-interactive apitally_serverless tests
|
|
11
|
+
|
|
12
|
+
test:
|
|
13
|
+
uv run pytest -v --tb=short
|
|
14
|
+
|
|
15
|
+
test-coverage:
|
|
16
|
+
uv run pytest -v --tb=short --cov --cov-report=xml
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: apitally-serverless
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Simple API monitoring & analytics for REST APIs running on serverless platforms (e.g. Cloudflare Workers).
|
|
5
|
+
Project-URL: Homepage, https://apitally.io
|
|
6
|
+
Project-URL: Documentation, https://docs.apitally.io
|
|
7
|
+
Project-URL: Repository, https://github.com/apitally/apitally-py-serverless
|
|
8
|
+
Author-email: Apitally <hello@apitally.io>
|
|
9
|
+
License: MIT License
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Environment :: Web Environment
|
|
13
|
+
Classifier: Framework :: FastAPI
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Information Technology
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
25
|
+
Classifier: Topic :: Internet
|
|
26
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
27
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware
|
|
28
|
+
Classifier: Topic :: Software Development
|
|
29
|
+
Classifier: Topic :: System :: Monitoring
|
|
30
|
+
Classifier: Typing :: Typed
|
|
31
|
+
Requires-Python: <4.0,>=3.10
|
|
32
|
+
Requires-Dist: typing-extensions>=4.0.0; python_version < '3.11'
|
|
33
|
+
Provides-Extra: fastapi
|
|
34
|
+
Requires-Dist: fastapi>=0.116.1; extra == 'fastapi'
|
|
35
|
+
Requires-Dist: starlette<1.0.0,>=0.47.2; extra == 'fastapi'
|
|
36
|
+
Provides-Extra: starlette
|
|
37
|
+
Requires-Dist: starlette<1.0.0,>=0.47.2; extra == 'starlette'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
<p align="center">
|
|
41
|
+
<a href="https://apitally.io" target="_blank">
|
|
42
|
+
<picture>
|
|
43
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://assets.apitally.io/logos/logo-horizontal-new-dark.png">
|
|
44
|
+
<source media="(prefers-color-scheme: light)" srcset="https://assets.apitally.io/logos/logo-horizontal-new-light.png">
|
|
45
|
+
<img alt="Apitally logo" src="https://assets.apitally.io/logos/logo-horizontal-new-light.png" width="220">
|
|
46
|
+
</picture>
|
|
47
|
+
</a>
|
|
48
|
+
</p>
|
|
49
|
+
<p align="center"><b>API monitoring & analytics made simple</b></p>
|
|
50
|
+
<p align="center" style="color: #ccc;">Real-time metrics, request logs, and alerts for your APIs — with just a few lines of code.</p>
|
|
51
|
+
<br>
|
|
52
|
+
<img alt="Apitally screenshots" src="https://assets.apitally.io/screenshots/overview.png">
|
|
53
|
+
<br>
|
|
54
|
+
|
|
55
|
+
# Apitally SDK for serverless Python runtimes
|
|
56
|
+
|
|
57
|
+
[](https://github.com/apitally/apitally-py-serverless/actions)
|
|
58
|
+
[](https://codecov.io/gh/apitally/apitally-py-serverless)
|
|
59
|
+
[](https://pypi.org/project/apitally-serverless/)
|
|
60
|
+
|
|
61
|
+
This SDK for Apitally currently supports the following web frameworks:
|
|
62
|
+
|
|
63
|
+
- [FastAPI](https://docs.apitally.io/setup-guides/fastapi-serverless)
|
|
64
|
+
|
|
65
|
+
The following serverless platforms are supported:
|
|
66
|
+
|
|
67
|
+
- [Cloudflare Workers](https://docs.apitally.io/setup-guides/cloudflare-workers) (via Logpush)
|
|
68
|
+
|
|
69
|
+
Learn more about Apitally on our 🌎 [website](https://apitally.io) or check out
|
|
70
|
+
the 📚 [documentation](https://docs.apitally.io).
|
|
71
|
+
|
|
72
|
+
## Key features
|
|
73
|
+
|
|
74
|
+
### API analytics
|
|
75
|
+
|
|
76
|
+
Track traffic, error and performance metrics for your API, each endpoint and individual API consumers, allowing you to make informed, data-driven engineering and product decisions.
|
|
77
|
+
|
|
78
|
+
### Error tracking
|
|
79
|
+
|
|
80
|
+
Understand which validation rules in your endpoints cause client errors. Capture error details and stack traces for 500 error responses, and have them linked to Sentry issues automatically.
|
|
81
|
+
|
|
82
|
+
### Request logging
|
|
83
|
+
|
|
84
|
+
Drill down from insights to individual requests or use powerful filtering to understand how consumers have interacted with your API. Configure exactly what is included in the logs to meet your requirements.
|
|
85
|
+
|
|
86
|
+
### API monitoring & alerting
|
|
87
|
+
|
|
88
|
+
Get notified immediately if something isn't right using custom alerts, synthetic uptime checks and heartbeat monitoring. Notifications can be delivered via email, Slack or Microsoft Teams.
|
|
89
|
+
|
|
90
|
+
## Installation
|
|
91
|
+
|
|
92
|
+
Use `uv` to add this SDK to your project's dependencies:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
uv add apitally-serverless
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Usage
|
|
99
|
+
|
|
100
|
+
Our comprehensive [setup guides](https://docs.apitally.io/setup-guides) include
|
|
101
|
+
all the details you need to get started.
|
|
102
|
+
|
|
103
|
+
### FastAPI
|
|
104
|
+
|
|
105
|
+
This is an example of how to add the Apitally middleware to a FastAPI
|
|
106
|
+
application running on a supported serverless platform. For further instructions, see our
|
|
107
|
+
[setup guide for FastAPI](https://docs.apitally.io/frameworks/fastapi-serverless).
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from fastapi import FastAPI
|
|
111
|
+
from apitally_serverless.fastapi import ApitallyMiddleware
|
|
112
|
+
|
|
113
|
+
app = FastAPI()
|
|
114
|
+
app.add_middleware(
|
|
115
|
+
ApitallyMiddleware,
|
|
116
|
+
log_request_headers=True,
|
|
117
|
+
log_request_body=True,
|
|
118
|
+
log_response_body=True,
|
|
119
|
+
)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Getting help
|
|
123
|
+
|
|
124
|
+
If you need help please [create a new discussion](https://github.com/orgs/apitally/discussions/categories/q-a) on GitHub
|
|
125
|
+
or [join our Slack workspace](https://join.slack.com/t/apitally-community/shared_invite/zt-2b3xxqhdu-9RMq2HyZbR79wtzNLoGHrg).
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
This library is licensed under the terms of the MIT license.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://apitally.io" target="_blank">
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://assets.apitally.io/logos/logo-horizontal-new-dark.png">
|
|
5
|
+
<source media="(prefers-color-scheme: light)" srcset="https://assets.apitally.io/logos/logo-horizontal-new-light.png">
|
|
6
|
+
<img alt="Apitally logo" src="https://assets.apitally.io/logos/logo-horizontal-new-light.png" width="220">
|
|
7
|
+
</picture>
|
|
8
|
+
</a>
|
|
9
|
+
</p>
|
|
10
|
+
<p align="center"><b>API monitoring & analytics made simple</b></p>
|
|
11
|
+
<p align="center" style="color: #ccc;">Real-time metrics, request logs, and alerts for your APIs — with just a few lines of code.</p>
|
|
12
|
+
<br>
|
|
13
|
+
<img alt="Apitally screenshots" src="https://assets.apitally.io/screenshots/overview.png">
|
|
14
|
+
<br>
|
|
15
|
+
|
|
16
|
+
# Apitally SDK for serverless Python runtimes
|
|
17
|
+
|
|
18
|
+
[](https://github.com/apitally/apitally-py-serverless/actions)
|
|
19
|
+
[](https://codecov.io/gh/apitally/apitally-py-serverless)
|
|
20
|
+
[](https://pypi.org/project/apitally-serverless/)
|
|
21
|
+
|
|
22
|
+
This SDK for Apitally currently supports the following web frameworks:
|
|
23
|
+
|
|
24
|
+
- [FastAPI](https://docs.apitally.io/setup-guides/fastapi-serverless)
|
|
25
|
+
|
|
26
|
+
The following serverless platforms are supported:
|
|
27
|
+
|
|
28
|
+
- [Cloudflare Workers](https://docs.apitally.io/setup-guides/cloudflare-workers) (via Logpush)
|
|
29
|
+
|
|
30
|
+
Learn more about Apitally on our 🌎 [website](https://apitally.io) or check out
|
|
31
|
+
the 📚 [documentation](https://docs.apitally.io).
|
|
32
|
+
|
|
33
|
+
## Key features
|
|
34
|
+
|
|
35
|
+
### API analytics
|
|
36
|
+
|
|
37
|
+
Track traffic, error and performance metrics for your API, each endpoint and individual API consumers, allowing you to make informed, data-driven engineering and product decisions.
|
|
38
|
+
|
|
39
|
+
### Error tracking
|
|
40
|
+
|
|
41
|
+
Understand which validation rules in your endpoints cause client errors. Capture error details and stack traces for 500 error responses, and have them linked to Sentry issues automatically.
|
|
42
|
+
|
|
43
|
+
### Request logging
|
|
44
|
+
|
|
45
|
+
Drill down from insights to individual requests or use powerful filtering to understand how consumers have interacted with your API. Configure exactly what is included in the logs to meet your requirements.
|
|
46
|
+
|
|
47
|
+
### API monitoring & alerting
|
|
48
|
+
|
|
49
|
+
Get notified immediately if something isn't right using custom alerts, synthetic uptime checks and heartbeat monitoring. Notifications can be delivered via email, Slack or Microsoft Teams.
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
Use `uv` to add this SDK to your project's dependencies:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
uv add apitally-serverless
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
60
|
+
|
|
61
|
+
Our comprehensive [setup guides](https://docs.apitally.io/setup-guides) include
|
|
62
|
+
all the details you need to get started.
|
|
63
|
+
|
|
64
|
+
### FastAPI
|
|
65
|
+
|
|
66
|
+
This is an example of how to add the Apitally middleware to a FastAPI
|
|
67
|
+
application running on a supported serverless platform. For further instructions, see our
|
|
68
|
+
[setup guide for FastAPI](https://docs.apitally.io/frameworks/fastapi-serverless).
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from fastapi import FastAPI
|
|
72
|
+
from apitally_serverless.fastapi import ApitallyMiddleware
|
|
73
|
+
|
|
74
|
+
app = FastAPI()
|
|
75
|
+
app.add_middleware(
|
|
76
|
+
ApitallyMiddleware,
|
|
77
|
+
log_request_headers=True,
|
|
78
|
+
log_request_body=True,
|
|
79
|
+
log_response_body=True,
|
|
80
|
+
)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Getting help
|
|
84
|
+
|
|
85
|
+
If you need help please [create a new discussion](https://github.com/orgs/apitally/discussions/categories/q-a) on GitHub
|
|
86
|
+
or [join our Slack workspace](https://join.slack.com/t/apitally-community/shared_invite/zt-2b3xxqhdu-9RMq2HyZbR79wtzNLoGHrg).
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
This library is licensed under the terms of the MIT license.
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
from typing import Any, TypedDict
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class ApitallyConfigKwargs(TypedDict, total=False):
|
|
6
|
+
enabled: bool
|
|
7
|
+
log_request_headers: bool
|
|
8
|
+
log_request_body: bool
|
|
9
|
+
log_response_headers: bool
|
|
10
|
+
log_response_body: bool
|
|
11
|
+
mask_headers: list[str]
|
|
12
|
+
mask_body_fields: list[str]
|
|
13
|
+
exclude_paths: list[str]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass
|
|
17
|
+
class ApitallyConfig:
|
|
18
|
+
enabled: bool = True
|
|
19
|
+
log_request_headers: bool = False
|
|
20
|
+
log_request_body: bool = False
|
|
21
|
+
log_response_headers: bool = True
|
|
22
|
+
log_response_body: bool = False
|
|
23
|
+
mask_headers: list[str] = field(default_factory=list)
|
|
24
|
+
mask_body_fields: list[str] = field(default_factory=list)
|
|
25
|
+
exclude_paths: list[str] = field(default_factory=list)
|
|
26
|
+
|
|
27
|
+
@classmethod
|
|
28
|
+
def from_kwargs(cls, kwargs: ApitallyConfigKwargs) -> "ApitallyConfig":
|
|
29
|
+
config_kwargs: dict[str, Any] = {k: v for k, v in kwargs.items() if k in cls.__dataclass_fields__}
|
|
30
|
+
return ApitallyConfig(**config_kwargs)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
_seen_consumer_hashes: set[int] = set()
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class ApitallyConsumer:
|
|
9
|
+
identifier: str
|
|
10
|
+
name: str | None = None
|
|
11
|
+
group: str | None = None
|
|
12
|
+
|
|
13
|
+
def __post_init__(self) -> None:
|
|
14
|
+
self.identifier = str(self.identifier).strip()[:128]
|
|
15
|
+
self.name = str(self.name).strip()[:64] if self.name else None
|
|
16
|
+
self.group = str(self.group).strip()[:64] if self.group else None
|
|
17
|
+
|
|
18
|
+
if self.name or self.group:
|
|
19
|
+
h = hash((self.identifier, self.name, self.group))
|
|
20
|
+
if h in _seen_consumer_hashes:
|
|
21
|
+
self.name = None
|
|
22
|
+
self.group = None
|
|
23
|
+
else:
|
|
24
|
+
_seen_consumer_hashes.add(h)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from typing import Iterable
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
SUPPORTED_CONTENT_TYPES = [
|
|
5
|
+
"application/json",
|
|
6
|
+
"application/ld+json",
|
|
7
|
+
"application/problem+json",
|
|
8
|
+
"application/vnd.api+json",
|
|
9
|
+
"application/x-ndjson",
|
|
10
|
+
"text/plain",
|
|
11
|
+
"text/html",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def convert_headers(
|
|
16
|
+
headers: Iterable[tuple[str, str]] | None,
|
|
17
|
+
) -> list[tuple[str, str]]:
|
|
18
|
+
if headers is None:
|
|
19
|
+
return []
|
|
20
|
+
return [(k.lower(), v) for k, v in headers]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def parse_content_length(
|
|
24
|
+
content_length: str | bytes | int | None,
|
|
25
|
+
) -> int | None:
|
|
26
|
+
if content_length is None:
|
|
27
|
+
return None
|
|
28
|
+
if isinstance(content_length, int):
|
|
29
|
+
return content_length
|
|
30
|
+
if isinstance(content_length, bytes):
|
|
31
|
+
content_length = content_length.decode()
|
|
32
|
+
try:
|
|
33
|
+
return int(content_length)
|
|
34
|
+
except ValueError:
|
|
35
|
+
return None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def is_supported_content_type(content_type: str | None) -> bool:
|
|
39
|
+
if not content_type:
|
|
40
|
+
return False
|
|
41
|
+
return any(content_type.startswith(t) for t in SUPPORTED_CONTENT_TYPES)
|