Skip to content

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

Description

@georgms

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-javacommunityIssues and PRs created by the community

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions