Skip to content

Draft: Add instrumentation for otel span annotations - #1348

Draft
Kleszczu98 wants to merge 3 commits into
open-telemetry:mainfrom
kta-prs:feature/span_annotation_instrumentation
Draft

Draft: Add instrumentation for otel span annotations#1348
Kleszczu98 wants to merge 3 commits into
open-telemetry:mainfrom
kta-prs:feature/span_annotation_instrumentation

Conversation

@Kleszczu98

Copy link
Copy Markdown

Example byteBuddy implementation of auto-instrumentation of the following annotations:

#412

@Kleszczu98
Kleszczu98 requested a review from a team as a code owner October 29, 2025 09:47
@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 29, 2025

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

@breedx-splk

Copy link
Copy Markdown
Contributor

@Kleszczu98 hi. The title of this still says it's a draft PR, but it's not marked as such. Please remove the word Draft from the title if it's ready for review, or mark it truly as draft by clicking "Convert to draft". You'll will also need to sign the Contributor License Agreement (CLA).

Thanks!

@Kleszczu98
Kleszczu98 marked this pull request as draft October 31, 2025 18:52

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we aware of a use case that requires tracing a constructor? It sounds a bit of an edge case to me. If there's no foreseeable usage right now, I'd prefer to leave it for a future PR.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ok, i will remove the constructor implementation and focus on just the normal method case to simplify the PR.

@Advice.OnMethodEnter(suppress = Throwable::class)
fun onEnter(
@Advice.AllArguments args: Array<Any?>,
@Advice.Origin method: Method

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd like to follow best practices from the upstream instrumentation, such as avoiding using @Advice.Origin Method. In this case it seems like we can just get the method name by using @Advice.Origin("#m") String methodName.

@JvmStatic
@Advice.OnMethodEnter(suppress = Throwable::class)
fun onEnter(
@Advice.AllArguments args: Array<Any?>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not faimilar with @WithSpan, though I'm curious why it might need all the method's arguments?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I found the @AddingSpanAttributes annotation but it seems i might've misunderstood it's function.
It is not mentioned in the linked documentation so perhaps I should remove this as well and stick to @WithSpan and @SpanAttribute ? It covers all the most common use cases already.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see. I also don't see it in the docs so it should be fine to leave it out, at least for now. I'll cc @breedx-splk in case he's more familiar with it to make sure we're not missing something important.

- Removed constructor implementation for now
- Applied @Advice.Origin("#m") in AddingSpanAttributesMethodAdvice.kt
- Added basic test for a start
- Generated apiDump
- Ran spotlessApply
- Ran check
@codecov

codecov Bot commented Nov 5, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 83 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.33%. Comparing base (289fdab) to head (ed7947d).
⚠️ Report is 412 commits behind head on main.

Files with missing lines Patch % Lines
...ation/agent/spanannotation/SpanAnnotationPlugin.kt 0.00% 30 Missing ⚠️
...entation/library/spanannotation/HelperFunctions.kt 0.00% 25 Missing ⚠️
...anannotation/advice/method/WithSpanMethodAdvice.kt 0.00% 9 Missing ⚠️
...ry/spanannotation/SpanAnnotationInstrumentation.kt 0.00% 8 Missing ⚠️
...otation/advice/method/SpanAttributeMethodAdvice.kt 0.00% 5 Missing ⚠️
.../advice/method/AddingSpanAttributesMethodAdvice.kt 0.00% 4 Missing ⚠️
.../instrumentation/library/spanannotation/TestApp.kt 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1348      +/-   ##
==========================================
- Coverage   64.17%   62.33%   -1.84%     
==========================================
  Files         153      164      +11     
  Lines        3059     3181     +122     
  Branches      315      328      +13     
==========================================
+ Hits         1963     1983      +20     
- Misses       1007     1105      +98     
- Partials       89       93       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fractalwrench fractalwrench added the needs author feedback Waiting for additional feedback from the author label Jan 21, 2026
@github-actions

Copy link
Copy Markdown

This has been automatically marked as stale because it has been marked as needing author feedback and has not had any activity for 21 days. It will be closed automatically if there is no response from the author within 14 additional days from this comment.

@github-actions github-actions Bot added the stale label Feb 11, 2026
@github-actions github-actions Bot closed this Feb 25, 2026
@DavidGrath

Copy link
Copy Markdown
Contributor

@Kleszczu98 , good day,
It seems this PR has aged quite a bit.
Do you still want to continue working on this? We'd be glad to have this merged once it's complete

@DavidGrath DavidGrath reopened this Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs author feedback Waiting for additional feedback from the author stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants