Skip to content

feat(instrumentation): add span processor for code call-site attributes#34

Open
prathamesh-sonpatki wants to merge 2 commits intomainfrom
feat/code-attributes-processor
Open

feat(instrumentation): add span processor for code call-site attributes#34
prathamesh-sonpatki wants to merge 2 commits intomainfrom
feat/code-attributes-processor

Conversation

@prathamesh-sonpatki
Copy link
Copy Markdown
Member

Summary

  • Adds instrumentation/codeattr package with a SpanProcessor that stamps code.function, code.filepath, and code.lineno onto outbound spans
  • Only enriches Client, Producer, and Consumer span kinds — DB queries, HTTP client calls, Kafka messages, Redis commands, etc.
  • Uses sync.Pool to reuse the [64]uintptr frame buffer, avoiding a per-span heap allocation
  • Attribute keys use semconv.CodeFunctionKey / CodeFilepathKey / CodeLineNumberKey from semconv v1.25.0
  • Wired into the tracer provider in agent.go alongside the existing batch exporter

How it works

At span start, the processor walks runtime.Callers frames and skips known library prefixes (go.opentelemetry.io/, go.nhat.io/, database/sql., net/http., github.com/last9/go-agent, Sarama, Redis, Mongo, AWS SDK, etc.). The first non-library frame becomes the reported call site.

Test plan

  • Add a DB query span in an instrumented app and verify code.function, code.filepath, code.lineno appear with the correct caller location
  • Verify server/internal spans do NOT get code attributes
  • Verify no measurable overhead regression on high-throughput paths

🤖 Generated with Claude Code

prathamesh-sonpatki and others added 2 commits April 8, 2026 08:29
Adds a SpanProcessor that stamps code.function, code.filepath, and
code.lineno onto every Client, Producer, and Consumer span by walking
the call stack at span creation time. Server and Internal spans are
skipped. Uses sync.Pool to reuse the uintptr frame buffer and avoids
a per-span heap allocation. Attribute keys use semconv v1.25.0 constants.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add processor_test.go with 19 tests covering span kind filtering
  (client/producer/consumer enriched, server/internal skipped),
  isSkipped prefix matching, and shortFuncName trimming
- Group skipPrefixes by category (stdlib, OTel, agent, drivers)
- Remove dead pool fallback allocation (pcPool.New guarantees *pcsBuffer)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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