dbt-copilot-python 2.0.0__tar.gz → 2.0.1a0__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.
- {dbt_copilot_python-2.0.0 → dbt_copilot_python-2.0.1a0}/PKG-INFO +52 -4
- {dbt_copilot_python-2.0.0 → dbt_copilot_python-2.0.1a0}/README.md +48 -2
- dbt_copilot_python-2.0.1a0/dbt_copilot_python/error_tracking.py +47 -0
- {dbt_copilot_python-2.0.0 → dbt_copilot_python-2.0.1a0}/pyproject.toml +5 -2
- {dbt_copilot_python-2.0.0 → dbt_copilot_python-2.0.1a0}/LICENSE +0 -0
- {dbt_copilot_python-2.0.0 → dbt_copilot_python-2.0.1a0}/dbt_copilot_python/__init__.py +0 -0
- {dbt_copilot_python-2.0.0 → dbt_copilot_python-2.0.1a0}/dbt_copilot_python/celery_health_check/__init__.py +0 -0
- {dbt_copilot_python-2.0.0 → dbt_copilot_python-2.0.1a0}/dbt_copilot_python/celery_health_check/const.py +0 -0
- {dbt_copilot_python-2.0.0 → dbt_copilot_python-2.0.1a0}/dbt_copilot_python/celery_health_check/healthcheck.py +0 -0
- {dbt_copilot_python-2.0.0 → dbt_copilot_python-2.0.1a0}/dbt_copilot_python/celery_health_check/heartbeat.py +0 -0
- {dbt_copilot_python-2.0.0 → dbt_copilot_python-2.0.1a0}/dbt_copilot_python/database.py +0 -0
- {dbt_copilot_python-2.0.0 → dbt_copilot_python-2.0.1a0}/dbt_copilot_python/network.py +0 -0
- {dbt_copilot_python-2.0.0 → dbt_copilot_python-2.0.1a0}/dbt_copilot_python/utility.py +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dbt-copilot-python
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.1a0
|
|
4
4
|
Summary: Helper functions to run Django and Flask applications in AWS Copilot/ECS.
|
|
5
5
|
License-File: LICENSE
|
|
6
6
|
Author: Department for Business and Trade Platform Team
|
|
7
7
|
Author-email: sre-team@digital.trade.gov.uk
|
|
8
|
-
Requires-Python: >=3.9,<
|
|
8
|
+
Requires-Python: >=3.9,<3.15
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.9
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.10
|
|
@@ -14,7 +14,9 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.13
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.14
|
|
16
16
|
Provides-Extra: celery
|
|
17
|
+
Provides-Extra: error-tracking
|
|
17
18
|
Requires-Dist: celery (>=5.0) ; extra == "celery"
|
|
19
|
+
Requires-Dist: ddtrace (>=3,<5) ; extra == "error-tracking"
|
|
18
20
|
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
19
21
|
Description-Content-Type: text/markdown
|
|
20
22
|
|
|
@@ -38,7 +40,7 @@ pip install dbt-copilot-python
|
|
|
38
40
|
|
|
39
41
|
#### With celery
|
|
40
42
|
|
|
41
|
-
If you are using celery, you should also install an appropriate version of celery using your project's package manager, or
|
|
43
|
+
If you are using celery, you should also install an appropriate version of celery using your project's package manager, or our built-in extra.
|
|
42
44
|
|
|
43
45
|
```shell
|
|
44
46
|
# Poetry
|
|
@@ -66,6 +68,37 @@ pip freeze | grep "^celery==" >> requirements.txt
|
|
|
66
68
|
pipenv install dbt-copilot-python[celery]
|
|
67
69
|
```
|
|
68
70
|
|
|
71
|
+
#### With error tracking
|
|
72
|
+
|
|
73
|
+
If you intend on using the error tracking filter, you should also install an appropriate version of ddtrace using your project's package manager, or our built-in extra.
|
|
74
|
+
|
|
75
|
+
```shell
|
|
76
|
+
# Poetry
|
|
77
|
+
poetry add ddtrace
|
|
78
|
+
|
|
79
|
+
# Pip
|
|
80
|
+
pip install ddtrace
|
|
81
|
+
pip freeze | grep "^ddtrace==" >> requirements.txt
|
|
82
|
+
|
|
83
|
+
# Pipenv
|
|
84
|
+
pipenv install ddtrace
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**OR**
|
|
88
|
+
|
|
89
|
+
```shell
|
|
90
|
+
# Poetry
|
|
91
|
+
poetry add dbt-copilot-python[error-tracking]
|
|
92
|
+
|
|
93
|
+
# Pip
|
|
94
|
+
pip install dbt-copilot-python[error-tracking]
|
|
95
|
+
pip freeze | grep "^ddtrace==" >> requirements.txt
|
|
96
|
+
|
|
97
|
+
# Pipenv
|
|
98
|
+
pipenv install dbt-copilot-python[error-tracking]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
|
|
69
102
|
### Usage
|
|
70
103
|
|
|
71
104
|
#### `ALLOWED_HOSTS` setting
|
|
@@ -129,7 +162,7 @@ To configure the `DATABASES` setting from an RDS JSON object stored in AWS Secre
|
|
|
129
162
|
import dj_database_url
|
|
130
163
|
|
|
131
164
|
from dbt_copilot_python.database import database_url_from_env
|
|
132
|
-
|
|
165
|
+
|
|
133
166
|
DATABASES = {
|
|
134
167
|
"default": dj_database_url.config(
|
|
135
168
|
default=database_url_from_env("DATABASE_ENV_VAR_KEY")
|
|
@@ -145,6 +178,21 @@ To configure the `DATABASES` setting from an RDS JSON object stored in AWS Secre
|
|
|
145
178
|
DATABASES = database_from_env("DATABASE_ENV_VAR_KEY")
|
|
146
179
|
```
|
|
147
180
|
|
|
181
|
+
#### Error tracking
|
|
182
|
+
|
|
183
|
+
To enable error tracking for logs you must attach the `DatadogErrorTrackingFilter` to any of the loggers which you'd like to track logs emitted at a level `>=logging.ERROR`.
|
|
184
|
+
|
|
185
|
+
Generally speaking you could do something as follows
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
import logging
|
|
189
|
+
|
|
190
|
+
from dbt_copilot_python import DatadogErrorTrackingFilter
|
|
191
|
+
|
|
192
|
+
logger = logging.getLogger()
|
|
193
|
+
logger.addFilter(DatadogErrorTrackingFilter())
|
|
194
|
+
```
|
|
195
|
+
|
|
148
196
|
## Contributing to `dbt-copilot-python`
|
|
149
197
|
|
|
150
198
|
### Requirements
|
|
@@ -18,7 +18,7 @@ pip install dbt-copilot-python
|
|
|
18
18
|
|
|
19
19
|
#### With celery
|
|
20
20
|
|
|
21
|
-
If you are using celery, you should also install an appropriate version of celery using your project's package manager, or
|
|
21
|
+
If you are using celery, you should also install an appropriate version of celery using your project's package manager, or our built-in extra.
|
|
22
22
|
|
|
23
23
|
```shell
|
|
24
24
|
# Poetry
|
|
@@ -46,6 +46,37 @@ pip freeze | grep "^celery==" >> requirements.txt
|
|
|
46
46
|
pipenv install dbt-copilot-python[celery]
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
+
#### With error tracking
|
|
50
|
+
|
|
51
|
+
If you intend on using the error tracking filter, you should also install an appropriate version of ddtrace using your project's package manager, or our built-in extra.
|
|
52
|
+
|
|
53
|
+
```shell
|
|
54
|
+
# Poetry
|
|
55
|
+
poetry add ddtrace
|
|
56
|
+
|
|
57
|
+
# Pip
|
|
58
|
+
pip install ddtrace
|
|
59
|
+
pip freeze | grep "^ddtrace==" >> requirements.txt
|
|
60
|
+
|
|
61
|
+
# Pipenv
|
|
62
|
+
pipenv install ddtrace
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**OR**
|
|
66
|
+
|
|
67
|
+
```shell
|
|
68
|
+
# Poetry
|
|
69
|
+
poetry add dbt-copilot-python[error-tracking]
|
|
70
|
+
|
|
71
|
+
# Pip
|
|
72
|
+
pip install dbt-copilot-python[error-tracking]
|
|
73
|
+
pip freeze | grep "^ddtrace==" >> requirements.txt
|
|
74
|
+
|
|
75
|
+
# Pipenv
|
|
76
|
+
pipenv install dbt-copilot-python[error-tracking]
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
|
|
49
80
|
### Usage
|
|
50
81
|
|
|
51
82
|
#### `ALLOWED_HOSTS` setting
|
|
@@ -109,7 +140,7 @@ To configure the `DATABASES` setting from an RDS JSON object stored in AWS Secre
|
|
|
109
140
|
import dj_database_url
|
|
110
141
|
|
|
111
142
|
from dbt_copilot_python.database import database_url_from_env
|
|
112
|
-
|
|
143
|
+
|
|
113
144
|
DATABASES = {
|
|
114
145
|
"default": dj_database_url.config(
|
|
115
146
|
default=database_url_from_env("DATABASE_ENV_VAR_KEY")
|
|
@@ -125,6 +156,21 @@ To configure the `DATABASES` setting from an RDS JSON object stored in AWS Secre
|
|
|
125
156
|
DATABASES = database_from_env("DATABASE_ENV_VAR_KEY")
|
|
126
157
|
```
|
|
127
158
|
|
|
159
|
+
#### Error tracking
|
|
160
|
+
|
|
161
|
+
To enable error tracking for logs you must attach the `DatadogErrorTrackingFilter` to any of the loggers which you'd like to track logs emitted at a level `>=logging.ERROR`.
|
|
162
|
+
|
|
163
|
+
Generally speaking you could do something as follows
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
import logging
|
|
167
|
+
|
|
168
|
+
from dbt_copilot_python import DatadogErrorTrackingFilter
|
|
169
|
+
|
|
170
|
+
logger = logging.getLogger()
|
|
171
|
+
logger.addFilter(DatadogErrorTrackingFilter())
|
|
172
|
+
```
|
|
173
|
+
|
|
128
174
|
## Contributing to `dbt-copilot-python`
|
|
129
175
|
|
|
130
176
|
### Requirements
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
import traceback
|
|
5
|
+
from functools import lru_cache
|
|
6
|
+
|
|
7
|
+
from ddtrace.trace import tracer
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DatadogErrorTrackingFilter(logging.Filter):
|
|
11
|
+
def __init__(self, name: str = "") -> None:
|
|
12
|
+
self._working_directory = os.getcwd()
|
|
13
|
+
super().__init__(name)
|
|
14
|
+
|
|
15
|
+
def filter(self, record):
|
|
16
|
+
if record.levelno >= logging.ERROR:
|
|
17
|
+
# Escape quickly if inside of a handled exception, use native
|
|
18
|
+
# functionality to surface handled errors
|
|
19
|
+
# https://docs.datadoghq.com/error_tracking/backend/capturing_handled_errors/python/#automatic-instrumentation
|
|
20
|
+
exc_info = sys.exc_info()
|
|
21
|
+
if any(exc_info):
|
|
22
|
+
return True
|
|
23
|
+
|
|
24
|
+
span = tracer.current_span()
|
|
25
|
+
if span:
|
|
26
|
+
span.record_exception(
|
|
27
|
+
BaseException(record.msg),
|
|
28
|
+
attributes={
|
|
29
|
+
"exception.stacktrace": "".join(traceback.format_stack(limit=20)),
|
|
30
|
+
"exception.type": f"{self._calculate_module_path(record.pathname, record.module, record.funcName)}.LoggedError",
|
|
31
|
+
},
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
return True
|
|
35
|
+
|
|
36
|
+
@lru_cache(maxsize=32)
|
|
37
|
+
def _calculate_module_path(self, pathname: str, module: str, func_name: str) -> str:
|
|
38
|
+
path_from_project_root = pathname.replace(self._working_directory, "")
|
|
39
|
+
|
|
40
|
+
if path_from_project_root != pathname:
|
|
41
|
+
module_path_with_function = path_from_project_root.split("/")[1:-1]
|
|
42
|
+
else:
|
|
43
|
+
module_path_with_function = path_from_project_root.split("/")[1:]
|
|
44
|
+
|
|
45
|
+
module_path_with_function.extend([module, func_name])
|
|
46
|
+
|
|
47
|
+
return ".".join(module_path_with_function)
|
|
@@ -3,7 +3,7 @@ line-length = 100
|
|
|
3
3
|
|
|
4
4
|
[tool.poetry]
|
|
5
5
|
name = "dbt-copilot-python"
|
|
6
|
-
version = "2.0.
|
|
6
|
+
version = "2.0.1a0"
|
|
7
7
|
description = "Helper functions to run Django and Flask applications in AWS Copilot/ECS."
|
|
8
8
|
authors = [
|
|
9
9
|
"Department for Business and Trade Platform Team <sre-team@digital.trade.gov.uk>",
|
|
@@ -12,12 +12,14 @@ readme = "README.md"
|
|
|
12
12
|
packages = [{ include = "dbt_copilot_python" }]
|
|
13
13
|
|
|
14
14
|
[tool.poetry.dependencies]
|
|
15
|
-
python = "
|
|
15
|
+
python = ">=3.9,<3.15"
|
|
16
16
|
requests = "^2.32.3"
|
|
17
17
|
celery = { version = ">=5.0", optional = true }
|
|
18
|
+
ddtrace = { version = ">=3,<5", optional = true }
|
|
18
19
|
|
|
19
20
|
[tool.poetry.extras]
|
|
20
21
|
celery = ["celery"]
|
|
22
|
+
error-tracking = ["ddtrace"]
|
|
21
23
|
|
|
22
24
|
[tool.poetry.group.dev.dependencies]
|
|
23
25
|
pre-commit = ">=3.3.3,<5.0.0"
|
|
@@ -25,6 +27,7 @@ pytest = ">=7.3.2,<9.0.0"
|
|
|
25
27
|
requests-mock = "^1.11.0"
|
|
26
28
|
tox = "^4.6.3"
|
|
27
29
|
pytest-celery = "^0.0.0"
|
|
30
|
+
ddtrace = ">=3,<5"
|
|
28
31
|
|
|
29
32
|
[build-system]
|
|
30
33
|
requires = ["poetry-core"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|