Skip to content

Conversation

@Kleszczu98
Copy link

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
Copy link

linux-foundation-easycla bot commented Oct 29, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@breedx-splk
Copy link
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
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
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
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
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
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
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
Copy link

codecov bot commented Nov 5, 2025

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 16 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 Sentry.
📢 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.

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.

3 participants