Skip to content

Add privacy-minimized OpenTelemetry events - #37

Merged
Deathcharge merged 2 commits into
mainfrom
codex/opentelemetry-decision-events
Aug 2, 2026
Merged

Add privacy-minimized OpenTelemetry events#37
Deathcharge merged 2 commits into
mainfrom
codex/opentelemetry-decision-events

Conversation

@Deathcharge

Copy link
Copy Markdown
Owner

What changed

  • add an optional OpenTelemetryDecisionEventSink that emits a versioned samsarix.policy.decision event on the current recording span
  • restrict the event to policy/decision metadata and exclude tool inputs, actor/context data, policy condition data, messages, approvals, and callback results
  • add bounded ordered CompositeAuditSink fanout for pairing durable audit storage with trace correlation
  • pin the optional API and exact SDK contract at OpenTelemetry 1.44.0, with a real in-memory exporter integration test and no-network example
  • document sampling, partial delivery, export, privacy, and application ownership boundaries
  • require the OpenTelemetry contract job before main distribution attestation

Why

Operators need to correlate policy outcomes with existing agent and request traces without turning authorization telemetry into a second copy of sensitive tool payloads. The base package remains dependency-free, while applications opt into the API and continue to own their SDK/exporter configuration.

Impact

  • no change for base-package users
  • optional install: samsarix-agent-ethics[opentelemetry]
  • recording spans receive one metadata-only event per audited decision
  • non-recording spans intentionally no-op
  • synchronous telemetry API failures remain inside the existing fail-closed audit boundary
  • trace acceptance is not represented as durable delivery or export proof

Validation

  • 523 tests passed with 95.80% branch-aware coverage
  • real OpenTelemetry API/SDK 1.44.0 contract passed on Python 3.11
  • combined OpenAI Agents 0.18.3 + OpenTelemetry 1.44.0 built-wheel contracts passed on Python 3.11 and Python 3.14
  • Ruff format and lint passed
  • mypy passed
  • wheel/sdist build and Twine metadata checks passed
  • dependency-free wheel import and missing-extra error path verified

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Deathcharge, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 50 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2b82dbe7-61a2-4045-8f33-d8990932916e

📥 Commits

Reviewing files that changed from the base of the PR and between f5a25c0 and e90006c.

📒 Files selected for processing (4)
  • RELEASING.md
  • SECURITY.md
  • src/samsarix_ethics/otel.py
  • tests/test_otel.py

Summary by CodeRabbit

  • New Features

    • Added optional OpenTelemetry integration for metadata-only policy decision events on active traces.
    • Added ordered, bounded fan-out to multiple audit sinks with fail-fast delivery.
    • Added a no-network OpenTelemetry demonstration and public API exports.
  • Documentation

    • Added setup, usage, privacy, security, architecture, and operational guidance for telemetry and audit composition.
  • Tests

    • Added integration coverage for trace correlation, privacy protections, sink ordering, and failure handling.

Walkthrough

The package adds bounded ordered audit fan-out and an optional OpenTelemetry sink for metadata-only decision events. It also adds pinned integration validation, a no-network demo, public exports, and documentation for configuration, privacy, failure behavior, and release checks.

Changes

Audit and OpenTelemetry integration

Layer / File(s) Summary
Composite audit delivery
src/samsarix_ethics/audit.py, tests/test_otel.py
CompositeAuditSink validates 1–32 distinct synchronous sinks and delivers AuditRecord values in order with fail-fast handling.
OpenTelemetry decision events
src/samsarix_ethics/otel.py, tests/test_otel.py
OpenTelemetryDecisionEventSink validates the optional API, ignores non-recording spans, and emits versioned metadata-only events.
Integration contract and public wiring
pyproject.toml, requirements-opentelemetry.txt, src/samsarix_ethics/__init__.py, integration_tests/test_opentelemetry_sdk.py, examples/opentelemetry_decision_event_demo.py, .github/workflows/ci.yml, tests/test_public_api.py
The optional dependency is pinned to version 1.44.0. Public exports, SDK integration tests, the demo, and the CI contract job cover the new behavior.
Documentation and release evidence
README.md, docs/OPENTELEMETRY.md, docs/API.md, docs/ARCHITECTURE.md, docs/ADOPTION.md, SECURITY.md, RELEASING.md, CONTRIBUTING.md, ROADMAP.md, CHANGELOG.md, docs/PRODUCTIZATION.md
Documentation describes installation, attributes, privacy boundaries, ordered delivery, partial failures, caller-owned telemetry configuration, and release verification.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ToolGate
  participant OpenTelemetryDecisionEventSink
  participant CurrentSpan
  participant Exporter
  ToolGate->>OpenTelemetryDecisionEventSink: deliver AuditRecord
  OpenTelemetryDecisionEventSink->>CurrentSpan: add decision event
  CurrentSpan->>Exporter: export span when tracing shuts down
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding privacy-minimized OpenTelemetry events.
Description check ✅ Passed The description covers the change, rationale, impact, security boundaries, dependencies, API effects, and validation results in sufficient detail.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/opentelemetry-decision-events

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@RELEASING.md`:
- Around line 34-41: Update the release validation steps so the OpenAI Agents
and OpenTelemetry contracts run in separate environments, each installing
requirements-dev.lock with only its corresponding optional lock. Keep each
integration’s pytest and demo commands in its matching environment, rather than
installing both optional lock graphs together.

In `@SECURITY.md`:
- Around line 44-50: Update the OpenTelemetry metadata statement in SECURITY.md
to clarify that the sink emits versioned event attributes derived from
AuditRecord, along with the event version and record version attributes.
Preserve the surrounding ownership, export, and durability guidance.

In `@src/samsarix_ethics/otel.py`:
- Around line 19-20: Update OpenTelemetryIntegrationError to inherit from
AuditLogError instead of SamsarixEthicsError, preserving its existing diagnostic
messages through _deliver_audit_record() and the ToolGate execution paths.

In `@tests/test_otel.py`:
- Around line 105-133: Add an assertion in
test_opentelemetry_sink_validates_dependency_and_api_shape using monkeypatched
import_module returning SimpleNamespace() without get_current_span, then
construct OpenTelemetryDecisionEventSink and assert
OpenTelemetryIntegrationError with the existing \[opentelemetry\]
install-guidance match. Keep the existing missing-import and non-callable API
cases unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: dc2de88f-57e5-4e23-a533-5e097c52d4e2

📥 Commits

Reviewing files that changed from the base of the PR and between 28b7f2c and f5a25c0.

⛔ Files ignored due to path filters (1)
  • requirements-opentelemetry.lock is excluded by !**/*.lock
📒 Files selected for processing (21)
  • .github/workflows/ci.yml
  • CHANGELOG.md
  • CONTRIBUTING.md
  • README.md
  • RELEASING.md
  • ROADMAP.md
  • SECURITY.md
  • docs/ADOPTION.md
  • docs/API.md
  • docs/ARCHITECTURE.md
  • docs/OPENTELEMETRY.md
  • docs/PRODUCTIZATION.md
  • examples/opentelemetry_decision_event_demo.py
  • integration_tests/test_opentelemetry_sdk.py
  • pyproject.toml
  • requirements-opentelemetry.txt
  • src/samsarix_ethics/__init__.py
  • src/samsarix_ethics/audit.py
  • src/samsarix_ethics/otel.py
  • tests/test_otel.py
  • tests/test_public_api.py

Comment thread RELEASING.md
Comment thread SECURITY.md
Comment thread src/samsarix_ethics/otel.py Outdated
Comment thread tests/test_otel.py
@Deathcharge
Deathcharge merged commit 8e88fe5 into main Aug 2, 2026
8 checks passed
@Deathcharge
Deathcharge deleted the codex/opentelemetry-decision-events branch August 2, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant