apitally-serverless 0.2.0__tar.gz → 0.2.1__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.2.1/.editorconfig +22 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/.github/workflows/publish.yaml +3 -3
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/.github/workflows/tests.yaml +27 -16
- apitally_serverless-0.2.1/.tool-versions +1 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/Makefile +8 -2
- apitally_serverless-0.2.1/PKG-INFO +180 -0
- apitally_serverless-0.2.1/README.md +141 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/apitally_serverless/starlette.py +2 -2
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/pyproject.toml +7 -8
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/tests/test_common_masking.py +16 -12
- apitally_serverless-0.2.1/uv.lock +657 -0
- apitally_serverless-0.2.0/.github/workflows/summary.yaml +0 -16
- apitally_serverless-0.2.0/.pre-commit-config.yaml +0 -19
- apitally_serverless-0.2.0/.tool-versions +0 -1
- apitally_serverless-0.2.0/PKG-INFO +0 -129
- apitally_serverless-0.2.0/README.md +0 -90
- apitally_serverless-0.2.0/uv.lock +0 -812
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/.gitignore +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/LICENSE +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/apitally_serverless/__init__.py +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/apitally_serverless/common/__init__.py +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/apitally_serverless/common/config.py +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/apitally_serverless/common/consumers.py +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/apitally_serverless/common/exceptions.py +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/apitally_serverless/common/headers.py +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/apitally_serverless/common/masking.py +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/apitally_serverless/common/output.py +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/apitally_serverless/fastapi.py +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/apitally_serverless/py.typed +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/renovate.json +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/tests/__init__.py +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/tests/conftest.py +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/tests/test_common_consumers.py +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/tests/test_common_exceptions.py +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/tests/test_common_headers.py +0 -0
- {apitally_serverless-0.2.0 → apitally_serverless-0.2.1}/tests/test_fastapi.py +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
root = true
|
|
2
|
+
|
|
3
|
+
[*]
|
|
4
|
+
end_of_line = lf
|
|
5
|
+
insert_final_newline = true
|
|
6
|
+
trim_trailing_whitespace = true
|
|
7
|
+
|
|
8
|
+
[*.py]
|
|
9
|
+
indent_style = space
|
|
10
|
+
indent_size = 4
|
|
11
|
+
max_line_length = 120
|
|
12
|
+
|
|
13
|
+
[*.toml]
|
|
14
|
+
indent_style = space
|
|
15
|
+
indent_size = 4
|
|
16
|
+
|
|
17
|
+
[*.{yaml,json}]
|
|
18
|
+
indent_style = space
|
|
19
|
+
indent_size = 2
|
|
20
|
+
|
|
21
|
+
[Makefile]
|
|
22
|
+
indent_style = tab
|
|
@@ -10,13 +10,13 @@ jobs:
|
|
|
10
10
|
runs-on: ubuntu-latest
|
|
11
11
|
environment: release
|
|
12
12
|
steps:
|
|
13
|
-
- uses: actions/checkout@
|
|
13
|
+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
|
14
14
|
with:
|
|
15
15
|
fetch-depth: 0
|
|
16
16
|
- name: Install uv
|
|
17
|
-
uses: astral-sh/setup-uv@
|
|
17
|
+
uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
|
|
18
18
|
with:
|
|
19
|
-
version: "0.
|
|
19
|
+
version: "0.11.28"
|
|
20
20
|
enable-cache: true
|
|
21
21
|
- name: Build package
|
|
22
22
|
run: uv build
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
name: Tests
|
|
2
2
|
on:
|
|
3
3
|
push:
|
|
4
|
+
branches:
|
|
5
|
+
- main
|
|
6
|
+
paths-ignore:
|
|
7
|
+
- .gitignore
|
|
8
|
+
- LICENSE
|
|
9
|
+
- README.md
|
|
10
|
+
pull_request:
|
|
4
11
|
paths-ignore:
|
|
5
12
|
- .gitignore
|
|
6
13
|
- LICENSE
|
|
@@ -10,23 +17,14 @@ concurrency:
|
|
|
10
17
|
cancel-in-progress: true
|
|
11
18
|
|
|
12
19
|
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
20
|
test-coverage:
|
|
23
21
|
runs-on: ubuntu-latest
|
|
24
22
|
steps:
|
|
25
|
-
- uses: actions/checkout@
|
|
23
|
+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
|
26
24
|
- name: Install uv
|
|
27
|
-
uses: astral-sh/setup-uv@
|
|
25
|
+
uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
|
|
28
26
|
with:
|
|
29
|
-
version: "0.
|
|
27
|
+
version: "0.11.28"
|
|
30
28
|
enable-cache: true
|
|
31
29
|
- name: Install Python
|
|
32
30
|
run: uv python install 3.14
|
|
@@ -39,7 +37,7 @@ jobs:
|
|
|
39
37
|
- name: Run tests and create coverage report
|
|
40
38
|
run: uv run make test-coverage
|
|
41
39
|
- name: Upload coverage report to Codecov
|
|
42
|
-
uses: codecov/codecov-action@
|
|
40
|
+
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7
|
|
43
41
|
with:
|
|
44
42
|
token: ${{ secrets.CODECOV_TOKEN }}
|
|
45
43
|
|
|
@@ -53,11 +51,11 @@ jobs:
|
|
|
53
51
|
- fastapi starlette
|
|
54
52
|
- fastapi==0.116.1 starlette
|
|
55
53
|
steps:
|
|
56
|
-
- uses: actions/checkout@
|
|
54
|
+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
|
57
55
|
- name: Install uv
|
|
58
|
-
uses: astral-sh/setup-uv@
|
|
56
|
+
uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
|
|
59
57
|
with:
|
|
60
|
-
version: "0.
|
|
58
|
+
version: "0.11.28"
|
|
61
59
|
enable-cache: true
|
|
62
60
|
- name: Install Python
|
|
63
61
|
run: uv python install ${{ matrix.python }}
|
|
@@ -69,3 +67,16 @@ jobs:
|
|
|
69
67
|
run: uv pip install ${{ matrix.deps }} ./dist/apitally_serverless-*.whl
|
|
70
68
|
- name: Run tests
|
|
71
69
|
run: uv run make test
|
|
70
|
+
|
|
71
|
+
ci-gate:
|
|
72
|
+
needs:
|
|
73
|
+
- test-coverage
|
|
74
|
+
- test-matrix
|
|
75
|
+
if: always()
|
|
76
|
+
runs-on: ubuntu-latest
|
|
77
|
+
steps:
|
|
78
|
+
- name: All checks passed or skipped
|
|
79
|
+
run: |
|
|
80
|
+
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" || "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
|
|
81
|
+
exit 1
|
|
82
|
+
fi
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uv 0.11.28
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.PHONY: format check test test-coverage
|
|
1
|
+
.PHONY: format check test test-coverage publish-dev
|
|
2
2
|
|
|
3
3
|
format:
|
|
4
4
|
uv run ruff check apitally_serverless tests --fix --select I
|
|
@@ -7,10 +7,16 @@ format:
|
|
|
7
7
|
check:
|
|
8
8
|
uv run ruff check apitally_serverless tests
|
|
9
9
|
uv run ruff format --diff apitally_serverless tests
|
|
10
|
-
uv run
|
|
10
|
+
uv run ty check apitally_serverless tests
|
|
11
|
+
uv lock --locked
|
|
11
12
|
|
|
12
13
|
test:
|
|
13
14
|
uv run pytest -v --tb=short
|
|
14
15
|
|
|
15
16
|
test-coverage:
|
|
16
17
|
uv run pytest -v --tb=short --cov --cov-report=xml
|
|
18
|
+
|
|
19
|
+
publish-dev:
|
|
20
|
+
rm -rf dist
|
|
21
|
+
uv build
|
|
22
|
+
uv publish
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: apitally-serverless
|
|
3
|
+
Version: 0.2.1
|
|
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;">Metrics, logs, and alerts for your serverless APIs — with just a few lines of code.</p>
|
|
51
|
+
<br>
|
|
52
|
+
<p>
|
|
53
|
+
<picture>
|
|
54
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://assets.apitally.io/screenshots/overview-dark.png">
|
|
55
|
+
<source media="(prefers-color-scheme: light)" srcset="https://assets.apitally.io/screenshots/overview-light.png">
|
|
56
|
+
<img alt="Apitally dashboard" src="https://assets.apitally.io/screenshots/overview-light.png">
|
|
57
|
+
</picture>
|
|
58
|
+
</p>
|
|
59
|
+
<br>
|
|
60
|
+
|
|
61
|
+
# Apitally SDK for Cloudflare Python Workers
|
|
62
|
+
|
|
63
|
+
[](https://github.com/apitally/apitally-py-serverless/actions)
|
|
64
|
+
[](https://codecov.io/gh/apitally/apitally-py-serverless)
|
|
65
|
+
[](https://pypi.org/project/apitally-serverless/)
|
|
66
|
+
|
|
67
|
+
Apitally is a simple API monitoring and analytics tool that makes it easy to understand API usage, monitor performance, and troubleshoot issues.
|
|
68
|
+
Get started in minutes by just adding a few lines of code and a Logpush job.
|
|
69
|
+
|
|
70
|
+
Learn more about Apitally on our 🌎 [website](https://apitally.io) or check out
|
|
71
|
+
the 📚 [documentation](https://docs.apitally.io).
|
|
72
|
+
|
|
73
|
+
This SDK is for APIs running on [Cloudflare Python Workers](https://developers.cloudflare.com/workers/languages/python/) and relies on [Logpush](https://developers.cloudflare.com/workers/observability/logs/logpush/) to send data to Apitally.
|
|
74
|
+
|
|
75
|
+
## Key features
|
|
76
|
+
|
|
77
|
+
### API analytics
|
|
78
|
+
|
|
79
|
+
Track traffic, error and performance metrics for your API, each endpoint and
|
|
80
|
+
individual API consumers, allowing you to make informed, data-driven engineering
|
|
81
|
+
and product decisions.
|
|
82
|
+
|
|
83
|
+
### Request logs
|
|
84
|
+
|
|
85
|
+
Drill down from insights to individual API requests or use powerful search and filters to
|
|
86
|
+
find specific requests. View correlated application logs for a complete picture
|
|
87
|
+
of each request, making troubleshooting faster and easier.
|
|
88
|
+
|
|
89
|
+
### Error tracking
|
|
90
|
+
|
|
91
|
+
Understand which validation rules in your endpoints cause client errors. Capture
|
|
92
|
+
error details and stack traces for 500 error responses.
|
|
93
|
+
|
|
94
|
+
### API monitoring & alerts
|
|
95
|
+
|
|
96
|
+
Get notified immediately if something isn't right using custom alerts and synthetic
|
|
97
|
+
uptime checks. Alert notifications can be delivered via email, Slack and Microsoft Teams.
|
|
98
|
+
|
|
99
|
+
## Supported frameworks
|
|
100
|
+
|
|
101
|
+
| Framework | Supported versions | Setup guide |
|
|
102
|
+
| ------------------------------------------------- | ------------------ | ------------------------------------------------------------------------ |
|
|
103
|
+
| [**FastAPI**](https://github.com/fastapi/fastapi) | `>=0.116.1` | [Link](https://docs.apitally.io/setup-guides/fastapi-cloudflare-workers) |
|
|
104
|
+
|
|
105
|
+
Apitally also supports many other web frameworks in [Python](https://github.com/apitally/apitally-py), [JavaScript](https://github.com/apitally/apitally-js), [Go](https://github.com/apitally/apitally-go), [.NET](https://github.com/apitally/apitally-dotnet) and [Java](https://github.com/apitally/apitally-java) via our other SDKs.
|
|
106
|
+
|
|
107
|
+
## Getting started
|
|
108
|
+
|
|
109
|
+
If you don't have an Apitally account yet, first [sign up here](https://app.apitally.io/?signup).
|
|
110
|
+
|
|
111
|
+
### 1. Create app in Apitally
|
|
112
|
+
|
|
113
|
+
Create an app in the Apitally dashboard and select **FastAPI (Cloudflare Workers)** as your framework. You'll see detailed setup instructions, which also include your client ID.
|
|
114
|
+
|
|
115
|
+
### 2. Create Logpush job
|
|
116
|
+
|
|
117
|
+
Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/) and navigate to _Analytics & Logs > Logpush_. Create a [Logpush](https://developers.cloudflare.com/workers/observability/logs/logpush/) job with the following settings:
|
|
118
|
+
|
|
119
|
+
| Setting | Value |
|
|
120
|
+
| ---------------------------- | ---------------------------------------------------------------------------------- |
|
|
121
|
+
| Destination | HTTP destination |
|
|
122
|
+
| HTTP endpoint | `https://hub.apitally.io/v2/{client-id}/{env}/logpush` |
|
|
123
|
+
| Dataset | Workers trace events |
|
|
124
|
+
| If logs match... | Filtered logs: EventType equals `fetch` and ScriptName equals `{your-worker-name}` |
|
|
125
|
+
| Send the following fields... | General: Event, EventTimestampMs, Logs |
|
|
126
|
+
|
|
127
|
+
In the HTTP endpoint, replace `{client-id}` with your app's client ID and `{env}` with the environment (e.g. `prod` or `dev`). In the filter criteria, replace `{your-worker-name}` with the name of your Worker, as specified in your Wrangler config.
|
|
128
|
+
|
|
129
|
+
### 3. Configure Worker
|
|
130
|
+
|
|
131
|
+
Enable [Workers Logs](https://developers.cloudflare.com/workers/observability/logs/workers-logs/) and [Logpush](https://developers.cloudflare.com/workers/observability/logs/logpush/) in your `wrangler.toml` configuration file:
|
|
132
|
+
|
|
133
|
+
```toml
|
|
134
|
+
logpush = true
|
|
135
|
+
|
|
136
|
+
[observability]
|
|
137
|
+
enabled = true
|
|
138
|
+
head_sampling_rate = 1
|
|
139
|
+
|
|
140
|
+
[observability.logs]
|
|
141
|
+
invocation_logs = true
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### 4. Add middleware
|
|
145
|
+
|
|
146
|
+
Install the SDK:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
uv add apitally-serverless
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Then add the Apitally middleware to your FastAPI application:
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
from fastapi import FastAPI
|
|
156
|
+
from apitally_serverless.fastapi import ApitallyMiddleware
|
|
157
|
+
|
|
158
|
+
app = FastAPI()
|
|
159
|
+
app.add_middleware(
|
|
160
|
+
ApitallyMiddleware,
|
|
161
|
+
log_request_headers=True,
|
|
162
|
+
log_request_body=True,
|
|
163
|
+
log_response_body=True,
|
|
164
|
+
)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
For further instructions, see our
|
|
168
|
+
[setup guide for FastAPI on Cloudflare Workers](https://docs.apitally.io/setup-guides/fastapi-cloudflare-workers).
|
|
169
|
+
|
|
170
|
+
See the [SDK reference](https://docs.apitally.io/sdk-reference/python-serverless) for all available configuration options, including how to mask sensitive data, customize request logging, and more.
|
|
171
|
+
|
|
172
|
+
## Getting help
|
|
173
|
+
|
|
174
|
+
If you need help please
|
|
175
|
+
[create a new discussion](https://github.com/orgs/apitally/discussions/categories/q-a)
|
|
176
|
+
on GitHub or email us at [support@apitally.io](mailto:support@apitally.io). We'll get back to you as soon as possible.
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
This library is licensed under the terms of the [MIT license](LICENSE).
|
|
@@ -0,0 +1,141 @@
|
|
|
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;">Metrics, logs, and alerts for your serverless APIs — with just a few lines of code.</p>
|
|
12
|
+
<br>
|
|
13
|
+
<p>
|
|
14
|
+
<picture>
|
|
15
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://assets.apitally.io/screenshots/overview-dark.png">
|
|
16
|
+
<source media="(prefers-color-scheme: light)" srcset="https://assets.apitally.io/screenshots/overview-light.png">
|
|
17
|
+
<img alt="Apitally dashboard" src="https://assets.apitally.io/screenshots/overview-light.png">
|
|
18
|
+
</picture>
|
|
19
|
+
</p>
|
|
20
|
+
<br>
|
|
21
|
+
|
|
22
|
+
# Apitally SDK for Cloudflare Python Workers
|
|
23
|
+
|
|
24
|
+
[](https://github.com/apitally/apitally-py-serverless/actions)
|
|
25
|
+
[](https://codecov.io/gh/apitally/apitally-py-serverless)
|
|
26
|
+
[](https://pypi.org/project/apitally-serverless/)
|
|
27
|
+
|
|
28
|
+
Apitally is a simple API monitoring and analytics tool that makes it easy to understand API usage, monitor performance, and troubleshoot issues.
|
|
29
|
+
Get started in minutes by just adding a few lines of code and a Logpush job.
|
|
30
|
+
|
|
31
|
+
Learn more about Apitally on our 🌎 [website](https://apitally.io) or check out
|
|
32
|
+
the 📚 [documentation](https://docs.apitally.io).
|
|
33
|
+
|
|
34
|
+
This SDK is for APIs running on [Cloudflare Python Workers](https://developers.cloudflare.com/workers/languages/python/) and relies on [Logpush](https://developers.cloudflare.com/workers/observability/logs/logpush/) to send data to Apitally.
|
|
35
|
+
|
|
36
|
+
## Key features
|
|
37
|
+
|
|
38
|
+
### API analytics
|
|
39
|
+
|
|
40
|
+
Track traffic, error and performance metrics for your API, each endpoint and
|
|
41
|
+
individual API consumers, allowing you to make informed, data-driven engineering
|
|
42
|
+
and product decisions.
|
|
43
|
+
|
|
44
|
+
### Request logs
|
|
45
|
+
|
|
46
|
+
Drill down from insights to individual API requests or use powerful search and filters to
|
|
47
|
+
find specific requests. View correlated application logs for a complete picture
|
|
48
|
+
of each request, making troubleshooting faster and easier.
|
|
49
|
+
|
|
50
|
+
### Error tracking
|
|
51
|
+
|
|
52
|
+
Understand which validation rules in your endpoints cause client errors. Capture
|
|
53
|
+
error details and stack traces for 500 error responses.
|
|
54
|
+
|
|
55
|
+
### API monitoring & alerts
|
|
56
|
+
|
|
57
|
+
Get notified immediately if something isn't right using custom alerts and synthetic
|
|
58
|
+
uptime checks. Alert notifications can be delivered via email, Slack and Microsoft Teams.
|
|
59
|
+
|
|
60
|
+
## Supported frameworks
|
|
61
|
+
|
|
62
|
+
| Framework | Supported versions | Setup guide |
|
|
63
|
+
| ------------------------------------------------- | ------------------ | ------------------------------------------------------------------------ |
|
|
64
|
+
| [**FastAPI**](https://github.com/fastapi/fastapi) | `>=0.116.1` | [Link](https://docs.apitally.io/setup-guides/fastapi-cloudflare-workers) |
|
|
65
|
+
|
|
66
|
+
Apitally also supports many other web frameworks in [Python](https://github.com/apitally/apitally-py), [JavaScript](https://github.com/apitally/apitally-js), [Go](https://github.com/apitally/apitally-go), [.NET](https://github.com/apitally/apitally-dotnet) and [Java](https://github.com/apitally/apitally-java) via our other SDKs.
|
|
67
|
+
|
|
68
|
+
## Getting started
|
|
69
|
+
|
|
70
|
+
If you don't have an Apitally account yet, first [sign up here](https://app.apitally.io/?signup).
|
|
71
|
+
|
|
72
|
+
### 1. Create app in Apitally
|
|
73
|
+
|
|
74
|
+
Create an app in the Apitally dashboard and select **FastAPI (Cloudflare Workers)** as your framework. You'll see detailed setup instructions, which also include your client ID.
|
|
75
|
+
|
|
76
|
+
### 2. Create Logpush job
|
|
77
|
+
|
|
78
|
+
Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/) and navigate to _Analytics & Logs > Logpush_. Create a [Logpush](https://developers.cloudflare.com/workers/observability/logs/logpush/) job with the following settings:
|
|
79
|
+
|
|
80
|
+
| Setting | Value |
|
|
81
|
+
| ---------------------------- | ---------------------------------------------------------------------------------- |
|
|
82
|
+
| Destination | HTTP destination |
|
|
83
|
+
| HTTP endpoint | `https://hub.apitally.io/v2/{client-id}/{env}/logpush` |
|
|
84
|
+
| Dataset | Workers trace events |
|
|
85
|
+
| If logs match... | Filtered logs: EventType equals `fetch` and ScriptName equals `{your-worker-name}` |
|
|
86
|
+
| Send the following fields... | General: Event, EventTimestampMs, Logs |
|
|
87
|
+
|
|
88
|
+
In the HTTP endpoint, replace `{client-id}` with your app's client ID and `{env}` with the environment (e.g. `prod` or `dev`). In the filter criteria, replace `{your-worker-name}` with the name of your Worker, as specified in your Wrangler config.
|
|
89
|
+
|
|
90
|
+
### 3. Configure Worker
|
|
91
|
+
|
|
92
|
+
Enable [Workers Logs](https://developers.cloudflare.com/workers/observability/logs/workers-logs/) and [Logpush](https://developers.cloudflare.com/workers/observability/logs/logpush/) in your `wrangler.toml` configuration file:
|
|
93
|
+
|
|
94
|
+
```toml
|
|
95
|
+
logpush = true
|
|
96
|
+
|
|
97
|
+
[observability]
|
|
98
|
+
enabled = true
|
|
99
|
+
head_sampling_rate = 1
|
|
100
|
+
|
|
101
|
+
[observability.logs]
|
|
102
|
+
invocation_logs = true
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### 4. Add middleware
|
|
106
|
+
|
|
107
|
+
Install the SDK:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
uv add apitally-serverless
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Then add the Apitally middleware to your FastAPI application:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from fastapi import FastAPI
|
|
117
|
+
from apitally_serverless.fastapi import ApitallyMiddleware
|
|
118
|
+
|
|
119
|
+
app = FastAPI()
|
|
120
|
+
app.add_middleware(
|
|
121
|
+
ApitallyMiddleware,
|
|
122
|
+
log_request_headers=True,
|
|
123
|
+
log_request_body=True,
|
|
124
|
+
log_response_body=True,
|
|
125
|
+
)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
For further instructions, see our
|
|
129
|
+
[setup guide for FastAPI on Cloudflare Workers](https://docs.apitally.io/setup-guides/fastapi-cloudflare-workers).
|
|
130
|
+
|
|
131
|
+
See the [SDK reference](https://docs.apitally.io/sdk-reference/python-serverless) for all available configuration options, including how to mask sensitive data, customize request logging, and more.
|
|
132
|
+
|
|
133
|
+
## Getting help
|
|
134
|
+
|
|
135
|
+
If you need help please
|
|
136
|
+
[create a new discussion](https://github.com/orgs/apitally/discussions/categories/q-a)
|
|
137
|
+
on GitHub or email us at [support@apitally.io](mailto:support@apitally.io). We'll get back to you as soon as possible.
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
This library is licensed under the terms of the [MIT license](LICENSE).
|
|
@@ -211,7 +211,7 @@ def _get_path(request: Request, routes: list[BaseRoute] | None = None) -> str |
|
|
|
211
211
|
routes = request.app.routes
|
|
212
212
|
for route in routes:
|
|
213
213
|
if hasattr(route, "routes"):
|
|
214
|
-
path = _get_path(request, routes=route
|
|
214
|
+
path = _get_path(request, routes=getattr(route, "routes"))
|
|
215
215
|
if path is not None:
|
|
216
216
|
return path
|
|
217
217
|
elif hasattr(route, "path"):
|
|
@@ -232,7 +232,7 @@ def _get_routes(app: ASGIApp | Router) -> list[BaseRoute]:
|
|
|
232
232
|
if isinstance(app, Router):
|
|
233
233
|
return app.routes
|
|
234
234
|
elif hasattr(app, "app"):
|
|
235
|
-
return _get_routes(app
|
|
235
|
+
return _get_routes(getattr(app, "app"))
|
|
236
236
|
return [] # pragma: no cover
|
|
237
237
|
|
|
238
238
|
|
|
@@ -40,15 +40,14 @@ Documentation = "https://docs.apitally.io"
|
|
|
40
40
|
Repository = "https://github.com/apitally/apitally-py-serverless"
|
|
41
41
|
|
|
42
42
|
[dependency-groups]
|
|
43
|
-
dev = ["
|
|
43
|
+
dev = ["ruff~=0.15.0", "ty>=0.0.61"]
|
|
44
44
|
test = [
|
|
45
45
|
"httpx~=0.28.0",
|
|
46
|
-
"pytest~=9.
|
|
47
|
-
"pytest-asyncio~=1.
|
|
48
|
-
"pytest-cov~=7.
|
|
46
|
+
"pytest~=9.1.1",
|
|
47
|
+
"pytest-asyncio~=1.4.0",
|
|
48
|
+
"pytest-cov~=7.1.0",
|
|
49
49
|
"pytest-mock~=3.15.0",
|
|
50
50
|
]
|
|
51
|
-
types = ["types-pexpect", "types-pygments", "types-pyyaml"]
|
|
52
51
|
|
|
53
52
|
[build-system]
|
|
54
53
|
requires = ["hatchling", "hatch-vcs"]
|
|
@@ -56,6 +55,7 @@ build-backend = "hatchling.build"
|
|
|
56
55
|
|
|
57
56
|
[tool.hatch.version]
|
|
58
57
|
source = "vcs"
|
|
58
|
+
raw-options = { local_scheme = "no-local-version" }
|
|
59
59
|
|
|
60
60
|
[tool.uv]
|
|
61
61
|
default-groups = ["dev", "test"]
|
|
@@ -70,9 +70,8 @@ select = ["E", "F", "W", "I"]
|
|
|
70
70
|
[tool.ruff.lint.isort]
|
|
71
71
|
lines-after-imports = 2
|
|
72
72
|
|
|
73
|
-
[tool.
|
|
74
|
-
|
|
75
|
-
check_untyped_defs = true
|
|
73
|
+
[tool.ty.environment]
|
|
74
|
+
python-version = "3.13"
|
|
76
75
|
|
|
77
76
|
[tool.pytest.ini_options]
|
|
78
77
|
asyncio_mode = "auto"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import json
|
|
2
|
-
from typing import Any
|
|
2
|
+
from typing import Any, cast
|
|
3
3
|
|
|
4
4
|
from apitally_serverless.common.config import ApitallyConfig
|
|
5
5
|
from apitally_serverless.common.masking import MASKED, DataMasker
|
|
@@ -7,7 +7,7 @@ from apitally_serverless.common.output import OutputDataDict
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
def create_config(**kwargs: Any) -> ApitallyConfig:
|
|
10
|
-
defaults = {
|
|
10
|
+
defaults: dict[str, Any] = {
|
|
11
11
|
"enabled": True,
|
|
12
12
|
"log_request_headers": True,
|
|
13
13
|
"log_request_body": True,
|
|
@@ -39,16 +39,20 @@ def create_output_data(
|
|
|
39
39
|
}
|
|
40
40
|
if response:
|
|
41
41
|
response_dict.update(response)
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
return cast(
|
|
43
|
+
OutputDataDict,
|
|
44
|
+
{
|
|
45
|
+
"instance_uuid": "00000000-0000-0000-0000-000000000000",
|
|
46
|
+
"request_uuid": "00000000-0000-0000-0000-000000000000",
|
|
47
|
+
"request": request_dict,
|
|
48
|
+
"response": response_dict,
|
|
49
|
+
"startup": None,
|
|
50
|
+
"consumer": None,
|
|
51
|
+
"validation_errors": None,
|
|
52
|
+
"exception": None,
|
|
53
|
+
"exclude": False,
|
|
54
|
+
},
|
|
55
|
+
)
|
|
52
56
|
|
|
53
57
|
|
|
54
58
|
def test_exclude_paths():
|