apm-agent-java icon indicating copy to clipboard operation
apm-agent-java copied to clipboard

Elastic APM Java agent cannot automatically infer the class name / object name for a span when using Scala and @CaptureSpan

Open georgms opened this issue 8 months ago • 1 comments

Describe the bug

According to the documentation @CaptureSpan will automatically set the name of the span to Classname#methodname. When using Scala 2, this works fine for classes but not for objects. For objects, only the #methodname is inferred but the Classname is just missing.

Steps to reproduce

  1. Use Scala 2.12.18 and co.elastic.apm:apm-agent-api:1.50.0.
  2. Create a Scala class and object:
import co.elastic.apm.api.{CaptureSpan, ElasticApm, Transaction}

class Example {
 @CaptureSpan
 def myClassMethod() = println("Example#myClassMethod")
}

object Example {
 @CaptureSpan
 def myObjectMethod() = println("Example#myObjectMethod")
}

ElasticApm.startTransaction()

(new Example).myClassMethod()

Example.myObjectMethod()

ElasticApm.stopTransaction()
  1. Run the code.
  2. Check your Elastic APM instance for the captured spans.

Expected behavior

Two spans are captured with the names:

  1. Example#myClassMethod
  2. Example#myObjectMethod

Debug logs

n/a

georgms avatar Jun 17 '24 08:06 georgms