Add auto-instrumentation for Spring MVC handler and @Transactional spans (like Datadog agent)

Open
#4,617 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
java, spring

Research direction

Start by reviewing the Spring MVC and Spring transaction integration points named in the issue, especially HandlerAdapter.handle() and TransactionInterceptor.invoke(), and compare them with the upstream OpenTelemetry Spring MVC instrumentation module. Done means the Java agent creates spring.handler and spring.transaction spans with controller or service method context and preserves the requested request-to-database waterfall without application changes.

Written by the indexing model from the issue text.

Description

Is your feature request related to a problem? Please describe.

When using the Application Insights Java agent (3.7.x) with a Spring Boot application, the transaction waterfall only shows auto-instrumented external calls (JDBC, HTTP clients) but not the internal Spring
framework flow.

The Datadog Java agent, by comparison, automatically creates spans for Spring framework integration points via bytecode instrumentation, producing a detailed waterfall without any code change:

servlet.request (incoming HTTP)
└─ spring.handler (controller method)
└─ spring.transaction (@Transactional service method)
└─ jdbc.query (SQL query via repository)
└─ postgresql.query (driver-level execution)

This is achieved because the Datadog agent instruments Spring MVC handler dispatch and Spring @Transactional boundaries automatically — not every bean method, but the key framework integration points that
give full visibility into the request lifecycle.

With the Application Insights agent, the same request only shows:

GET /api/v1/threads/{id}/messages (request)
└─ SELECT ... FROM message (JDBC)
└─ POST https://openai.azure.com (HTTP)

The entire controller-to-service layer is invisible, making it difficult to identify which business logic step is slow or failing.

Describe the solution you would like

Auto-instrument Spring framework integration points that the Datadog agent already covers, specifically:

  1. spring.handler — Spring MVC handler method dispatch (the controller method matched by @RequestMapping / @GetMapping / etc.). This span should include the controller class and method name.
  2. spring.transaction — Spring @Transactional boundaries. This would capture the service-layer method wrapped in a transaction, providing the controller → service link in the waterfall.

These are not arbitrary application methods — they are well-defined framework extension points where Spring already has interceptor/advice infrastructure. The agent could instrument HandlerAdapter.handle()
and TransactionInterceptor.invoke() at the bytecode level, just as it already does for JDBC and HTTP clients.

This would produce the same waterfall visibility that Datadog users get out of the box, without requiring any application code changes, @WithSpan annotations, or customInstrumentation configuration.

Describe alternatives you have considered

  • customInstrumentation in applicationinsights.json: Requires listing every class and method individually. Does not scale, is fragile to maintain, and new methods are silently missed. No wildcard or pattern
    support is available.
  • @WithSpan annotations: Requires modifying application code, adds a dependency on opentelemetry-instrumentation-annotations, and must be manually added to every relevant method.
  • Spring AOP aspect with ObservationRegistry: A custom @Aspect that wraps all Spring bean methods in Micrometer Observations (bridged to OTel spans via micrometer-tracing-bridge-otel). This works but
    requires application-side code, adds spring-boot-starter-aop as a dependency, and introduces AOP proxy overhead. It also instruments more than necessary (every public bean method) since there is no way to
    target just framework integration points.
  • OpenTelemetry Java agent extensions (ByteBuddy): Building a custom InstrumentationModule targeting Spring MVC and Spring TX. However, the Application Insights documentation does not guarantee compatibility
    with custom agent extensions.

Additional context

The Datadog Java agent achieves this by instrumenting specific Spring framework classes at the bytecode level:

  • HandlerAdapter / DispatcherServlet for spring.handler spans
  • PlatformTransactionManager / TransactionInterceptor for spring.transaction spans

These are stable Spring APIs that rarely change between versions. The OpenTelemetry upstream agent already instruments Spring MVC handlers (via spring-webmvc instrumentation module), so the foundation exists
in the OTel ecosystem — it may just need to be enabled or surfaced in the Application Insights distribution.

Dominant language
Java
Stars
327
Forks
222
Avg merge
22h 34m
Merged PRs (30d)
14

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/ApplicationInsights-Java

All issues in microsoft/ApplicationInsights-Java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.