Decouple structured events from stdlib logging via explicit EventSink#37
Merged
Conversation
- New events module: EventSink protocol, Null/InMemory/Callback/Composite/ JSONL sinks, EventRuntime ambient run scope (default: null sink) - Events are OTel Logs Data Model shaped: time_unix_nano, severity_text/ number, event_name, body, trace_id/span_id/parent_span_id, attributes, resource stamped once on run start - span() end event is the canonical wide event; start events demoted to debug; error_type renamed to error.type (semconv) - observability_context() owns one run without touching stdlib handlers; cli_logging_handlers() attaches terminal + EventBridgeHandler to named package loggers only (never root, no handlers.clear()); cli_run_context() composes both with the JSONL sink for CLI entrypoints - EventBridgeHandler carries httpcore wire-debug mining, header secret redaction, and exc_info tracebacks into the event stream - HTTP run-summary counters renamed to http.client.* aligned names - HTTP metric reset moved into observability_context (per-run, not per-handler-config) - OTLP logs: logs provider configured when exporting; OtelLogsSink emits wide events through the OTel Logs API - Deleted: configure_logging root clearing, JSONLogFileHandler, _DropStructuredEvents, structured-record magic attrs Amp-Thread-ID: https://ampcode.com/threads/T-019eba67-c19d-7166-9690-dcb2f0eed165 Co-authored-by: Amp <amp@ampcode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements Track B (lib side) of the file-handling + observability redesign
(spec: src-auth-perms-sync dev/PLAN.md).
What changed
eventsmodule:EventSinkprotocol with Null/InMemory/Callback/Composite/JSONL sinks and an
EventRuntimeambient run scope (default:null sink — importing the library never writes anywhere).
time_unix_nano,severity_text/severity_number,event_name,body,trace_id/span_id/parent_span_id, nestedattributes,resourcestamped once per run.span-start events demoted to debug;
error_type→error.type(semconv).observability_context()owns one run withouttouching stdlib handlers.
cli_logging_handlers()attaches terminal +EventBridgeHandlerto named package loggers only — never the rootlogger, no
handlers.clear()(fixes host applications having theirlogging config destroyed on import).
cli_run_context()composes bothwith the JSONL sink for CLI entrypoints.
redaction, exc_info tracebacks (now in the bridge), log-file retention
pruning, resource sampler, run summaries.
http.client.*aligned names;metric reset moved into
observability_context(per-run correctness forlong-running hosts).
OtelLogsSinkemits wide events through the OTel Logs API.
configure_loggingroot clearing,JSONLogFileHandler,_DropStructuredEvents, structured-record magic attrs.Verification
uv run python -m unittest discover -s tests— 104 tests OKuv run pyright— 0 errors (strict, src + tests)uv run ruff check/format --check— cleansuite 102/102 and live e2e 119/120 against the sgdev test instance (the
one failure is the wheel smoke needing this release on PyPI).