Description
Is your feature request related to a problem? Please describe.
The OpenTelemetry Java agent already excels in automatically generating spans around specified methods via the otel.instrumentation.methods.include
configuration. This feature, however, currently assigns span names directly from method names, a default behavior that, while straightforward, does not leverage the potential depth of observability that could be achieved by more dynamically naming spans. Dynamic span naming could utilize method parameters or returned values, offering richer insights, particularly in complex application scenarios.
To enhance this capability, I propose the introduction of configurable span naming based on method parameter values or return values, inspired by similar features found in APM tools like AppDynamics' SplitbyPOJOMethodCall
. This enhancement would permit the specification of span naming directly within configuration files, greatly simplifying the process of instrumentation by allowing for more descriptive and contextually relevant span names without additional coding.
Describe the solution you'd like
Feature Outline
I propose extending the otel.instrumentation.methods.include
configuration to allow specifying a template for dynamic span naming directly within the method specification. This enhancement would enable users to define span names based on the values of method parameters or even values obtained through getter chains on those parameters.
Proposed Syntax
The new syntax would allow including a spanName attribute within the method specification, where the span name can be dynamically constructed using indices to refer to method parameters and/or employing getter chains for more complex objects. Here's how the proposed syntax looks:
otel.instrumentation.methods.include=
my.package.OrderProcessor[processOrder(spanName="OrderProcess-{0}")],
my.package.CustomerService[handleInquiry(spanName="SupportInquiry-{2}")],
my.package.OrderService[submitOrder(spanName="OrderSubmit-{0.getOrderDetails().getType()}")]
processOrder(spanName="OrderProcess-{0}")
: Automatically names spans based on the value of the first parameter of the processOrder method.handleInquiry(spanName="SupportInquiry-{2}")
: Names spans based on the third parameter of the handleInquiry method.submitOrder(spanName="OrderSubmit-{0.getOrderDetails().getType()}")
: Demonstrates a complex example where the span name is derived using a recursive getter chain on the first parameter.
Describe alternatives you've considered
No response
Additional context
No response