简体中文 | English
matterloop-observability
MatterLoop 的事件是业务事实,不是日志字符串。matterloop-observability 把 Core LoopEvent
接到日志、指标和 Trace,同时把日志后端与 OpenTelemetry 的进程级配置留给宿主应用。
pip install matterloop-observability
# 需要 OpenTelemetry 时
pip install "matterloop-observability[otel]"
一次合理的装配
import logging
from matterloop_observability import (
CompositeEventPublisher,
HandlerEventPublisher,
MetricsHandler,
PublisherFailureMode,
Redactor,
StructuredLoggingHandler,
)
redactor = Redactor(extra_fields=("tenant_secret", "session_credential"))
metrics = MetricsHandler()
events = CompositeEventPublisher(
publishers=(
HandlerEventPublisher(
StructuredLoggingHandler(
logger=logging.getLogger("app.matterloop.audit"),
redactor=redactor,
)
),
HandlerEventPublisher(metrics),
),
failure_mode=PublisherFailureMode.RAISE,
)
将 events 注入 AgentLoop(events=...)。处理器按顺序执行;本包不创建后台队列,也不接管 Logger、
Exporter、Provider 或它们的关闭流程。
失败策略要显式选择
CompositeEventPublisher(publishers, failure_mode) 支持两种策略:
LOG_AND_CONTINUE是默认值,适合可丢失的遥测。单个发布器失败会记录异常,并继续发布后续事件。RAISE在第一个失败处停止,适合审计不可缺失的场景。代价是可观测性故障可能中断业务闭环。
如果要求“状态提交与审计记录同时成功”,顺序调用几个 Publisher 并不能提供事务保证。应使用 Outbox、持久化事件表或消息系统完成原子交接。
日志里有什么
StructuredLoggingHandler(logger, redactor) 输出单行 JSON,包含事件类型、run_id、Loop 状态、
发生时间、事件说明和请求 metadata。默认 Logger 名称是 matterloop.events;日志格式、轮转、
保留期和访问控制仍由应用配置。
Redactor(extra_fields) 会递归检查映射键,默认识别 token、authorization、cookie、
api_key、password 和 secret,也能命中 access_token 之类的前后缀名称。它不会扫描自由文本:
提示词、模型输出、URL 查询参数和异常堆栈里的秘密仍可能泄漏。不要把凭据放进 goal、detail
或任意字符串 metadata。
指标与 Trace
MetricsHandler保存当前进程内的事件计数,适合测试和轻量诊断。OpenTelemetryMetricsHandler写入matterloop.loop.events,只附带事件类型和 Loop 状态。TracingHandler为每个事件创建短 Span,不会自动构造覆盖整个 Loop 的父 Span。
OpenTelemetry 组件只使用 API。宿主必须先配置 SDK、Exporter、采样和资源属性;安装 extra 不等于
数据会被导出。构造时缺少 OpenTelemetry 依赖会立即抛出 RuntimeError。
扩展方式
同步或异步 callable 可用 HandlerEventPublisher(handler) 接入。需要批量、重试或背压时,直接实现
Core EventPublisher.publish(event),在实现内部管理有界队列和关闭流程。
本包当前面向 Core LoopEvent。TeamLoop 事件的数据结构不同,需要单独适配,不能把团队事件发布器
直接塞给这些处理器。生产拓扑和关闭顺序见企业集成指南。
Metadata
Release files for matterloop-observability 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| matterloop_observability-0.1.2.tar.gz | 18.1 kB | With provenance | Details for matterloop_observability-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| matterloop_observability-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for matterloop_observability-0.1.2-py3-none-any.whl |
Total release size: 36.2 kB
Release files / matterloop_observability-0.1.2.tar.gz
| Download URL | matterloop_observability-0.1.2.tar.gz |
|---|---|
| Size | 18.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
239544def1dc30fce5c11bba56e2430270d5f50066310712f1ca8ba0cef6854d
|
|
BLAKE2b-256 checksum How to use checksums |
aef8e18c71e8e3cf494fa5735c0491d2d13e71b5aef6a7f86737de90166db548
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 23, 2026.
Transparency logRelease files / matterloop_observability-0.1.2-py3-none-any.whl
| Download URL | matterloop_observability-0.1.2-py3-none-any.whl |
|---|---|
| Size | 18.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4c3ace2e1d08f68a25ed70a24a9940f9eb7780425895b1460710e7fcc1f0ef12
|
|
BLAKE2b-256 checksum How to use checksums |
70301c332e883752df30286c5550c1067b84d3c27931ad9d13e4246097cee08e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 23, 2026.
Transparency logSecurity for matterloop-observability 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for matterloop_observability-0.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.