pyLogAndOrder 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.
- pylogandorder-1.0.0/COMPATIBILITY.md +26 -0
- pylogandorder-1.0.0/GLOSSARY.md +36 -0
- pylogandorder-1.0.0/LICENSE +21 -0
- pylogandorder-1.0.0/MANIFEST.in +6 -0
- pylogandorder-1.0.0/PKG-INFO +171 -0
- pylogandorder-1.0.0/README.md +141 -0
- pylogandorder-1.0.0/deploy/README.md +40 -0
- pylogandorder-1.0.0/deploy/main.bicep +93 -0
- pylogandorder-1.0.0/docs/adr/0001-target-supported-ingestion-without-legacy-compatibility.md +5 -0
- pylogandorder-1.0.0/docs/adr/0002-use-one-event-envelope.md +5 -0
- pylogandorder-1.0.0/docs/adr/0003-app-registration-authentication.md +5 -0
- pylogandorder-1.0.0/docs/agents/domain.md +25 -0
- pylogandorder-1.0.0/docs/agents/issue-tracker.md +24 -0
- pylogandorder-1.0.0/docs/agents/triage-labels.md +11 -0
- pylogandorder-1.0.0/docs/demo-resources.json +24 -0
- pylogandorder-1.0.0/docs/live-verification.md +34 -0
- pylogandorder-1.0.0/docs/plans/logs-ingestion-publication.json +381 -0
- pylogandorder-1.0.0/docs/plans/logs-ingestion-tickets.md +298 -0
- pylogandorder-1.0.0/docs/proposals/durable-storage.md +58 -0
- pylogandorder-1.0.0/docs/publishing.md +34 -0
- pylogandorder-1.0.0/docs/specs/logs-ingestion-migration.md +167 -0
- pylogandorder-1.0.0/docs/specs/shared-event-fixtures.json +293 -0
- pylogandorder-1.0.0/examples/basic_usage.py +22 -0
- pylogandorder-1.0.0/pyproject.toml +54 -0
- pylogandorder-1.0.0/scripts/fetch_release.py +33 -0
- pylogandorder-1.0.0/scripts/test_live.py +100 -0
- pylogandorder-1.0.0/scripts/test_package.py +16 -0
- pylogandorder-1.0.0/setup.cfg +4 -0
- pylogandorder-1.0.0/src/pyLogAndOrder.egg-info/PKG-INFO +171 -0
- pylogandorder-1.0.0/src/pyLogAndOrder.egg-info/SOURCES.txt +41 -0
- pylogandorder-1.0.0/src/pyLogAndOrder.egg-info/dependency_links.txt +1 -0
- pylogandorder-1.0.0/src/pyLogAndOrder.egg-info/requires.txt +9 -0
- pylogandorder-1.0.0/src/pyLogAndOrder.egg-info/top_level.txt +1 -0
- pylogandorder-1.0.0/src/pylogandorder/__init__.py +19 -0
- pylogandorder-1.0.0/src/pylogandorder/_credentials.py +93 -0
- pylogandorder-1.0.0/src/pylogandorder/_events.py +110 -0
- pylogandorder-1.0.0/src/pylogandorder/_policy.py +76 -0
- pylogandorder-1.0.0/src/pylogandorder/client.py +173 -0
- pylogandorder-1.0.0/src/pylogandorder/handler.py +226 -0
- pylogandorder-1.0.0/tests/__init__.py +1 -0
- pylogandorder-1.0.0/tests/test_client.py +262 -0
- pylogandorder-1.0.0/tests/test_deployment.py +27 -0
- pylogandorder-1.0.0/tests/test_handler.py +162 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Compatibility
|
|
2
|
+
|
|
3
|
+
Python 3.12+ is required. CI tests Windows and Linux on 3.12, 3.13 and 3.14.
|
|
4
|
+
The client uses azure-monitor-ingestion 1.1.x and Azure Identity 1.x. A constrained
|
|
5
|
+
SDK version keeps the tested serialization/chunking contract explicit.
|
|
6
|
+
|
|
7
|
+
The shared event envelope matches PowerShell LogAndOrder 2.0: TimeGenerated,
|
|
8
|
+
level, message and dynamic properties. Shared fixtures in docs/specs are
|
|
9
|
+
byte-identical between repositories. JSON whitespace, compression and object-key
|
|
10
|
+
order are not event data. Generated Python source/exception context belongs
|
|
11
|
+
inside properties and can be sent explicitly from another language.
|
|
12
|
+
|
|
13
|
+
The handler is asynchronous and bounded. Unlike a synchronous logging handler,
|
|
14
|
+
a logging call acknowledges queue admission rather than Azure acceptance. Use
|
|
15
|
+
its counters, safe callback and lifecycle reports to assess loss or incomplete
|
|
16
|
+
work. This package does not preserve the old logging-azure-rest top-level schema.
|
|
17
|
+
|
|
18
|
+
0.1.x workspace keys, legacy constructors and time_field are removed without
|
|
19
|
+
shims. Use an existing workspace with a new compatible table and DCR, and migrate
|
|
20
|
+
queries/alerts from suffixes such as message_s to the shared schema. An in-place
|
|
21
|
+
classic-table migration is irreversible operator work, never automatic behavior.
|
|
22
|
+
|
|
23
|
+
Public Azure and the selected app-registration modes are the built-in contract.
|
|
24
|
+
Native managed identity/certificates, sovereign-cloud presets and durable storage
|
|
25
|
+
remain follow-up work. Caller-supplied TokenCredential is supported without
|
|
26
|
+
changing the event contract. Historical releases are retained.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# LogAndOrder telemetry
|
|
2
|
+
|
|
3
|
+
Shared language for events sent by LogAndOrder and pyLogAndOrder to Azure Monitor Logs.
|
|
4
|
+
|
|
5
|
+
## Language
|
|
6
|
+
|
|
7
|
+
**Event**:
|
|
8
|
+
A timestamped statement with a severity, a message, and additional contextual properties.
|
|
9
|
+
_Avoid_: Row, logging record (when referring to the cross-language event)
|
|
10
|
+
|
|
11
|
+
**Event envelope**:
|
|
12
|
+
The common set of event fields used by both libraries: TimeGenerated, level, message, and properties.
|
|
13
|
+
|
|
14
|
+
**Event time**:
|
|
15
|
+
The time the event occurred, rather than the time Azure accepted or stored it.
|
|
16
|
+
|
|
17
|
+
**Properties**:
|
|
18
|
+
Additional event context, including service information, source metadata, exceptions, and custom values.
|
|
19
|
+
_Avoid_: Top-level extras
|
|
20
|
+
|
|
21
|
+
**Input stream**:
|
|
22
|
+
A named input declared by a data collection rule, describing the incoming event schema.
|
|
23
|
+
_Avoid_: Table name (when referring to the input stream)
|
|
24
|
+
|
|
25
|
+
**Destination table**:
|
|
26
|
+
The Log Analytics table to which a data collection rule routes events.
|
|
27
|
+
|
|
28
|
+
**Ingestion acceptance**:
|
|
29
|
+
Azure's acknowledgement that an ingestion request was accepted; it does not establish that its events are queryable.
|
|
30
|
+
_Avoid_: Delivery confirmation (when only acceptance is known)
|
|
31
|
+
|
|
32
|
+
**Query visibility**:
|
|
33
|
+
The presence of an accepted event in the destination table when queried.
|
|
34
|
+
|
|
35
|
+
**Side-by-side migration**:
|
|
36
|
+
A migration into a new destination table while an existing table remains available for validating data, queries, and alerts.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Nedomkull Mathematical Modeling
|
|
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,171 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyLogAndOrder
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Entra-authenticated Azure Monitor Logs Ingestion client and bounded logging handler
|
|
5
|
+
Author: Nedomkull Mathematical Modeling
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Nedomkull-Mathematical-Modeling/pyLogAndOrder
|
|
8
|
+
Project-URL: Repository, https://github.com/Nedomkull-Mathematical-Modeling/pyLogAndOrder
|
|
9
|
+
Keywords: azure,log-analytics,telemetry,logging,monitoring
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Topic :: System :: Logging
|
|
17
|
+
Classifier: Topic :: System :: Monitoring
|
|
18
|
+
Requires-Python: >=3.12
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: azure-monitor-ingestion<1.2,>=1.1.0
|
|
22
|
+
Requires-Dist: azure-identity<2,>=1.27.1
|
|
23
|
+
Requires-Dist: azure-core<2,>=1.41.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest<10,>=8; extra == "dev"
|
|
26
|
+
Requires-Dist: mypy<3,>=1.15; extra == "dev"
|
|
27
|
+
Requires-Dist: build<2,>=1.2; extra == "dev"
|
|
28
|
+
Requires-Dist: twine<8,>=6; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# pyLogAndOrder
|
|
32
|
+
|
|
33
|
+
Send the same event envelope as PowerShell LogAndOrder through Microsoft's
|
|
34
|
+
Azure Monitor Logs Ingestion SDK. Requires Python 3.12 or later; CI covers
|
|
35
|
+
3.12, 3.13 and 3.14 on Windows and Linux.
|
|
36
|
+
|
|
37
|
+
Version 1.0.0 is a breaking release candidate, pending registry publication.
|
|
38
|
+
For development, install this checkout with `python -m pip install -e ".[dev]"`.
|
|
39
|
+
After publication: `python -m pip install pyLogAndOrder==1.0.0`.
|
|
40
|
+
|
|
41
|
+
## Configure Azure
|
|
42
|
+
|
|
43
|
+
Create an Entra app registration and service principal. Deploy the shared
|
|
44
|
+
four-column table, Direct DCR and DCR-scoped Monitoring Metrics Publisher role
|
|
45
|
+
into an existing workspace using [deploy/main.bicep](deploy/main.bicep).
|
|
46
|
+
[Deployment instructions](deploy/README.md) include side-by-side migration and
|
|
47
|
+
the irreversible in-place operator alternative. The service-principal object ID
|
|
48
|
+
is different from the application's client ID. Normal library calls never
|
|
49
|
+
provision, migrate or delete Azure resources.
|
|
50
|
+
|
|
51
|
+
Explicit keyword arguments take precedence over these environment settings:
|
|
52
|
+
|
|
53
|
+
| Argument | Environment variable |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| `endpoint` | `LA_INGESTION_ENDPOINT` |
|
|
56
|
+
| `dcr_immutable_id` | `LA_DCR_IMMUTABLE_ID` |
|
|
57
|
+
| `stream_name` | `LA_STREAM_NAME` |
|
|
58
|
+
| `auth_mode` | `LA_AUTH_MODE` |
|
|
59
|
+
| `tenant_id` | `AZURE_TENANT_ID` |
|
|
60
|
+
| `client_id` | `AZURE_CLIENT_ID` |
|
|
61
|
+
| `federated_token_file` | `AZURE_FEDERATED_TOKEN_FILE` |
|
|
62
|
+
| `client_secret` | `AZURE_CLIENT_SECRET` |
|
|
63
|
+
|
|
64
|
+
Prefer `workload_identity`: configure the application's exact external issuer,
|
|
65
|
+
subject and `api://AzureADTokenExchange` audience, and have your host refresh the
|
|
66
|
+
assertion file. The adapter invalidates Azure Identity's assertion source when
|
|
67
|
+
the file changes; Azure Identity exchanges it for Monitor scope
|
|
68
|
+
`https://monitor.azure.com/.default` and owns token renewal/cache behavior.
|
|
69
|
+
A GitHub job identity does not supply a permanent identity for an unrelated daemon.
|
|
70
|
+
Use explicit `client_secret` mode on hosts without an OIDC issuer. Store secrets
|
|
71
|
+
in the host's secret manager. If both credential sources exist, select a mode;
|
|
72
|
+
OIDC failures never silently switch to a secret. A caller-owned Azure
|
|
73
|
+
`credential` can also be supplied. Such credentials must implement finite token
|
|
74
|
+
acquisition timeouts; the library cannot cancel arbitrary caller code.
|
|
75
|
+
|
|
76
|
+
## Direct sending
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from pylogandorder import LogAnalyticsClient, IngestionError
|
|
80
|
+
|
|
81
|
+
with LogAnalyticsClient() as client: # settings from the host environment
|
|
82
|
+
result = client.send_event({
|
|
83
|
+
"message": "worker started", "level": "INFO",
|
|
84
|
+
"properties": {"service": "worker", "nested": {"ok": True}},
|
|
85
|
+
})
|
|
86
|
+
print(result.records_accepted)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
`send_log_analytics_event(data, **settings)` is a one-shot alternative. A reusable
|
|
90
|
+
client avoids repeated credential initialization. Inputs are dictionaries, lists
|
|
91
|
+
of dictionaries or raw JSON. Output always has `TimeGenerated`, `level`,
|
|
92
|
+
`message`, `properties`. Event time is UTC with six fractional digits and a Z
|
|
93
|
+
suffix; an explicitly supplied time must include a timezone. Severity defaults
|
|
94
|
+
to INFO; WARN/FATAL normalize to WARNING/CRITICAL. Unknown top-level fields move
|
|
95
|
+
into properties. Conflicting members, duplicate JSON keys, unsupported types and
|
|
96
|
+
nonfinite numbers are rejected before sending. Nested values and Unicode survive.
|
|
97
|
+
|
|
98
|
+
Preflight validates the entire input before any upload, enforces 64,000 bytes
|
|
99
|
+
per serialized canonical field and 1,000,000 bytes for both raw/compressed
|
|
100
|
+
requests. Nothing is silently truncated. The SDK performs compression and
|
|
101
|
+
serialization; an SDK pipeline guard checks actual wire sizes. An empty list
|
|
102
|
+
returns zero counts without acquiring a token; configuration is still validated.
|
|
103
|
+
|
|
104
|
+
`SendSummary` contains `records_total`, `records_accepted`, `records_failed`,
|
|
105
|
+
`records_unconfirmed`, `records_not_attempted`, `batches_accepted`, `request_ids`.
|
|
106
|
+
Terminal record counts sum to the total. Terminal failures raise `IngestionError`
|
|
107
|
+
with `.summary` and safe `.status_code`; inspect the summary before replaying.
|
|
108
|
+
The configured SDK retry policy owns at most `max_retries=3` retries after the
|
|
109
|
+
initial attempt, within `timeout=60` seconds. It honors Retry-After on 429,
|
|
110
|
+
uses exponential backoff plus jitter for transient service/network failures,
|
|
111
|
+
and never retries 400/401/403/404/413. Later batches stop after terminal failure.
|
|
112
|
+
Timeouts are uncertain; a later permanent retry rejection cannot disprove earlier
|
|
113
|
+
acceptance. Retrying uncertain events may create duplicates. Acceptance does not
|
|
114
|
+
prove query visibility. No durable storage or exactly-once guarantee is provided.
|
|
115
|
+
|
|
116
|
+
## Standard logging
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
import logging
|
|
120
|
+
from pylogandorder import LogAnalyticsHandler
|
|
121
|
+
|
|
122
|
+
handler = LogAnalyticsHandler(extra_fields={"service": "worker"})
|
|
123
|
+
logger = logging.getLogger("worker")
|
|
124
|
+
logger.setLevel(logging.INFO)
|
|
125
|
+
logger.addHandler(handler)
|
|
126
|
+
logger.info("completed %s", "å", extra={"customer": "example"})
|
|
127
|
+
report = handler.flush(timeout=30)
|
|
128
|
+
logger.removeHandler(handler)
|
|
129
|
+
shutdown = handler.close(timeout=30)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The handler uses occurrence time, severity and formatted message. Source
|
|
133
|
+
metadata and exceptions go under properties; per-record context overrides
|
|
134
|
+
defaults. Generated `source`/`exception` fields are reserved. One worker owns all
|
|
135
|
+
uploads; the waiting queue defaults to 1000 records and at most 100 more are in
|
|
136
|
+
flight. Queue-full and invalid records are dropped visibly. Diagnostics go
|
|
137
|
+
directly to stderr, default to once per minute per category and exclude payloads/credentials. Optional
|
|
138
|
+
`on_error(records, context)` receives affected canonical events and safe context;
|
|
139
|
+
callback exceptions are contained and recursive handler logging is suppressed.
|
|
140
|
+
|
|
141
|
+
`handler.counters` is a thread-safe snapshot of `accepted`, `failed`,
|
|
142
|
+
`unconfirmed`, `dropped_queue_full`, `dropped_invalid`, `dropped_closed`,
|
|
143
|
+
`abandoned_on_close`, `queued` and `in_flight`. Unsubmitted records after a
|
|
144
|
+
terminal batch failure count as failed at the handler, rather than disappearing.
|
|
145
|
+
|
|
146
|
+
`flush` includes every record admitted before its call, including an active
|
|
147
|
+
upload. Its default deadline is 30 seconds. `close` stops admission, drains once
|
|
148
|
+
with a default 30-second deadline and is idempotent. `LifecycleReport` separates
|
|
149
|
+
pending work, abandoned queued events and `in_flight_unconfirmed`. A deadline
|
|
150
|
+
stops waiting; it does not cancel an active SDK request, which may finish later
|
|
151
|
+
and update counters. No concurrent forced resend occurs. Emit after close is
|
|
152
|
+
rejected and diagnosed. Injected clients remain caller-owned; otherwise the
|
|
153
|
+
worker closes its owned client after the active request finishes. Abandoned-event
|
|
154
|
+
callbacks run on that worker after any active upload; they never extend the
|
|
155
|
+
caller's close deadline and may finish later than close returns.
|
|
156
|
+
|
|
157
|
+
## Migration and verification
|
|
158
|
+
|
|
159
|
+
Version 1.0 removes `workspace_id`, `shared_key`, `log_type`, `time_field` and
|
|
160
|
+
legacy headers/signatures. Replace these with endpoint/DCR/input-stream and
|
|
161
|
+
Entra credentials. Move service/customer/source/exception fields into properties.
|
|
162
|
+
Old KQL suffixes such as `message_s`, `httpStatus_d`, `timestamp_t` do not appear
|
|
163
|
+
in the new schema: update queries and alerts or explicitly map historical data.
|
|
164
|
+
See [COMPATIBILITY.md](COMPATIBILITY.md).
|
|
165
|
+
|
|
166
|
+
Offline verification: `python -m pytest -q` and
|
|
167
|
+
`python -m mypy src --check-untyped-defs --follow-imports=silent`.
|
|
168
|
+
Install Azure CLI and pinned Bicep v0.49.2 for compiled deployment tests.
|
|
169
|
+
Live verification is opt-in: [instructions](docs/live-verification.md).
|
|
170
|
+
Build using `python -m build`; validate metadata using `python -m twine check dist/*`.
|
|
171
|
+
Registry publication requires approval of the exact reviewed wheel/source artifacts.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# pyLogAndOrder
|
|
2
|
+
|
|
3
|
+
Send the same event envelope as PowerShell LogAndOrder through Microsoft's
|
|
4
|
+
Azure Monitor Logs Ingestion SDK. Requires Python 3.12 or later; CI covers
|
|
5
|
+
3.12, 3.13 and 3.14 on Windows and Linux.
|
|
6
|
+
|
|
7
|
+
Version 1.0.0 is a breaking release candidate, pending registry publication.
|
|
8
|
+
For development, install this checkout with `python -m pip install -e ".[dev]"`.
|
|
9
|
+
After publication: `python -m pip install pyLogAndOrder==1.0.0`.
|
|
10
|
+
|
|
11
|
+
## Configure Azure
|
|
12
|
+
|
|
13
|
+
Create an Entra app registration and service principal. Deploy the shared
|
|
14
|
+
four-column table, Direct DCR and DCR-scoped Monitoring Metrics Publisher role
|
|
15
|
+
into an existing workspace using [deploy/main.bicep](deploy/main.bicep).
|
|
16
|
+
[Deployment instructions](deploy/README.md) include side-by-side migration and
|
|
17
|
+
the irreversible in-place operator alternative. The service-principal object ID
|
|
18
|
+
is different from the application's client ID. Normal library calls never
|
|
19
|
+
provision, migrate or delete Azure resources.
|
|
20
|
+
|
|
21
|
+
Explicit keyword arguments take precedence over these environment settings:
|
|
22
|
+
|
|
23
|
+
| Argument | Environment variable |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| `endpoint` | `LA_INGESTION_ENDPOINT` |
|
|
26
|
+
| `dcr_immutable_id` | `LA_DCR_IMMUTABLE_ID` |
|
|
27
|
+
| `stream_name` | `LA_STREAM_NAME` |
|
|
28
|
+
| `auth_mode` | `LA_AUTH_MODE` |
|
|
29
|
+
| `tenant_id` | `AZURE_TENANT_ID` |
|
|
30
|
+
| `client_id` | `AZURE_CLIENT_ID` |
|
|
31
|
+
| `federated_token_file` | `AZURE_FEDERATED_TOKEN_FILE` |
|
|
32
|
+
| `client_secret` | `AZURE_CLIENT_SECRET` |
|
|
33
|
+
|
|
34
|
+
Prefer `workload_identity`: configure the application's exact external issuer,
|
|
35
|
+
subject and `api://AzureADTokenExchange` audience, and have your host refresh the
|
|
36
|
+
assertion file. The adapter invalidates Azure Identity's assertion source when
|
|
37
|
+
the file changes; Azure Identity exchanges it for Monitor scope
|
|
38
|
+
`https://monitor.azure.com/.default` and owns token renewal/cache behavior.
|
|
39
|
+
A GitHub job identity does not supply a permanent identity for an unrelated daemon.
|
|
40
|
+
Use explicit `client_secret` mode on hosts without an OIDC issuer. Store secrets
|
|
41
|
+
in the host's secret manager. If both credential sources exist, select a mode;
|
|
42
|
+
OIDC failures never silently switch to a secret. A caller-owned Azure
|
|
43
|
+
`credential` can also be supplied. Such credentials must implement finite token
|
|
44
|
+
acquisition timeouts; the library cannot cancel arbitrary caller code.
|
|
45
|
+
|
|
46
|
+
## Direct sending
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from pylogandorder import LogAnalyticsClient, IngestionError
|
|
50
|
+
|
|
51
|
+
with LogAnalyticsClient() as client: # settings from the host environment
|
|
52
|
+
result = client.send_event({
|
|
53
|
+
"message": "worker started", "level": "INFO",
|
|
54
|
+
"properties": {"service": "worker", "nested": {"ok": True}},
|
|
55
|
+
})
|
|
56
|
+
print(result.records_accepted)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`send_log_analytics_event(data, **settings)` is a one-shot alternative. A reusable
|
|
60
|
+
client avoids repeated credential initialization. Inputs are dictionaries, lists
|
|
61
|
+
of dictionaries or raw JSON. Output always has `TimeGenerated`, `level`,
|
|
62
|
+
`message`, `properties`. Event time is UTC with six fractional digits and a Z
|
|
63
|
+
suffix; an explicitly supplied time must include a timezone. Severity defaults
|
|
64
|
+
to INFO; WARN/FATAL normalize to WARNING/CRITICAL. Unknown top-level fields move
|
|
65
|
+
into properties. Conflicting members, duplicate JSON keys, unsupported types and
|
|
66
|
+
nonfinite numbers are rejected before sending. Nested values and Unicode survive.
|
|
67
|
+
|
|
68
|
+
Preflight validates the entire input before any upload, enforces 64,000 bytes
|
|
69
|
+
per serialized canonical field and 1,000,000 bytes for both raw/compressed
|
|
70
|
+
requests. Nothing is silently truncated. The SDK performs compression and
|
|
71
|
+
serialization; an SDK pipeline guard checks actual wire sizes. An empty list
|
|
72
|
+
returns zero counts without acquiring a token; configuration is still validated.
|
|
73
|
+
|
|
74
|
+
`SendSummary` contains `records_total`, `records_accepted`, `records_failed`,
|
|
75
|
+
`records_unconfirmed`, `records_not_attempted`, `batches_accepted`, `request_ids`.
|
|
76
|
+
Terminal record counts sum to the total. Terminal failures raise `IngestionError`
|
|
77
|
+
with `.summary` and safe `.status_code`; inspect the summary before replaying.
|
|
78
|
+
The configured SDK retry policy owns at most `max_retries=3` retries after the
|
|
79
|
+
initial attempt, within `timeout=60` seconds. It honors Retry-After on 429,
|
|
80
|
+
uses exponential backoff plus jitter for transient service/network failures,
|
|
81
|
+
and never retries 400/401/403/404/413. Later batches stop after terminal failure.
|
|
82
|
+
Timeouts are uncertain; a later permanent retry rejection cannot disprove earlier
|
|
83
|
+
acceptance. Retrying uncertain events may create duplicates. Acceptance does not
|
|
84
|
+
prove query visibility. No durable storage or exactly-once guarantee is provided.
|
|
85
|
+
|
|
86
|
+
## Standard logging
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
import logging
|
|
90
|
+
from pylogandorder import LogAnalyticsHandler
|
|
91
|
+
|
|
92
|
+
handler = LogAnalyticsHandler(extra_fields={"service": "worker"})
|
|
93
|
+
logger = logging.getLogger("worker")
|
|
94
|
+
logger.setLevel(logging.INFO)
|
|
95
|
+
logger.addHandler(handler)
|
|
96
|
+
logger.info("completed %s", "å", extra={"customer": "example"})
|
|
97
|
+
report = handler.flush(timeout=30)
|
|
98
|
+
logger.removeHandler(handler)
|
|
99
|
+
shutdown = handler.close(timeout=30)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The handler uses occurrence time, severity and formatted message. Source
|
|
103
|
+
metadata and exceptions go under properties; per-record context overrides
|
|
104
|
+
defaults. Generated `source`/`exception` fields are reserved. One worker owns all
|
|
105
|
+
uploads; the waiting queue defaults to 1000 records and at most 100 more are in
|
|
106
|
+
flight. Queue-full and invalid records are dropped visibly. Diagnostics go
|
|
107
|
+
directly to stderr, default to once per minute per category and exclude payloads/credentials. Optional
|
|
108
|
+
`on_error(records, context)` receives affected canonical events and safe context;
|
|
109
|
+
callback exceptions are contained and recursive handler logging is suppressed.
|
|
110
|
+
|
|
111
|
+
`handler.counters` is a thread-safe snapshot of `accepted`, `failed`,
|
|
112
|
+
`unconfirmed`, `dropped_queue_full`, `dropped_invalid`, `dropped_closed`,
|
|
113
|
+
`abandoned_on_close`, `queued` and `in_flight`. Unsubmitted records after a
|
|
114
|
+
terminal batch failure count as failed at the handler, rather than disappearing.
|
|
115
|
+
|
|
116
|
+
`flush` includes every record admitted before its call, including an active
|
|
117
|
+
upload. Its default deadline is 30 seconds. `close` stops admission, drains once
|
|
118
|
+
with a default 30-second deadline and is idempotent. `LifecycleReport` separates
|
|
119
|
+
pending work, abandoned queued events and `in_flight_unconfirmed`. A deadline
|
|
120
|
+
stops waiting; it does not cancel an active SDK request, which may finish later
|
|
121
|
+
and update counters. No concurrent forced resend occurs. Emit after close is
|
|
122
|
+
rejected and diagnosed. Injected clients remain caller-owned; otherwise the
|
|
123
|
+
worker closes its owned client after the active request finishes. Abandoned-event
|
|
124
|
+
callbacks run on that worker after any active upload; they never extend the
|
|
125
|
+
caller's close deadline and may finish later than close returns.
|
|
126
|
+
|
|
127
|
+
## Migration and verification
|
|
128
|
+
|
|
129
|
+
Version 1.0 removes `workspace_id`, `shared_key`, `log_type`, `time_field` and
|
|
130
|
+
legacy headers/signatures. Replace these with endpoint/DCR/input-stream and
|
|
131
|
+
Entra credentials. Move service/customer/source/exception fields into properties.
|
|
132
|
+
Old KQL suffixes such as `message_s`, `httpStatus_d`, `timestamp_t` do not appear
|
|
133
|
+
in the new schema: update queries and alerts or explicitly map historical data.
|
|
134
|
+
See [COMPATIBILITY.md](COMPATIBILITY.md).
|
|
135
|
+
|
|
136
|
+
Offline verification: `python -m pytest -q` and
|
|
137
|
+
`python -m mypy src --check-untyped-defs --follow-imports=silent`.
|
|
138
|
+
Install Azure CLI and pinned Bicep v0.49.2 for compiled deployment tests.
|
|
139
|
+
Live verification is opt-in: [instructions](docs/live-verification.md).
|
|
140
|
+
Build using `python -m build`; validate metadata using `python -m twine check dist/*`.
|
|
141
|
+
Registry publication requires approval of the exact reviewed wheel/source artifacts.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Provision ingestion resources
|
|
2
|
+
|
|
3
|
+
Sign in to the intended tenant/subscription with Azure CLI. Bicep deploys into
|
|
4
|
+
the resource group containing an existing Log Analytics workspace; it does not
|
|
5
|
+
create a workspace or change its quota, SKU or existing tables.
|
|
6
|
+
|
|
7
|
+
```powershell
|
|
8
|
+
az bicep install --version v0.49.2
|
|
9
|
+
az deployment group create --subscription '<subscription ID>' --resource-group '<workspace resource group>' --template-file deploy/main.bicep --parameters workspaceName='<existing workspace>' location='<workspace region>' principalObjectId='<service-principal object ID>' tableName='MyEvents_CL' dcrName='dcr-my-events' inputStreamName='Custom-MyEvents'
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
The table has exactly the common four columns. The Direct DCR supplies its own
|
|
13
|
+
ingestion endpoint and projects those same fields to the table. The role
|
|
14
|
+
assignment grants Monitoring Metrics Publisher on this DCR only. Outputs expose
|
|
15
|
+
the endpoint, immutable DCR ID and declared input stream for application settings.
|
|
16
|
+
The input stream need not equal the output table name. Existing compatible DCE
|
|
17
|
+
endpoints can also be supplied to the library when required by the operator's network.
|
|
18
|
+
|
|
19
|
+
Use a **new table name** for side-by-side migration. Preserve the old table while
|
|
20
|
+
validating queries and alerts. For example, replace `message_s` with `message`
|
|
21
|
+
and map an old custom `httpStatus_d` value into `properties.httpStatus`. If an
|
|
22
|
+
operator instead chooses irreversible in-place migration, first inventory
|
|
23
|
+
existing column names, data flows and dependent queries; the supplied template
|
|
24
|
+
does not perform that operation.
|
|
25
|
+
|
|
26
|
+
App registration, service-principal creation and federated trust require separate
|
|
27
|
+
directory permissions and are intentionally not bundled into this resource template.
|
|
28
|
+
For OIDC, configure exact issuer/subject/audience trust. The assertion audience is
|
|
29
|
+
`api://AzureADTokenExchange`; the exchanged access-token scope is
|
|
30
|
+
`https://monitor.azure.com/.default`. The hosting platform owns assertion refresh.
|
|
31
|
+
|
|
32
|
+
Query verification needs additional operator query permission. The ingestion
|
|
33
|
+
publisher role does not grant data-read access. Keep test data isolated and grant
|
|
34
|
+
read access only to the intended test table, using the platform's table-level RBAC.
|
|
35
|
+
|
|
36
|
+
The demo recorded in [the public resource inventory](../docs/demo-resources.json) reuses the Nedomkull workspace
|
|
37
|
+
in West Europe and adds only `LogAndOrderDemo_CL`, `dcr-logandorder-demo`,
|
|
38
|
+
its scoped publisher assignment, and the demo application. The table uses the
|
|
39
|
+
workspace's usage-based Analytics billing and 30-day retention; no existing
|
|
40
|
+
workspace quota or retention settings were changed.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
targetScope = 'resourceGroup'
|
|
2
|
+
|
|
3
|
+
@description('Existing workspace in this deployment resource group.')
|
|
4
|
+
param workspaceName string
|
|
5
|
+
|
|
6
|
+
@description('The existing workspace region; the DCR must use the same region.')
|
|
7
|
+
param location string
|
|
8
|
+
|
|
9
|
+
@description('Object ID of the app service principal, not the application/client ID.')
|
|
10
|
+
@minLength(36)
|
|
11
|
+
@maxLength(36)
|
|
12
|
+
param principalObjectId string
|
|
13
|
+
|
|
14
|
+
@description('New custom table name, including the _CL suffix. Existing tables are not migrated.')
|
|
15
|
+
param tableName string = 'LogAndOrder_CL'
|
|
16
|
+
|
|
17
|
+
@description('DCR resource name.')
|
|
18
|
+
param dcrName string = 'dcr-logandorder'
|
|
19
|
+
|
|
20
|
+
@description('Declared input stream; it need not equal the output table name.')
|
|
21
|
+
param inputStreamName string = 'Custom-LogAndOrder'
|
|
22
|
+
|
|
23
|
+
param tags object = {
|
|
24
|
+
application: 'LogAndOrder'
|
|
25
|
+
purpose: 'telemetry'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
resource workspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' existing = {
|
|
29
|
+
name: workspaceName
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var columns = [
|
|
33
|
+
{ name: 'TimeGenerated', type: 'datetime' }
|
|
34
|
+
{ name: 'level', type: 'string' }
|
|
35
|
+
{ name: 'message', type: 'string' }
|
|
36
|
+
{ name: 'properties', type: 'dynamic' }
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
resource table 'Microsoft.OperationalInsights/workspaces/tables@2022-10-01' = {
|
|
40
|
+
parent: workspace
|
|
41
|
+
name: tableName
|
|
42
|
+
properties: {
|
|
43
|
+
plan: 'Analytics'
|
|
44
|
+
retentionInDays: 30
|
|
45
|
+
totalRetentionInDays: 30
|
|
46
|
+
schema: {
|
|
47
|
+
name: tableName
|
|
48
|
+
columns: columns
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
resource rule 'Microsoft.Insights/dataCollectionRules@2023-03-11' = {
|
|
54
|
+
name: dcrName
|
|
55
|
+
location: location
|
|
56
|
+
kind: 'Direct'
|
|
57
|
+
tags: tags
|
|
58
|
+
properties: {
|
|
59
|
+
streamDeclarations: {
|
|
60
|
+
'${inputStreamName}': { columns: columns }
|
|
61
|
+
}
|
|
62
|
+
destinations: {
|
|
63
|
+
logAnalytics: [
|
|
64
|
+
{ name: 'workspace', workspaceResourceId: workspace.id }
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
dataFlows: [
|
|
68
|
+
{
|
|
69
|
+
streams: [inputStreamName]
|
|
70
|
+
destinations: ['workspace']
|
|
71
|
+
transformKql: 'source | project TimeGenerated, level, message, properties'
|
|
72
|
+
outputStream: 'Custom-${tableName}'
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
dependsOn: [table]
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
resource publisher 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
|
|
80
|
+
name: guid(rule.id, principalObjectId, 'Monitoring Metrics Publisher')
|
|
81
|
+
scope: rule
|
|
82
|
+
properties: {
|
|
83
|
+
principalId: principalObjectId
|
|
84
|
+
principalType: 'ServicePrincipal'
|
|
85
|
+
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '3913510d-42f4-4e42-8a64-420c390055eb')
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
output endpoint string = rule.properties.endpoints!.logsIngestion!
|
|
90
|
+
output dcrImmutableId string = rule.properties.immutableId!
|
|
91
|
+
output streamName string = inputStreamName
|
|
92
|
+
output tableResourceId string = table.id
|
|
93
|
+
output dcrResourceId string = rule.id
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Target supported ingestion without legacy compatibility
|
|
2
|
+
|
|
3
|
+
Neither library is in active use, so the migration may redesign the public interface and event contract around the Azure Monitor Logs Ingestion API without preserving the HTTP Data Collector API or adding compatibility shims. This avoids maintaining two authentication and ingestion paths for consumers that do not yet exist.
|
|
4
|
+
|
|
5
|
+
Recommend a new destination table alongside any existing classic table, with explicit field mappings and query and alert migration guidance. Document in-place migration as a deliberate operator choice because it is irreversible; provisioning must not silently migrate an existing table.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Use one event envelope across both libraries
|
|
2
|
+
|
|
3
|
+
Both libraries must produce the same event contract: TimeGenerated, level, message, and dynamic properties. Service context, language-specific source metadata, exception information, and custom extras belong inside properties rather than extending the top-level schema.
|
|
4
|
+
|
|
5
|
+
This replaces the separately proposed PowerShell and Python schemas so operators can query equivalent events consistently across languages. There are no active library consumers requiring preservation of the old field layouts; future changes to this shared contract must be coordinated between the repositories.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Authenticate app registrations with federation and an explicit secret fallback
|
|
2
|
+
|
|
3
|
+
Use an Entra app registration with OIDC workload-identity federation as the preferred authentication mode, and client-secret credentials as the explicit alternative for hosts without a renewable OIDC assertion source. The host supplies and refreshes the external assertion; the libraries exchange it for Monitor access rather than creating an issuer.
|
|
4
|
+
|
|
5
|
+
Keep authentication selection visible and fail configured OIDC errors without silently switching identities. Native managed-identity acquisition, native certificate credentials and sovereign-cloud presets are follow-up work, while Python callers may supply their own Azure credential. This avoids conflating the previously proposed managed-identity host protocols and matches the owner's selected app-registration deployment model.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Domain docs
|
|
2
|
+
|
|
3
|
+
## Before exploring
|
|
4
|
+
|
|
5
|
+
Read the root GLOSSARY.md and relevant decisions in docs/adr/.
|
|
6
|
+
|
|
7
|
+
If these are absent, proceed silently. The domain-modeling skill
|
|
8
|
+
creates them when terms or decisions are resolved.
|
|
9
|
+
|
|
10
|
+
## Layout
|
|
11
|
+
|
|
12
|
+
Use a single-context layout:
|
|
13
|
+
|
|
14
|
+
- GLOSSARY.md at the repository root
|
|
15
|
+
- docs/adr/ for architectural decision records
|
|
16
|
+
|
|
17
|
+
## Vocabulary
|
|
18
|
+
|
|
19
|
+
Use glossary terms in issue titles, proposals, hypotheses, and tests.
|
|
20
|
+
Note meaningful vocabulary gaps for domain-modeling.
|
|
21
|
+
|
|
22
|
+
## Decisions
|
|
23
|
+
|
|
24
|
+
If a proposal contradicts an ADR, identify the conflict and explain
|
|
25
|
+
why the decision should be reconsidered.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Issue tracker: GitHub
|
|
2
|
+
|
|
3
|
+
Issues and specs live in GitHub Issues for
|
|
4
|
+
Nedomkull-Mathematical-Modeling/PyLogAndOrder. Use the gh CLI.
|
|
5
|
+
|
|
6
|
+
## Operations
|
|
7
|
+
|
|
8
|
+
- Create: gh issue create --title "..." --body-file <file>
|
|
9
|
+
- Read: gh issue view <number> --json number,title,body,labels,comments
|
|
10
|
+
- List: gh issue list --state open --json number,title,body,labels
|
|
11
|
+
- Comment: gh issue comment <number> --body-file <file>
|
|
12
|
+
- Label: gh issue edit <number> --add-label "..."
|
|
13
|
+
- Remove label: gh issue edit <number> --remove-label "..."
|
|
14
|
+
- Close: gh issue close <number> --comment "..."
|
|
15
|
+
|
|
16
|
+
Run commands inside this clone so gh infers the repository.
|
|
17
|
+
Use UTF-8 files for multiline issue bodies and comments.
|
|
18
|
+
|
|
19
|
+
When a skill says "publish to the issue tracker", create an issue.
|
|
20
|
+
When it says "fetch the relevant ticket", read the issue.
|
|
21
|
+
|
|
22
|
+
## Pull requests as a triage surface
|
|
23
|
+
|
|
24
|
+
**PRs as a request surface: no.**
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Triage labels
|
|
2
|
+
|
|
3
|
+
| Role | Tracker label | Meaning |
|
|
4
|
+
| --- | --- | --- |
|
|
5
|
+
| needs-triage | needs-triage | Maintainer needs to evaluate |
|
|
6
|
+
| needs-info | needs-info | Waiting for reporter information |
|
|
7
|
+
| ready-for-agent | ready-for-agent | Fully specified for an autonomous agent |
|
|
8
|
+
| ready-for-human | ready-for-human | Requires human implementation |
|
|
9
|
+
| wontfix | wontfix | Will not be actioned |
|
|
10
|
+
|
|
11
|
+
When a skill mentions a triage role, use its tracker label.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"tenant_id": "c61696e5-1f46-4fe0-97b3-2d3f8ba98c57",
|
|
3
|
+
"subscription_id": "9cf8ab97-6d03-4f0c-b446-a670c976518b",
|
|
4
|
+
"resource_group": "DefaultResourceGroup-WEU",
|
|
5
|
+
"workspace_name": "DefaultWorkspace-9cf8ab97-6d03-4f0c-b446-a670c976518b-WEU",
|
|
6
|
+
"workspace_query_id": "9131792d-8d70-4e65-b7b9-0c4369e76478",
|
|
7
|
+
"location": "westeurope",
|
|
8
|
+
"table_name": "LogAndOrderDemo_CL",
|
|
9
|
+
"dcr_name": "dcr-logandorder-demo",
|
|
10
|
+
"endpoint": "https://dcr-logandorder-demo-rys1-westeurope.logs.z1.ingest.monitor.azure.com",
|
|
11
|
+
"dcr_immutable_id": "dcr-df20309a1b164552a7dd14f24f12cb84",
|
|
12
|
+
"stream_name": "Custom-LogAndOrderDemo",
|
|
13
|
+
"application_client_id": "4affe6a2-fc65-4b26-a52f-e71f311666f3",
|
|
14
|
+
"application_object_id": "4d533060-62d0-4af9-a9be-1661888c7b9e",
|
|
15
|
+
"service_principal_object_id": "03890e5c-ef5f-4951-864a-3900601386e2",
|
|
16
|
+
"demo_secret_expires_utc": "2026-12-08T20:07:17Z",
|
|
17
|
+
"existing_workspace_reused": true,
|
|
18
|
+
"query_executor_role_id": "d22759de-ac0a-43ca-8bfe-644a8c3b9628",
|
|
19
|
+
"query_executor_assignment_id": "8d006b36-9e02-4417-9bb7-c4321b182a13",
|
|
20
|
+
"demo_table_reader_assignment_id": "1bb3b0d2-55bb-4198-af47-9803fdf6be94",
|
|
21
|
+
"federated_credential_name": "github-logandorder-migration",
|
|
22
|
+
"federated_subject": "repo:Nedomkull-Mathematical-Modeling/LogAndOrder:ref:refs/heads/codex/logs-ingestion-migration",
|
|
23
|
+
"notes": "Identifiers only; no credentials. Owner approved DCR publishing, workspace query execution/metadata, Reader limited to the demo table, and branch-specific OIDC trust."
|
|
24
|
+
}
|