django-log-formatter-asim 0.0.5__tar.gz → 1.0.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.
- {django_log_formatter_asim-0.0.5 → django_log_formatter_asim-1.0.0}/PKG-INFO +37 -3
- {django_log_formatter_asim-0.0.5 → django_log_formatter_asim-1.0.0}/README.md +33 -0
- {django_log_formatter_asim-0.0.5 → django_log_formatter_asim-1.0.0}/django_log_formatter_asim/__init__.py +45 -0
- {django_log_formatter_asim-0.0.5 → django_log_formatter_asim-1.0.0}/pyproject.toml +2 -1
- {django_log_formatter_asim-0.0.5 → django_log_formatter_asim-1.0.0}/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: django-log-formatter-asim
|
|
3
|
-
Version: 0.0
|
|
3
|
+
Version: 1.0.0
|
|
4
4
|
Summary: Formats Django logs in ASIM format.
|
|
5
5
|
License: MIT
|
|
6
6
|
Author: Department for Business and Trade Platform Team
|
|
@@ -12,7 +12,9 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.10
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
-
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Requires-Dist: ddtrace (>=3.2.1,<4.0.0)
|
|
17
|
+
Requires-Dist: django (>=3,<5) ; python_version == "3.9"
|
|
16
18
|
Requires-Dist: django (>=3,<6) ; python_version >= "3.10" and python_version < "4"
|
|
17
19
|
Requires-Dist: pre-commit (>=3.5.0,<4.0.0)
|
|
18
20
|
Description-Content-Type: text/markdown
|
|
@@ -140,3 +142,35 @@ Run `poetry run pytest` in the root directory to run all tests.
|
|
|
140
142
|
|
|
141
143
|
Or, run `poetry run tox` in the root directory to run all tests for multiple Python versions. See the [`tox` configuration file](tox.ini).
|
|
142
144
|
|
|
145
|
+
### Publishing
|
|
146
|
+
|
|
147
|
+
1. Acquire API token from [Passman](https://passman.ci.uktrade.digital/secret/cc82a3f7-ddfa-4312-ab56-1ff8528dadc8/).
|
|
148
|
+
- Request access from the SRE team.
|
|
149
|
+
- _Note: You will need access to the `platform` group in Passman._
|
|
150
|
+
2. Run `poetry config pypi-token.pypi <token>` to add the token to your Poetry configuration.
|
|
151
|
+
|
|
152
|
+
Update the version, as the same version cannot be published to PyPI.
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
poetry version patch
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
More options for the `version` command can be found in the [Poetry documentation](https://python-poetry.org/docs/cli/#version). For example, for a minor version bump: `poetry version minor`.
|
|
159
|
+
|
|
160
|
+
Build the Python package.
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
poetry build
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Publish the Python package.
|
|
167
|
+
|
|
168
|
+
_Note: Make sure your Pull Request (PR) is approved and contains the version upgrade in `pyproject.toml` before publishing the package._
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
poetry publish
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Check the [PyPI Release history](https://pypi.org/project/django-log-formatter-asim/#history) to make sure the package has been updated.
|
|
175
|
+
|
|
176
|
+
For an optional manual check, install the package locally and test everything works as expected.
|
|
@@ -120,3 +120,36 @@ If you wish to create your own ASIM formatter, you can inherit from ASIMSystemFo
|
|
|
120
120
|
Run `poetry run pytest` in the root directory to run all tests.
|
|
121
121
|
|
|
122
122
|
Or, run `poetry run tox` in the root directory to run all tests for multiple Python versions. See the [`tox` configuration file](tox.ini).
|
|
123
|
+
|
|
124
|
+
### Publishing
|
|
125
|
+
|
|
126
|
+
1. Acquire API token from [Passman](https://passman.ci.uktrade.digital/secret/cc82a3f7-ddfa-4312-ab56-1ff8528dadc8/).
|
|
127
|
+
- Request access from the SRE team.
|
|
128
|
+
- _Note: You will need access to the `platform` group in Passman._
|
|
129
|
+
2. Run `poetry config pypi-token.pypi <token>` to add the token to your Poetry configuration.
|
|
130
|
+
|
|
131
|
+
Update the version, as the same version cannot be published to PyPI.
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
poetry version patch
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
More options for the `version` command can be found in the [Poetry documentation](https://python-poetry.org/docs/cli/#version). For example, for a minor version bump: `poetry version minor`.
|
|
138
|
+
|
|
139
|
+
Build the Python package.
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
poetry build
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Publish the Python package.
|
|
146
|
+
|
|
147
|
+
_Note: Make sure your Pull Request (PR) is approved and contains the version upgrade in `pyproject.toml` before publishing the package._
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
poetry publish
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Check the [PyPI Release history](https://pypi.org/project/django-log-formatter-asim/#history) to make sure the package has been updated.
|
|
154
|
+
|
|
155
|
+
For an optional manual check, install the package locally and test everything works as expected.
|
|
@@ -2,7 +2,10 @@ import json
|
|
|
2
2
|
import logging
|
|
3
3
|
from datetime import datetime
|
|
4
4
|
from importlib.metadata import distribution
|
|
5
|
+
import os
|
|
5
6
|
|
|
7
|
+
import ddtrace
|
|
8
|
+
from ddtrace.trace import tracer
|
|
6
9
|
from django.conf import settings
|
|
7
10
|
|
|
8
11
|
|
|
@@ -25,6 +28,46 @@ class ASIMRootFormatter:
|
|
|
25
28
|
|
|
26
29
|
return copied_dict
|
|
27
30
|
|
|
31
|
+
def _get_container_id(self):
|
|
32
|
+
"""
|
|
33
|
+
The dockerId (container Id) is available via the metadata endpoint. However, it looks like it is embedded in the
|
|
34
|
+
metadata URL e.g.:
|
|
35
|
+
ECS_CONTAINER_METADATA_URI=http://169.254.170.2/v3/709d1c10779d47b2a84db9eef2ebd041-0265927825
|
|
36
|
+
See: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v4-response.html
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
try:
|
|
40
|
+
return os.environ["ECS_CONTAINER_METADATA_URI"].split("/")[-1]
|
|
41
|
+
except (KeyError, IndexError):
|
|
42
|
+
return ""
|
|
43
|
+
|
|
44
|
+
def _get_first_64_bits_of(self, trace_id):
|
|
45
|
+
# See https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/python/#no-standard-library-logging
|
|
46
|
+
return str((1 << 64) - 1 & trace_id)
|
|
47
|
+
|
|
48
|
+
def _datadog_trace_dict(self):
|
|
49
|
+
event_dict = {}
|
|
50
|
+
|
|
51
|
+
span = tracer.current_span()
|
|
52
|
+
trace_id, span_id = (
|
|
53
|
+
(self._get_first_64_bits_of(span.trace_id), span.span_id)
|
|
54
|
+
if span
|
|
55
|
+
else (None, None)
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# add ids to structlog event dictionary
|
|
59
|
+
event_dict["dd.trace_id"] = str(trace_id or 0)
|
|
60
|
+
event_dict["dd.span_id"] = str(span_id or 0)
|
|
61
|
+
|
|
62
|
+
# add the env, service, and version configured for the tracer
|
|
63
|
+
event_dict["env"] = ddtrace.config.env or ""
|
|
64
|
+
event_dict["service"] = ddtrace.config.service or ""
|
|
65
|
+
event_dict["version"] = ddtrace.config.version or ""
|
|
66
|
+
|
|
67
|
+
event_dict["container_id"] = self._get_container_id()
|
|
68
|
+
|
|
69
|
+
return event_dict
|
|
70
|
+
|
|
28
71
|
def get_log_dict(self):
|
|
29
72
|
record = self.record
|
|
30
73
|
log_time = datetime.utcfromtimestamp(record.created).isoformat()
|
|
@@ -48,6 +91,8 @@ class ASIMRootFormatter:
|
|
|
48
91
|
},
|
|
49
92
|
}
|
|
50
93
|
|
|
94
|
+
log_dict.update(self._datadog_trace_dict())
|
|
95
|
+
|
|
51
96
|
if getattr(settings, "DLFA_INCLUDE_RAW_LOG", False):
|
|
52
97
|
return self.get_log_dict_with_raw(log_dict)
|
|
53
98
|
|
|
@@ -3,7 +3,7 @@ line-length = 100
|
|
|
3
3
|
|
|
4
4
|
[tool.poetry]
|
|
5
5
|
name = "django-log-formatter-asim"
|
|
6
|
-
version = "0.0
|
|
6
|
+
version = "1.0.0"
|
|
7
7
|
description = "Formats Django logs in ASIM format."
|
|
8
8
|
authors = ["Department for Business and Trade Platform Team <sre-team@digital.trade.gov.uk>"]
|
|
9
9
|
license = "MIT"
|
|
@@ -19,6 +19,7 @@ django = [
|
|
|
19
19
|
{ version = ">=3,<5", python = ">=3.9,<3.10" },
|
|
20
20
|
{ version = ">=3,<6", python = ">=3.10,<4" },
|
|
21
21
|
]
|
|
22
|
+
ddtrace = "^3.2.1"
|
|
22
23
|
|
|
23
24
|
[tool.poetry.group.dev.dependencies]
|
|
24
25
|
pre-commit = "^3.5.0"
|
|
File without changes
|