michaelhyatt / elastic-apm-mule4-agent

APM agent for tracing Mule 4 applications using Elastic APM
18 stars 9 forks source link

transactionId is lost if service calls itself #7

Closed adrianj closed 4 years ago

adrianj commented 4 years ago

We have a use case where sometimes a service will call itself. In this situation, a RuntimeException is occurring due to a null transactionId.

Application has two endpoints: /request and /status. The /request endpoint calls /status.

This is the general flow:

  1. enter /request flow - creates transaction id
  2. enter /status flow - same transaction id (from correlationId)
  3. exit /status flow - close the transaction, remove the id from the transactionStore
  4. next /request flow component - RuntimeException - transactionId no longer exists

I was able to work around it by modifying the mule4-agent SpanUtils.startSpan to not throw an exception and instead return ElasticApm.currentTransaction().

Mule Kernel 4.2.0 AdoptOpenJDK 1.8 mule4-agent 0.0.2 mule-apikit-module 1.3.3

michaelhyatt commented 4 years ago

@adrianj this is great that you found a solution, do you mind creating a pull request with the code you fixed?