wayscribe 0.2.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.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,6 @@
1
+ # The tests need helpers and the repository's conformance fixtures, which an
2
+ # sdist cannot carry, so the sdist ships the package alone. Run the tests from
3
+ # the repository: pnpm test:python.
4
+ prune tests
5
+ prune scripts
6
+ global-exclude __pycache__ *.py[cod]
wayscribe-0.2.0/NOTICE ADDED
@@ -0,0 +1,8 @@
1
+ Wayscribe
2
+ Copyright 2026 Jorge Polanco
3
+
4
+ This product includes software developed as part of the Wayscribe
5
+ project (https://gitlab.com/jojithedev/wayscribe).
6
+
7
+ Licensed under the Apache License, Version 2.0. You may obtain a copy of
8
+ the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -0,0 +1,378 @@
1
+ Metadata-Version: 2.4
2
+ Name: wayscribe
3
+ Version: 0.2.0
4
+ Summary: Native Python recorder for Wayscribe record-level debugging
5
+ Author: Jorge Polanco
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://wayscribe.dev
8
+ Project-URL: Source, https://gitlab.com/jojithedev/wayscribe
9
+ Project-URL: Documentation, https://gitlab.com/jojithedev/wayscribe/-/blob/main/packages/sdk-python/README.md
10
+ Project-URL: Changelog, https://gitlab.com/jojithedev/wayscribe/-/blob/main/CHANGELOG.md
11
+ Project-URL: Issues, https://gitlab.com/jojithedev/wayscribe/-/issues
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.11
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ License-File: NOTICE
23
+ Dynamic: license-file
24
+
25
+ # Wayscribe Python SDK
26
+
27
+ Distribution: `wayscribe`. Import: `wayscribe`. Version: `0.2.0`.
28
+ Python 3.11 or newer is required. Runtime code uses only the standard library;
29
+ setuptools is a build dependency only.
30
+
31
+ ```sh
32
+ python3 -m pip install wayscribe
33
+ ```
34
+
35
+ Each release file on PyPI carries a publish attestation: PyPI verified that it
36
+ was uploaded by this repository's GitLab CI release job, with no long-lived
37
+ upload token involved. The recorder works with the published Wayscribe API
38
+ from `v0.1.0` onward.
39
+
40
+ The controlled
41
+ [`examples/mixed-language`](https://gitlab.com/jojithedev/wayscribe/-/blob/main/examples/mixed-language/README.md)
42
+ workflow installs a wheel built from this checkout and continues one real
43
+ journey from Node through Python to the Go SDK. To build and install that
44
+ wheel from the repository root:
45
+
46
+ ```sh
47
+ uv build --out-dir packages/sdk-python/dist packages/sdk-python
48
+ python3 -m pip install --no-deps packages/sdk-python/dist/wayscribe-0.2.0-py3-none-any.whl
49
+ ```
50
+
51
+ The distribution and import name are both `wayscribe`.
52
+
53
+ The recorder captures events synchronously and delivers immutable, redacted bytes
54
+ from one bounded daemon sender. Record calls never wait for network work.
55
+
56
+ ```python
57
+ from wayscribe import create_recorder
58
+
59
+ payload = {"invoice_id": "inv_42", "amount": 10}
60
+ with create_recorder(
61
+ endpoint="http://localhost:8080", api_key="provided-by-the-host",
62
+ service="billing-worker", environment="development",
63
+ ) as recorder:
64
+ journey = recorder.journey({"type": "invoice", "id": "inv_42"}, label="Invoice sync")
65
+ journey.identify({"external_invoice": "external_42"})
66
+ result = journey.transform("normalize", payload, lambda: {**payload, "amount": 1000})
67
+ journey.record(operation="persisted", name="write-invoice", output=result)
68
+ journey.complete()
69
+
70
+ print(recorder.counters())
71
+ ```
72
+
73
+ Use an ingestion API key for the configured project and environment. The example
74
+ requires a local Wayscribe server and a real key to store events; an unavailable
75
+ server never raises a recorder transport error into the host.
76
+
77
+ ```python
78
+ from wayscribe import inject_http_headers, extract_http_context
79
+
80
+ context = {"journeyId": "jrn_example", "entity": {"type": "order", "id": "42"}}
81
+ headers = inject_http_headers(context, {"content-type": "application/json"})
82
+ # Default: journey and entity type only. No aliases or entity identifier.
83
+ assert extract_http_context(headers) == {"journeyId": "jrn_example"}
84
+ ```
85
+
86
+ The HTTP, SQS and payload helpers follow `docs/PROPAGATION_SPEC.md` and run all
87
+ committed carrier vectors. Injection accepts `level="journey-only"`,
88
+ `"journey-and-type"` (default), or `"full"`. The latter explicitly opts in to
89
+ propagating a usable entity identifier. `traceparent` is preserved and never
90
+ written. `extract_payload` returns `{"context": context_or_none, "data": value}`.
91
+ `has_journey` is a nonthrowing structural check; use extraction for validation.
92
+ A missing `data` property in a recognized envelope becomes `None` in Python.
93
+
94
+ Carriers have no environment field. Receiving recorders must use their own
95
+ configured environment. After `journey_environment_mismatch`, the application
96
+ must begin a new journey in the receiving environment.
97
+
98
+ Timing helpers accept mappings or objects with explicit snake_case fields:
99
+
100
+ ```python
101
+ from wayscribe import queue_metadata, http_metadata
102
+
103
+ metadata = queue_metadata(
104
+ {
105
+ "queue_name": "orders",
106
+ "id": "42",
107
+ "timestamp": 1000,
108
+ "processed_on": 1300,
109
+ "attempts_made": 0,
110
+ },
111
+ delivery_count=1,
112
+ )
113
+ assert metadata["queueWaitMs"] == 300
114
+
115
+ response_metadata = http_metadata(
116
+ {"status": 429, "headers": {"retry-after": "2"}},
117
+ target_url="https://api.example.com/orders/42",
118
+ )
119
+ assert response_metadata["targetHost"] == "api.example.com"
120
+ ```
121
+
122
+ A retry needs `ready_again_at` in epoch milliseconds; the original enqueue time
123
+ is never substituted. Unknown or invalid measurements are omitted, measured zero
124
+ is retained, and a delivery count above one prevents initial-enqueue wait.
125
+ `http_metadata(..., now=epoch_ms)` makes HTTP-date Retry-After deterministic;
126
+ omitting `now` uses the observation time. Numeric Retry-After needs no clock.
127
+ Only the URL host (and a nondefault port) is kept.
128
+
129
+ Capture is synchronous and detached. Built-in secret names apply at every depth
130
+ and in header shapes. Custom paths supplement built-ins in `redacted-payload`;
131
+ `full-payload` retains built-ins and omits custom paths. `metadata-only` omits input
132
+ and output while still redacting metadata. Capture repairs cycles, nonfinite
133
+ numbers, NUL and unpaired surrogates. Shared references expand independently.
134
+ Integers outside ±(2^53−1) are decimal strings. Bytes/bytearray become
135
+ `{"type": "bytes", "base64": "..."}`. Dates become UTC midnight; naive datetimes
136
+ are interpreted as UTC, and aware datetimes are converted to UTC. Strings are
137
+ bounded in UTF-16 units, protocol identifiers and labels in Unicode code points.
138
+ Unsupported objects become `[UNCAPTURABLE]`; arbitrary attributes are not explored.
139
+ Rendered byte objects obey the same depth and string limits as supplied objects;
140
+ their base64 strings may carry a truncation marker. A decimal integer string that
141
+ exceeds the string limit causes payload omission so retained integers keep every digit.
142
+
143
+ Labels and displayable aliases are stored, shown and searched in plain text.
144
+ Do not put personal data or credentials in them. Narrow email/telephone shape
145
+ warnings do not alter these values and cannot recognize every kind of personal
146
+ data. Each statement of a displayable alias must list its type again; the server
147
+ keeps it displayable only while every statement does so. Error messages are
148
+ credential-masked and bounded; stacks are never automatically collected.
149
+
150
+ Configuration comes explicitly from the host, never ambient environment
151
+ variables. Required fields are `endpoint`, `api_key`, `service`, `environment`.
152
+ Invalid required settings disable event admission; rejected optional settings use
153
+ defaults or documented clamps and are available separately from call-time reports.
154
+ `deployment` accepts `git_commit`, `version`, `image`, detached at resolution.
155
+ `redact` and `known_safe_names` accept at most 1,000 strings. The initial sender
156
+ concurrency is fixed at one; passing `max_concurrent_sends` is reported as rejected.
157
+ Delivery defaults and bounds are documented below.
158
+ The envelope budget is capped at the protocol maximum of 262,144 bytes.
159
+
160
+ `on_diagnostic` receives the Node SDK's report shape and names:
161
+ `{"kind", "code", "reason", "detail"}`, for example
162
+ `{"kind": "breaker_opened", "code": "consecutive_failures", "reason": "...",
163
+ "detail": {"failures": 5, "cooldownMs": 30000}}`. Match on `kind` and `code`;
164
+ `reason` is a sentence whose wording may change. The kinds are `delivered_first`
165
+ (once per recorder, after the first batch the server stored anything from),
166
+ `insecure_endpoint`, `transport_error`, `breaker_opened`, `dropped`,
167
+ `payload_omitted`, `payload_truncated`, `key_dropped`, `capture_error`,
168
+ `configuration_error`, `unredacted_secret_name` and
169
+ `personal_data_in_public_value`; `docs/SDK_SPEC.md` lists where Python still
170
+ differs from Node. A report raised by the sender thread (`delivered_first`,
171
+ `transport_error`, `breaker_opened`) is handed to the callback on a separate
172
+ daemon thread, so a slow callback never holds up delivery; `flush()` and
173
+ `shutdown()` wait for those callbacks within their own deadline. Every other
174
+ report runs the callback on the calling thread before the call returns, as in
175
+ Node. Keep the callback short either way.
176
+
177
+ Diagnostics never print payloads, credentials, endpoint paths or queries, or
178
+ exception messages. Debug logging is opt-in. A missing required setting, a
179
+ missing or short derivation secret, public personal-data shapes and unredacted
180
+ secret names have bounded process-wide warnings. An unredacted-secret report
181
+ names the field, the key as written (at most 128 characters) and its path with
182
+ every index written `[*]` (`input.lines[*].authToken`, `input[*].apiToken`; at
183
+ most 256 characters), never its value, and so does its printed line, with
184
+ credential shapes masked, so the name can be covered by a rule or marked
185
+ known-safe. At most 100 names are reported per recorder, once per folded name,
186
+ with one printed warning per process and folded name across fields and
187
+ spellings, or every report when `log_diagnostics` is on. Personal-data callbacks
188
+ and printing occur once per process, field and shape. A fork resets the
189
+ process-wide warning state and its lock so a child recorder can report safely.
190
+
191
+ For development, run from the repository root:
192
+
193
+ ```sh
194
+ pnpm test:python
195
+ pnpm test:python:conformance
196
+ ```
197
+
198
+ The recorder passes all 35 applicable SDK fixtures; the two throwing-property
199
+ fixtures are explicitly Node-only. Its captured request bytes are replayed
200
+ unchanged through the real local API dry run, and a clean wheel installation is
201
+ tested outside the source checkout. The example in `examples/python-worker`
202
+ exercises a queryable journey through the real API. These local checks do not
203
+ publish the package, and the separate Leadline pilot remains open.
204
+
205
+ ## Recorder and journey API
206
+
207
+ `create_recorder(**options)` and `Recorder(**options)` create the same recorder.
208
+ `journey(entity, journey_id=None, label=None)` copies the entity identity;
209
+ `for_entity(entity, label=None)` derives the journey using the configured
210
+ `journey_id_secret` (at least 32 UTF-8 bytes). A missing/invalid secret warns and
211
+ uses a fresh unpredictable ID. Identity arguments after `entity` are keyword-only.
212
+ `resume(context, entity=...)` uses the receiver's authoritative entity and its own
213
+ configured environment. It continues only a journey ID valid for both propagation
214
+ and the event protocol. Carrier parsing accepts up to 256 characters, but events
215
+ accept 128: a longer resumed ID is diagnosed and replaced with a fresh ID. An
216
+ explicit `journey_id` passed to `journey` is not silently replaced; invalid required
217
+ event identity is refused without incrementing delivery counters.
218
+
219
+ A journey supports `context()` (a detached mapping), `label(value)` (records
220
+ nothing), `record(operation=..., name=..., **event_fields)`,
221
+ `identify(aliases, displayable_aliases=())`, `fail(name, error)`, and
222
+ `complete(name="complete")`. Event keyword fields use snake_case:
223
+ `input`, `output`, `metadata`, `timestamp`, `duration_ms`, `attempt`, `error`,
224
+ `parent_event_id`, `trace_id`, `span_id`, `message_id`, `correlation_id`,
225
+ `journey_label`, `aliases`, `displayable_aliases`. `timestamp` is an ISO timestamp
226
+ with an explicit time zone. Omitted payloads are absent; explicit `None` is JSON
227
+ null. Pass trace/span IDs explicitly; no OpenTelemetry installation is needed.
228
+
229
+ `transform`, `persist`, `publish`, `consume`, `deliver`, and `validate` each accept
230
+ `(name, input, callback, **options)`. The callback takes no arguments and executes
231
+ once. A synchronous result returns synchronously; an awaitable result returns an
232
+ awaitable wrapper. Returned/resolved values, exception objects and cancellation
233
+ are preserved. Input and static metadata/aliases are captured before the callback
234
+ can mutate them. The event uses the start timestamp and whole elapsed milliseconds.
235
+ An explicit `attempt > 1` changes the operation to `retried`; a failed attempt
236
+ carries its own error, and `fail` is for terminal journey/branch failures.
237
+
238
+ Wrapper options include event fields plus:
239
+
240
+ - `capture_input(value)` and `capture_output(value)` project the captured view.
241
+ They may also accept a second `context` argument. They run synchronously;
242
+ exceptions or awaitable results produce `[UNCAPTURABLE]` and a safe diagnostic.
243
+ Output projections run only when the callback returns/resolves.
244
+ - `is_failure(result)` classifies a returned result once. A truthy value marks
245
+ failure; a string supplies the message, or a mapping supplies `message` and/or
246
+ `code`. Other truthy values use a generic message and `result_failed` code.
247
+ A failed classifier leaves the host's result unchanged and reports safely.
248
+ - `metadata_from(result[, context])` returns synchronous metadata, merged over
249
+ the static snapshot. Explicit `attempt` remains authoritative. For example,
250
+ `metadata_from=lambda response: http_metadata(response, target_url=url)` records
251
+ HTTP evidence without storing a URL path. A failed projection keeps static data.
252
+ - `queue_job=job`, `ready_again_at=epoch_ms`, `delivery_count=n` add the evidence
253
+ from `queue_metadata`. Pass the wrapper's `attempt` explicitly when retrying.
254
+
255
+ `recorder.across([journey_a, journey_b, journey_a])` exposes the operation methods,
256
+ including `record`, wrappers, `fail` and `complete`. It deduplicates by journey ID,
257
+ executes a wrapped callback once, and emits separate event IDs sharing timestamp
258
+ and duration. Context-aware projections run once for each distinct journey.
259
+ Journeys must belong to that recorder. Groups have no label/identify/context method.
260
+
261
+ ```python
262
+ import asyncio
263
+ from wayscribe import create_recorder
264
+
265
+ async def main():
266
+ async with create_recorder(
267
+ endpoint="http://localhost:8080", api_key="provided-by-the-host",
268
+ service="async-worker", environment="development",
269
+ ) as recorder:
270
+ journey = recorder.journey({"type": "invoice", "id": "inv_42"})
271
+ async def work():
272
+ await asyncio.sleep(0)
273
+ return {"ok": True}
274
+ result = await journey.deliver("send", {}, work)
275
+ assert result["ok"]
276
+ await recorder.async_flush(timeout_ms=1000)
277
+
278
+ asyncio.run(main())
279
+ ```
280
+
281
+ ## Delivery and lifecycle
282
+
283
+ The configurable delivery bounds are `batch_size=50` (clamped to 1–100),
284
+ `flush_interval_ms=1000`, `request_timeout_ms=1500`,
285
+ `max_buffered_events=1000`, and `max_event_bytes=262144` (capped at 262144).
286
+ The queue is bounded separately from the single in-flight batch (at most 100).
287
+ Overflow discards the oldest pending event. Retries retain their original queue
288
+ age and byte-identical envelopes. Transport uses the batch route, verified TLS for
289
+ HTTPS, a 1 MiB response-body limit, and no ambient proxy credentials. As the
290
+ Node SDK's `fetch` does, a 307 or 308 is followed, up to 20 times, with the same
291
+ body, and the API key is not sent to a different origin; any other 3xx is a
292
+ failed attempt and is retried. A 2xx body over 1 MiB cannot hold the verdicts
293
+ for 100 events and is read as a reply with no verdict (`no_verdict`), which is
294
+ what Node makes of a body it cannot parse.
295
+ Use HTTPS outside a trusted local development setup.
296
+
297
+ Fixed retry defaults are three HTTP attempts per logical send, full-jitter
298
+ exponential backoff (100 ms base, 2000 ms cap), and a breaker opening after five
299
+ failed logical sends for 30 seconds. Transient per-event refusals retain an
300
+ independent 30-second budget from the first refusal or ten logical sends, whichever
301
+ comes first. Ten logical sends can contain up to 30 HTTP attempts. Expired events
302
+ are dropped before another attempt, including after backoff or breaker cooldown.
303
+ Accepted events reset the breaker; whole-request 4xx is permanent and leaves the
304
+ breaker count unchanged. Verdicts are matched by position, not response event ID.
305
+ Unknown/missing/malformed successful verdicts drop once as `no_verdict`.
306
+
307
+ `flush(timeout_ms=5000)` and `shutdown(timeout_ms=5000)` return whether queued work
308
+ finished within the deadline. Finished means terminal accounting: consult counters
309
+ to distinguish sent events, permanent refusals and drops. A flush timeout leaves
310
+ pending work available for later delivery. Shutdown stops admission and drains until
311
+ empty, a pass makes no progress, or the deadline expires. It aborts active sockets
312
+ and counts every remaining event exactly once. Repeated shutdown returns its first
313
+ result. Valid records attempted after shutdown count as recorded and dropped with
314
+ cause `after_shutdown`; invalid calls are not admitted. Final delivery counts obey
315
+ `recorded == sent + rejected + dropped` and drop causes sum to `dropped`.
316
+
317
+ `async_flush` and `async_shutdown` await the same sender without blocking the event
318
+ loop or creating executor threads. Cancelling async shutdown finalizes remaining
319
+ work and propagates cancellation. Sync and async context managers call shutdown and
320
+ never suppress an exception from the context body. Background delivery cannot keep
321
+ the host process alive. A DNS/connect operation that the OS cannot cancel may finish
322
+ later in the daemon, but cannot write an HTTP request after cancellation or change
323
+ final counters. Shutdown cannot retract bytes sent earlier; the server can still
324
+ store an earlier in-flight request after the caller's deadline.
325
+
326
+ A recorder created before `fork()` (gunicorn `--preload`, Celery prefork,
327
+ `multiprocessing` with the fork start method) keeps working in the child. The
328
+ child's copy gets fresh locks, an empty queue, zero counters and its own sender
329
+ without acquiring anything it inherited, so a parent thread that held a lock
330
+ at the fork cannot block it. Events queued before the fork belong to the parent
331
+ and are never resent by a child; the child never closes the parent's socket. A
332
+ recorder shut down before the fork stays shut down in the child. Use detached
333
+ `counters()` and `rejected_settings()` for health checks; diagnostics callbacks
334
+ may safely reenter the recorder and must themselves remain short-running.
335
+
336
+ The sender thread starts with the first recorded event, so a recorder that never
337
+ records has no thread. A recorder dropped without `shutdown()` does not keep its
338
+ thread: once its queue is empty the thread ends within about a second of the
339
+ recorder being garbage-collected.
340
+
341
+ At interpreter exit, an `atexit` handler flushes what is still queued, with one
342
+ 1,000 ms deadline shared by every recorder in the process, so exit is never held
343
+ longer than that. It flushes and does not shut down; call `shutdown()` yourself
344
+ for a longer drain or exact final counts. `os._exit()`, a killed process and a
345
+ forked child that ends with `os._exit()` skip it, and their queued events are
346
+ lost.
347
+
348
+ ## Check your installed recorder
349
+
350
+ [CLI `check`](https://gitlab.com/jojithedev/wayscribe/-/blob/main/packages/cli/README.md#check-ingestion-and-preview-stored-events) exercises
351
+ explicit protocol/key/server configuration through a dry run. It does not inspect
352
+ an installed Python SDK. This separate synthetic public-SDK probe **stores an
353
+ event** in the configured environment:
354
+
355
+ ```python
356
+ import os
357
+ from wayscribe import create_recorder
358
+
359
+ with create_recorder(
360
+ endpoint=os.environ["WAYSCRIBE_URL"],
361
+ api_key=os.environ["WAYSCRIBE_API_KEY"],
362
+ service="python-sdk-check",
363
+ environment=os.environ["WAYSCRIBE_ENVIRONMENT"],
364
+ on_diagnostic=lambda d: print({"kind": d["kind"], "code": d["code"]}),
365
+ ) as recorder:
366
+ recorder.journey({"type": "sdk-check", "id": "synthetic-python"}).record(
367
+ operation="received", name="sdk-check"
368
+ )
369
+ drained = recorder.flush(timeout_ms=5000)
370
+ counters = recorder.counters()
371
+ print({"drained": drained, **{name: counters[name] for name in
372
+ ("recorded", "sent", "rejected", "dropped", "configuration_errors")}})
373
+ ```
374
+
375
+ Flush completion includes rejected/dropped work. Inspect delivery counters after
376
+ recording; an idle recorder's zero counters do not prove connectivity. The
377
+ context manager shuts down the recorder. Log diagnostic kind/code, not payloads,
378
+ keys or caller-written details.