raven-logger 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.
- raven_logger-1.0.0/LICENSE +21 -0
- raven_logger-1.0.0/PKG-INFO +117 -0
- raven_logger-1.0.0/README.md +93 -0
- raven_logger-1.0.0/pyproject.toml +37 -0
- raven_logger-1.0.0/raven_logger.egg-info/PKG-INFO +117 -0
- raven_logger-1.0.0/raven_logger.egg-info/SOURCES.txt +8 -0
- raven_logger-1.0.0/raven_logger.egg-info/dependency_links.txt +1 -0
- raven_logger-1.0.0/raven_logger.egg-info/top_level.txt +1 -0
- raven_logger-1.0.0/raven_sdk/__init__.py +94 -0
- raven_logger-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Giggso
|
|
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,117 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: raven-logger
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Application logging SDK for raven-log contract compliance — structured, validated JSON logs
|
|
5
|
+
Author-email: Giggso <m.abbasi@giggso.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/giggso/raven-sdk
|
|
8
|
+
Project-URL: Issues, https://github.com/giggso/raven-sdk/issues
|
|
9
|
+
Keywords: logging,observability,structured-logging,raven,tracing
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: System :: Logging
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# raven-sdk
|
|
26
|
+
|
|
27
|
+
Application logging SDK for **raven-log contract compliance** — emit validated, structured JSON records from any Python service.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install raven-sdk
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Quick start
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from raven_sdk import raven_log, new_trace_id, new_span_id
|
|
39
|
+
|
|
40
|
+
trace = new_trace_id()
|
|
41
|
+
|
|
42
|
+
raven_log(
|
|
43
|
+
level="INFO",
|
|
44
|
+
criticality="P3",
|
|
45
|
+
message="User signed in",
|
|
46
|
+
service="auth-service",
|
|
47
|
+
env="prod",
|
|
48
|
+
principal="user:42",
|
|
49
|
+
project="my-app",
|
|
50
|
+
trace_id=trace,
|
|
51
|
+
)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Output (one JSON line to stdout):
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"schema_version": "1",
|
|
59
|
+
"timestamp": "2026-06-22T12:00:00.000000+00:00",
|
|
60
|
+
"level": "INFO",
|
|
61
|
+
"criticality": "P3",
|
|
62
|
+
"service": "auth-service",
|
|
63
|
+
"env": "prod",
|
|
64
|
+
"trace_id": "550e8400-e29b-41d4-a716-446655440000",
|
|
65
|
+
"span_id": "a1b2c3d4",
|
|
66
|
+
"principal": "user:42",
|
|
67
|
+
"error_code": "",
|
|
68
|
+
"message": "User signed in",
|
|
69
|
+
"context": {},
|
|
70
|
+
"sample_payload": "",
|
|
71
|
+
"project": "my-app"
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## API
|
|
76
|
+
|
|
77
|
+
### `raven_log(...) -> dict`
|
|
78
|
+
|
|
79
|
+
| Parameter | Type | Required | Description |
|
|
80
|
+
|---|---|---|---|
|
|
81
|
+
| `level` | `"ERROR"` \| `"WARN"` \| `"INFO"` \| `"DEBUG"` | ✓ | Log level |
|
|
82
|
+
| `criticality` | `"P1"` \| `"P2"` \| `"P3"` \| `"P4"` | ✓ | Business criticality |
|
|
83
|
+
| `message` | `str` | ✓ | Human-readable description |
|
|
84
|
+
| `service` | `str` | ✓ | Emitting service name |
|
|
85
|
+
| `env` | `"prod"` \| `"staging"` \| `"dev"` | ✓ | Deployment environment |
|
|
86
|
+
| `principal` | `str` | ✓ | Acting identity (e.g. `"user:42"`) |
|
|
87
|
+
| `project` | `str` | ✓ | Project/team identifier |
|
|
88
|
+
| `error_code` | `str` | Required for `ERROR`/`WARN` | Machine-readable error code |
|
|
89
|
+
| `trace_id` | `str` | — | Distributed trace ID (auto-generated if omitted) |
|
|
90
|
+
| `span_id` | `str` | — | Span ID (auto-generated if omitted) |
|
|
91
|
+
| `context` | `dict` | — | Arbitrary structured context |
|
|
92
|
+
| `sample_payload` | `str` | — | Redacted payload snippet |
|
|
93
|
+
|
|
94
|
+
Returns the emitted record as a `dict`.
|
|
95
|
+
|
|
96
|
+
### `new_trace_id() -> str`
|
|
97
|
+
|
|
98
|
+
Generates a UUID v4 trace ID for use at service boundaries.
|
|
99
|
+
|
|
100
|
+
### `new_span_id() -> str`
|
|
101
|
+
|
|
102
|
+
Generates an 8-character span ID for operations within a trace.
|
|
103
|
+
|
|
104
|
+
## Custom emitter (Kafka, etc.)
|
|
105
|
+
|
|
106
|
+
Pass `_emit` to replace the default stdout writer:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
def kafka_emit(record: dict) -> None:
|
|
110
|
+
producer.send("logs", json.dumps(record).encode())
|
|
111
|
+
|
|
112
|
+
raven_log(..., _emit=kafka_emit)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
MIT © Giggso
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# raven-sdk
|
|
2
|
+
|
|
3
|
+
Application logging SDK for **raven-log contract compliance** — emit validated, structured JSON records from any Python service.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install raven-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from raven_sdk import raven_log, new_trace_id, new_span_id
|
|
15
|
+
|
|
16
|
+
trace = new_trace_id()
|
|
17
|
+
|
|
18
|
+
raven_log(
|
|
19
|
+
level="INFO",
|
|
20
|
+
criticality="P3",
|
|
21
|
+
message="User signed in",
|
|
22
|
+
service="auth-service",
|
|
23
|
+
env="prod",
|
|
24
|
+
principal="user:42",
|
|
25
|
+
project="my-app",
|
|
26
|
+
trace_id=trace,
|
|
27
|
+
)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Output (one JSON line to stdout):
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"schema_version": "1",
|
|
35
|
+
"timestamp": "2026-06-22T12:00:00.000000+00:00",
|
|
36
|
+
"level": "INFO",
|
|
37
|
+
"criticality": "P3",
|
|
38
|
+
"service": "auth-service",
|
|
39
|
+
"env": "prod",
|
|
40
|
+
"trace_id": "550e8400-e29b-41d4-a716-446655440000",
|
|
41
|
+
"span_id": "a1b2c3d4",
|
|
42
|
+
"principal": "user:42",
|
|
43
|
+
"error_code": "",
|
|
44
|
+
"message": "User signed in",
|
|
45
|
+
"context": {},
|
|
46
|
+
"sample_payload": "",
|
|
47
|
+
"project": "my-app"
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## API
|
|
52
|
+
|
|
53
|
+
### `raven_log(...) -> dict`
|
|
54
|
+
|
|
55
|
+
| Parameter | Type | Required | Description |
|
|
56
|
+
|---|---|---|---|
|
|
57
|
+
| `level` | `"ERROR"` \| `"WARN"` \| `"INFO"` \| `"DEBUG"` | ✓ | Log level |
|
|
58
|
+
| `criticality` | `"P1"` \| `"P2"` \| `"P3"` \| `"P4"` | ✓ | Business criticality |
|
|
59
|
+
| `message` | `str` | ✓ | Human-readable description |
|
|
60
|
+
| `service` | `str` | ✓ | Emitting service name |
|
|
61
|
+
| `env` | `"prod"` \| `"staging"` \| `"dev"` | ✓ | Deployment environment |
|
|
62
|
+
| `principal` | `str` | ✓ | Acting identity (e.g. `"user:42"`) |
|
|
63
|
+
| `project` | `str` | ✓ | Project/team identifier |
|
|
64
|
+
| `error_code` | `str` | Required for `ERROR`/`WARN` | Machine-readable error code |
|
|
65
|
+
| `trace_id` | `str` | — | Distributed trace ID (auto-generated if omitted) |
|
|
66
|
+
| `span_id` | `str` | — | Span ID (auto-generated if omitted) |
|
|
67
|
+
| `context` | `dict` | — | Arbitrary structured context |
|
|
68
|
+
| `sample_payload` | `str` | — | Redacted payload snippet |
|
|
69
|
+
|
|
70
|
+
Returns the emitted record as a `dict`.
|
|
71
|
+
|
|
72
|
+
### `new_trace_id() -> str`
|
|
73
|
+
|
|
74
|
+
Generates a UUID v4 trace ID for use at service boundaries.
|
|
75
|
+
|
|
76
|
+
### `new_span_id() -> str`
|
|
77
|
+
|
|
78
|
+
Generates an 8-character span ID for operations within a trace.
|
|
79
|
+
|
|
80
|
+
## Custom emitter (Kafka, etc.)
|
|
81
|
+
|
|
82
|
+
Pass `_emit` to replace the default stdout writer:
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
def kafka_emit(record: dict) -> None:
|
|
86
|
+
producer.send("logs", json.dumps(record).encode())
|
|
87
|
+
|
|
88
|
+
raven_log(..., _emit=kafka_emit)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT © Giggso
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "raven-logger"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Application logging SDK for raven-log contract compliance — structured, validated JSON logs"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Giggso", email = "m.abbasi@giggso.com" }
|
|
14
|
+
]
|
|
15
|
+
keywords = ["logging", "observability", "structured-logging", "raven", "tracing"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 5 - Production/Stable",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.8",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Topic :: System :: Logging",
|
|
26
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
27
|
+
]
|
|
28
|
+
requires-python = ">=3.8"
|
|
29
|
+
dependencies = []
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Homepage = "https://github.com/giggso/raven-sdk"
|
|
33
|
+
Issues = "https://github.com/giggso/raven-sdk/issues"
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.packages.find]
|
|
36
|
+
where = ["."]
|
|
37
|
+
include = ["raven_sdk*"]
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: raven-logger
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Application logging SDK for raven-log contract compliance — structured, validated JSON logs
|
|
5
|
+
Author-email: Giggso <m.abbasi@giggso.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/giggso/raven-sdk
|
|
8
|
+
Project-URL: Issues, https://github.com/giggso/raven-sdk/issues
|
|
9
|
+
Keywords: logging,observability,structured-logging,raven,tracing
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: System :: Logging
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# raven-sdk
|
|
26
|
+
|
|
27
|
+
Application logging SDK for **raven-log contract compliance** — emit validated, structured JSON records from any Python service.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install raven-sdk
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Quick start
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from raven_sdk import raven_log, new_trace_id, new_span_id
|
|
39
|
+
|
|
40
|
+
trace = new_trace_id()
|
|
41
|
+
|
|
42
|
+
raven_log(
|
|
43
|
+
level="INFO",
|
|
44
|
+
criticality="P3",
|
|
45
|
+
message="User signed in",
|
|
46
|
+
service="auth-service",
|
|
47
|
+
env="prod",
|
|
48
|
+
principal="user:42",
|
|
49
|
+
project="my-app",
|
|
50
|
+
trace_id=trace,
|
|
51
|
+
)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Output (one JSON line to stdout):
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"schema_version": "1",
|
|
59
|
+
"timestamp": "2026-06-22T12:00:00.000000+00:00",
|
|
60
|
+
"level": "INFO",
|
|
61
|
+
"criticality": "P3",
|
|
62
|
+
"service": "auth-service",
|
|
63
|
+
"env": "prod",
|
|
64
|
+
"trace_id": "550e8400-e29b-41d4-a716-446655440000",
|
|
65
|
+
"span_id": "a1b2c3d4",
|
|
66
|
+
"principal": "user:42",
|
|
67
|
+
"error_code": "",
|
|
68
|
+
"message": "User signed in",
|
|
69
|
+
"context": {},
|
|
70
|
+
"sample_payload": "",
|
|
71
|
+
"project": "my-app"
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## API
|
|
76
|
+
|
|
77
|
+
### `raven_log(...) -> dict`
|
|
78
|
+
|
|
79
|
+
| Parameter | Type | Required | Description |
|
|
80
|
+
|---|---|---|---|
|
|
81
|
+
| `level` | `"ERROR"` \| `"WARN"` \| `"INFO"` \| `"DEBUG"` | ✓ | Log level |
|
|
82
|
+
| `criticality` | `"P1"` \| `"P2"` \| `"P3"` \| `"P4"` | ✓ | Business criticality |
|
|
83
|
+
| `message` | `str` | ✓ | Human-readable description |
|
|
84
|
+
| `service` | `str` | ✓ | Emitting service name |
|
|
85
|
+
| `env` | `"prod"` \| `"staging"` \| `"dev"` | ✓ | Deployment environment |
|
|
86
|
+
| `principal` | `str` | ✓ | Acting identity (e.g. `"user:42"`) |
|
|
87
|
+
| `project` | `str` | ✓ | Project/team identifier |
|
|
88
|
+
| `error_code` | `str` | Required for `ERROR`/`WARN` | Machine-readable error code |
|
|
89
|
+
| `trace_id` | `str` | — | Distributed trace ID (auto-generated if omitted) |
|
|
90
|
+
| `span_id` | `str` | — | Span ID (auto-generated if omitted) |
|
|
91
|
+
| `context` | `dict` | — | Arbitrary structured context |
|
|
92
|
+
| `sample_payload` | `str` | — | Redacted payload snippet |
|
|
93
|
+
|
|
94
|
+
Returns the emitted record as a `dict`.
|
|
95
|
+
|
|
96
|
+
### `new_trace_id() -> str`
|
|
97
|
+
|
|
98
|
+
Generates a UUID v4 trace ID for use at service boundaries.
|
|
99
|
+
|
|
100
|
+
### `new_span_id() -> str`
|
|
101
|
+
|
|
102
|
+
Generates an 8-character span ID for operations within a trace.
|
|
103
|
+
|
|
104
|
+
## Custom emitter (Kafka, etc.)
|
|
105
|
+
|
|
106
|
+
Pass `_emit` to replace the default stdout writer:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
def kafka_emit(record: dict) -> None:
|
|
110
|
+
producer.send("logs", json.dumps(record).encode())
|
|
111
|
+
|
|
112
|
+
raven_log(..., _emit=kafka_emit)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
MIT © Giggso
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
raven_sdk
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""
|
|
2
|
+
raven_sdk — Application logging SDK for raven-log contract compliance.
|
|
3
|
+
Import in your application:
|
|
4
|
+
from raven_sdk import raven_log, new_trace_id, new_span_id
|
|
5
|
+
Every call emits a validated, structured record to stdout (JSON).
|
|
6
|
+
In production, replace _emit() with your Kafka producer.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import json, sys, uuid, os
|
|
10
|
+
from datetime import datetime, timezone
|
|
11
|
+
from typing import Optional, Literal, Any
|
|
12
|
+
|
|
13
|
+
__version__ = "1.0.0"
|
|
14
|
+
|
|
15
|
+
SCHEMA_VERSION = "1"
|
|
16
|
+
|
|
17
|
+
_VALID_LEVELS = {"ERROR", "WARN", "INFO", "DEBUG"}
|
|
18
|
+
_VALID_CRITICALITIES = {"P1", "P2", "P3", "P4"}
|
|
19
|
+
_VALID_ENVS = {"prod", "staging", "dev"}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def new_trace_id() -> str:
|
|
23
|
+
"""Generate a new trace ID at a service boundary."""
|
|
24
|
+
return str(uuid.uuid4())
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def new_span_id() -> str:
|
|
28
|
+
"""Generate a new span ID for an operation within a trace."""
|
|
29
|
+
return str(uuid.uuid4())[:8]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def raven_log(
|
|
33
|
+
level: Literal["ERROR", "WARN", "INFO", "DEBUG"],
|
|
34
|
+
criticality: Literal["P1", "P2", "P3", "P4"],
|
|
35
|
+
message: str,
|
|
36
|
+
service: str,
|
|
37
|
+
env: Literal["prod", "staging", "dev"],
|
|
38
|
+
principal: str,
|
|
39
|
+
project: str,
|
|
40
|
+
error_code: str = "",
|
|
41
|
+
trace_id: Optional[str] = None,
|
|
42
|
+
span_id: Optional[str] = None,
|
|
43
|
+
context: Optional[dict] = None,
|
|
44
|
+
sample_payload: str = "",
|
|
45
|
+
_emit=None,
|
|
46
|
+
) -> dict:
|
|
47
|
+
"""
|
|
48
|
+
Emit one raven-log conformant structured record.
|
|
49
|
+
Raises ValueError if required fields are missing or invalid.
|
|
50
|
+
"""
|
|
51
|
+
# ── Validation ──────────────────────────────────────────────────────────────
|
|
52
|
+
if level not in _VALID_LEVELS:
|
|
53
|
+
raise ValueError(f"raven_log: level '{level}' invalid — must be one of {_VALID_LEVELS}")
|
|
54
|
+
if criticality not in _VALID_CRITICALITIES:
|
|
55
|
+
raise ValueError(f"raven_log: criticality '{criticality}' invalid — must be one of {_VALID_CRITICALITIES}")
|
|
56
|
+
if env not in _VALID_ENVS:
|
|
57
|
+
raise ValueError(f"raven_log: env '{env}' invalid — must be one of {_VALID_ENVS}")
|
|
58
|
+
if level in ("ERROR", "WARN") and not error_code:
|
|
59
|
+
raise ValueError(f"raven_log: error_code is required when level is {level}")
|
|
60
|
+
if not service:
|
|
61
|
+
raise ValueError("raven_log: service is required")
|
|
62
|
+
if not principal:
|
|
63
|
+
raise ValueError("raven_log: principal is required")
|
|
64
|
+
if not project:
|
|
65
|
+
raise ValueError("raven_log: project is required")
|
|
66
|
+
|
|
67
|
+
# ── Build record ────────────────────────────────────────────────────────────
|
|
68
|
+
record = {
|
|
69
|
+
"schema_version": SCHEMA_VERSION,
|
|
70
|
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
71
|
+
"level": level,
|
|
72
|
+
"criticality": criticality,
|
|
73
|
+
"service": service,
|
|
74
|
+
"env": env,
|
|
75
|
+
"trace_id": trace_id or new_trace_id(),
|
|
76
|
+
"span_id": span_id or new_span_id(),
|
|
77
|
+
"principal": principal,
|
|
78
|
+
"error_code": error_code,
|
|
79
|
+
"message": message,
|
|
80
|
+
"context": context or {},
|
|
81
|
+
"sample_payload": sample_payload,
|
|
82
|
+
"project": project,
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
# ── Emit ─────────────────────────────────────────────────────────────────────
|
|
86
|
+
emitter = _emit or _default_emit
|
|
87
|
+
emitter(record)
|
|
88
|
+
|
|
89
|
+
return record
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _default_emit(record: dict) -> None:
|
|
93
|
+
"""Default emitter: write one JSON line to stdout."""
|
|
94
|
+
print(json.dumps(record), flush=True)
|