Skip to content

keep the parameter annotations of two advices on Scala 3 - #1435

Open
Dichotomia wants to merge 1 commit into
kamon-io:masterfrom
Dichotomia:fix-scala3-advice-parameter-annotations
Open

Dichotomia wants to merge 1 commit into
kamon-io:masterfrom
Dichotomia:fix-scala3-advice-parameter-annotations

Conversation

@Dichotomia

Copy link
Copy Markdown

Fixes #1416.

On Scala 3, the static forwarders of a plain object don't carry the parameter annotations of its methods, and Kanela reads the advice from those forwarders. ProduceWithEnvelopeContext and CaptureCurrentTimestampOnExit were plain objects, so on kamon-bundle_3 their @Advice.Enter / @Advice.Argument / @Advice.This were lost. ByteBuddy then bound exit's scope as @Advice.Argument(0) and failed to transform DefaultProducerStageLogic with Cannot assign final org.apache.pekko.kafka.ProducerMessage$Envelope in to interface kamon.context.Storage$Scope. The module became Scala 3 in #1397, which only added the cross version.

Both advices now follow the pattern the other advices already use (CaptureCurrentTimestampOnEnter, HikariInstrumentation): a private companion class and @static methods.

The two new specs read the parameter annotations of the static advice methods by reflection. They fail on Scala 3 before the change (Map("enter" -> List(List()), "exit" -> List(List()))) and pass on 2.13 and 3 after it, along with the rest of kamon-instrumentation-common and kamon-pekko-connectors-kafka (++ 2.13.13! and ++ 3.3.5!). scalafmtCheckAll is clean on both modules.

A scan of the static advice methods with parameters in kamon-bundle_3-2.8.1 found no other advice in this situation.

On Scala 3, the static forwarders generated for a plain object do not carry
the parameter annotations of its methods, and Kanela reads the advice from
those forwarders. ProduceWithEnvelopeContext and
CaptureCurrentTimestampOnExit were plain objects, so on kamon-bundle_3 their
@Advice.Enter / @Advice.Argument / @Advice.This were lost: ByteBuddy bound
exit's scope as @Advice.Argument(0) and failed to transform
DefaultProducerStageLogic with "Cannot assign final
org.apache.pekko.kafka.ProducerMessage$Envelope in to interface
kamon.context.Storage$Scope" (kamon-io#1416).

Both now follow the pattern the other advices already use: a private
companion class and @static methods. The new specs read the parameter
annotations of the static advice methods by reflection; they fail on Scala 3
before this change and pass on 2.13 and 3 after it.
@Dichotomia

Copy link
Copy Markdown
Author

I've signed the CLA.

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.

[kamon-pekko-connectors-kafka] Kamon 2.8.1 throws IllegalStateException when using pekko-connectors-kafka 1.1.0

1 participant