Skip to content

Add custom resource attributes and span links to OtelTraceSink#476

Open
bmdhodl wants to merge 3 commits into
mainfrom
feat/otel-sink-attrs-links
Open

Add custom resource attributes and span links to OtelTraceSink#476
bmdhodl wants to merge 3 commits into
mainfrom
feat/otel-sink-attrs-links

Conversation

@bmdhodl
Copy link
Copy Markdown
Owner

@bmdhodl bmdhodl commented May 16, 2026

Summary

  • This is the narrow Later-bucket sink improvement, not the full exporter module. Per the processed decision Request (2026-05-15-0010-blocked-decision-agent47-otel-exporter-direction), no new agentguard47.exporters.otel module, no new OTel dependencies, no observability repositioning.
  • OtelTraceSink.__init__ gains an optional resource_attributes dict — entries are coerced to strings and stamped as agentguard.resource.* on every span the sink emits.
  • Span-start events may carry a links list of {"span_id", "attributes"} entries referencing already-tracked spans; these become OTel Link objects. Unknown/malformed entries are skipped.
  • Both new behaviors default to off — fully backward compatible.

Test plan

  • pytest tests/test_otel_sink.py — 19 passed (9 original unchanged + 10 new)
  • pytest tests/ — 750 passed, no regressions
  • ruff check agentguard/sinks/otel.py — clean
  • New tests cover: resource attrs stamped on every span, non-string coercion, no-attrs default, link to tracked span, link to unknown span skipped, multiple links, no-links default, malformed link entries skipped

Artifacts

WORK_PLAN.md, RESEARCH.md, QA_REPORT.md committed at repo root. QA verdict: PASS — no secrets, no denylist paths, no coverage regression.

Risk

Low. Additive, opt-in, no new dependency; core SDK stays zero-dep. Diff ~297 lines.

Narrow Later-bucket sink improvement: enhance the existing OtelTraceSink
without a new exporter module or new dependency.

- resource_attributes constructor arg stamps agentguard.resource.* on
  every emitted span; values coerced to strings
- span-start events may carry a links list referencing tracked spans,
  converted to OTel Link objects; unknown/malformed entries skipped
- backward compatible: both new behaviors default to off
- 10 new tests; full suite 750 passing

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 16, 2026 05:21
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b5b0971a24

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sdk/agentguard/sinks/otel.py Outdated
_build_links called .items() on a link entry's attributes field without
checking it was a mapping; a string/list value raised AttributeError and
aborted emit(). Coerce non-dict attributes to {} before iterating.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a narrow OtelTraceSink enhancement for opt-in per-span resource-style attributes and OTel span links while keeping the SDK dependency boundary unchanged.

Changes:

  • Adds resource_attributes support to OtelTraceSink.
  • Converts span-start links entries into OTel Link objects for tracked spans.
  • Adds mock-based tests and root planning/research/QA artifacts.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
sdk/agentguard/sinks/otel.py Implements resource attribute stamping and span-link construction.
sdk/tests/test_otel_sink.py Extends fake OTel types and adds tests for resource attributes and links.
WORK_PLAN.md Documents intended scope, approach, and completion checklist.
RESEARCH.md Records implementation research and test evidence.
QA_REPORT.md Summarizes QA checks and claimed readiness.
Comments suppressed due to low confidence (2)

RESEARCH.md:15

  • This cites sdk/pyproject.toml:74 as a Ruff exclusion, but that line is the setuptools package-find exclude, not Ruff configuration. Ruff only ignores a few rules per file for tests/**; the tests are omitted because the project lint command targets sdk/agentguard/ and selected scripts, so this evidence is inaccurate as written.
- Ruff config (`sdk/pyproject.toml:74`) excludes `tests*` and `examples*`, so
  the 4 pre-existing F401 unused-import warnings in `test_otel_sink.py` are not
  CI-checked and are out of scope for this task. The production file
  `agentguard/sinks/otel.py` passes `ruff check` cleanly.

QA_REPORT.md:29

  • This repeats the inaccurate claim that Ruff config excludes tests*. The cited exclusion is package metadata, while Ruff would still check tests if invoked on them (apart from the listed per-file ignored rules); the reason CI/local lint skips these imports is the lint command's target set, not Ruff configuration.
- Pre-existing ruff F401 unused imports in `test_otel_sink.py` (`call`,
  `MagicMock`, `patch`, `sys`) were left untouched — out of scope, and ruff
  config excludes `tests*` so CI does not check them. Production file
  `otel.py` passes `ruff check` cleanly.

Comment thread sdk/agentguard/sinks/otel.py
Comment thread sdk/agentguard/sinks/otel.py
Comment thread RESEARCH.md Outdated
Comment thread sdk/tests/test_otel_sink.py
Comment thread QA_REPORT.md Outdated
Comment thread WORK_PLAN.md Outdated
@bmdhodl bmdhodl added the needs:patrick-review Requires Patrick personal review label May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:patrick-review Requires Patrick personal review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants