feat(instrumentation): add span processor for code call-site attributes#34
Open
prathamesh-sonpatki wants to merge 2 commits intomainfrom
Open
feat(instrumentation): add span processor for code call-site attributes#34prathamesh-sonpatki wants to merge 2 commits intomainfrom
prathamesh-sonpatki wants to merge 2 commits intomainfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
instrumentation/codeattrpackage with aSpanProcessorthat stampscode.function,code.filepath, andcode.linenoonto outbound spansClient,Producer, andConsumerspan kinds — DB queries, HTTP client calls, Kafka messages, Redis commands, etc.sync.Poolto reuse the[64]uintptrframe buffer, avoiding a per-span heap allocationsemconv.CodeFunctionKey/CodeFilepathKey/CodeLineNumberKeyfrom semconv v1.25.0agent.goalongside the existing batch exporterHow it works
At span start, the processor walks
runtime.Callersframes 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
code.function,code.filepath,code.linenoappear with the correct caller location🤖 Generated with Claude Code