feat: add span-level access for traces#2
Conversation
Add ScopeSpans and Span types with iterators and field accessors to extract TraceID, SpanID, and ParentSpanID directly from raw protobuf bytes, avoiding full pdata unmarshal. Resolves E-1467 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdds wire-format iterators and types for OTLP traces (ScopeSpans, Span) plus fixed-size byte extractors (TraceID, SpanID, ParentSpanID) to access span identifiers and nested spans without full unmarshaling; includes tests and benchmarks validating traversal and error cases. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@otlpwire.go`:
- Around line 552-586: The function extractFixedBytesField currently ignores
cases where the tag number matches fieldNum but the wireType is not
protowire.BytesType, treating the field as absent; update extractFixedBytesField
so that when num == fieldNum and wireType != protowire.BytesType it returns a
clear error (e.g., "wrong wire type for field") instead of skipping, leaving all
other behavior (proto3 zero-value handling, size check, skipping other fields
via skipField) unchanged.
Match the existing pattern from extractResourceMessage: when the field number matches but the wire type is not BytesType, return an error instead of silently skipping. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@otlpwire.go`:
- Around line 165-214: The helpers used by ResourceSpans.ScopeSpans,
ScopeSpans.Spans and ScopeSpans.SpanCount (e.g. forEachRepeatedField and
countOccurrences) currently ignore fields when num == fieldNum but wireType !=
BytesType, which hides malformed data; update those helper functions to return a
clear error when a matching field number has a non-BytesType wire type
(consistent with extractResourceMessage behavior), then propagate that error
back into the iterator error slot (iterErr) in ScopeSpans() and Spans() and
return it from SpanCount() so callers see wrong-wire-type errors instead of
silently skipping the field.
- Around line 30-35: Update the project documentation to include the new public
API types and accessors: add README.md sections describing the ScopeSpans and
Span types, their purpose (raw wire bytes), and document how to use their field
accessors TraceID, SpanID, ParentSpanID and the existing SpanCount() with short
usage examples showing how to obtain and read those fields; also add or update
CLAUDE.md per repository guidelines to mention these additions and any
contribution/CLA instructions. Ensure the docs reference the exact symbols
ScopeSpans, Span, TraceID, SpanID, ParentSpanID, and SpanCount() so users can
find and use the new API.
| // ScopeSpans represents a single ScopeSpans message (raw wire bytes). | ||
| type ScopeSpans []byte | ||
|
|
||
| // Span represents a single Span message (raw wire bytes). | ||
| type Span []byte | ||
|
|
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify commit message format (conventional commits)
echo "=== Recent Commits ==="
git log --oneline --decorate -n 20
echo -e "\n=== Checking README.md for new API mentions ==="
rg -n "ScopeSpans|Span\.TraceID|Span\.SpanID|Span\.ParentSpanID|SpanCount\(" README.md 2>/dev/null || echo "Not found in README.md"
echo -e "\n=== Checking CLAUDE.md for new API mentions ==="
rg -n "ScopeSpans|Span\.TraceID|Span\.SpanID|Span\.ParentSpanID|SpanCount\(" CLAUDE.md 2>/dev/null || echo "Not found in CLAUDE.md"
echo -e "\n=== Checking if docs files exist ==="
ls -la README.md CLAUDE.md 2>&1 || echo "One or both doc files missing"Repository: ollygarden/otlp-wire
Length of output: 665
Update documentation to cover new public API types and field accessors.
Commit format follows conventional commits (✓). However, README.md does not document the new public types (ScopeSpans, Span) or their field accessors (TraceID, SpanID, ParentSpanID); only SpanCount() is mentioned. Additionally, CLAUDE.md is missing and should be created or updated per coding guidelines requiring documentation files to be up to date.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@otlpwire.go` around lines 30 - 35, Update the project documentation to
include the new public API types and accessors: add README.md sections
describing the ScopeSpans and Span types, their purpose (raw wire bytes), and
document how to use their field accessors TraceID, SpanID, ParentSpanID and the
existing SpanCount() with short usage examples showing how to obtain and read
those fields; also add or update CLAUDE.md per repository guidelines to mention
these additions and any contribution/CLA instructions. Ensure the docs reference
the exact symbols ScopeSpans, Span, TraceID, SpanID, ParentSpanID, and
SpanCount() so users can find and use the new API.
Add wrong-wire-type checks to countRepeatedField, countOccurrences, and forEachRepeatedField, consistent with extractResourceMessage and extractFixedBytesField. Update README with new span-level API types, methods, and usage example. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@README.md`:
- Around line 151-167: The repo is missing CLAUDE.md to cover the new API
surface introduced (ResourceSpans.ScopeSpans, type ScopeSpans and methods
ScopeSpans.SpanCount/Spans, and type Span with TraceID/SpanID/ParentSpanID);
either add a CLAUDE.md that mirrors the API docs from README.md (document
ResourceSpans.ScopeSpans, ScopeSpans, ScopeSpans.SpanCount, ScopeSpans.Spans,
Span.TraceID, Span.SpanID, Span.ParentSpanID with signatures and brief
descriptions) or, if CLAUDE.md is not required, update the project documentation
policy (e.g., contributing or README note) to explicitly state that CLAUDE.md
isn’t needed and confirm in the PR description so reviewers know the omission is
intentional.
| func (r ResourceSpans) ScopeSpans() (iter.Seq[ScopeSpans], func() error) | ||
| ``` | ||
|
|
||
| **Scope-level operations (traces):** | ||
| ```go | ||
| type ScopeSpans []byte | ||
| func (s ScopeSpans) SpanCount() (int, error) | ||
| func (s ScopeSpans) Spans() (iter.Seq[Span], func() error) | ||
| ``` | ||
|
|
||
| **Span-level field accessors:** | ||
| ```go | ||
| type Span []byte | ||
| func (s Span) TraceID() ([16]byte, error) | ||
| func (s Span) SpanID() ([8]byte, error) | ||
| func (s Span) ParentSpanID() ([8]byte, error) | ||
| ``` |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -e
echo "=== Recent commits ==="
git log --oneline -n 20
echo -e "\n=== Docs presence ==="
ls -la README.md CLAUDE.md
echo -e "\n=== New API mentions in docs ==="
rg -n "ScopeSpans|Span\.TraceID|Span\.SpanID|Span\.ParentSpanID|SpanCount\(" README.md CLAUDE.mdRepository: ollygarden/otlp-wire
Length of output: 317
🏁 Script executed:
cat -n README.md | sed -n '140,180p'Repository: ollygarden/otlp-wire
Length of output: 1515
Create CLAUDE.md or confirm if it should document the new API surface.
The commit follows conventional format (✓), and the new API is properly documented in README.md at lines 151-167. However, CLAUDE.md does not exist. Per coding guidelines, documentation files (README.md, CLAUDE.md) must be up to date. Either create CLAUDE.md with API documentation coverage, or clarify whether CLAUDE.md is required for this project.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@README.md` around lines 151 - 167, The repo is missing CLAUDE.md to cover the
new API surface introduced (ResourceSpans.ScopeSpans, type ScopeSpans and
methods ScopeSpans.SpanCount/Spans, and type Span with
TraceID/SpanID/ParentSpanID); either add a CLAUDE.md that mirrors the API docs
from README.md (document ResourceSpans.ScopeSpans, ScopeSpans,
ScopeSpans.SpanCount, ScopeSpans.Spans, Span.TraceID, Span.SpanID,
Span.ParentSpanID with signatures and brief descriptions) or, if CLAUDE.md is
not required, update the project documentation policy (e.g., contributing or
README note) to explicitly state that CLAUDE.md isn’t needed and confirm in the
PR description so reviewers know the omission is intentional.
Summary
ScopeSpansandSpanbyte-slice types with iterators (ResourceSpans.ScopeSpans(),ScopeSpans.Spans()) and field accessors (TraceID(),SpanID(),ParentSpanID())Resolves E-1467
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests
Documentation