PHP - Missing trace when utilising createErrorFromThrowable

Hi there,
It seems when utilising createErrorFromThrowable the exception itself is being registered in ElasticAPM which is great.
However, its missing the stack trace.
I can see that other transactions have a trace sample attached (which means the Agent is registered correctly), but when it comes to capturing errors it is missing.

Any idea how i can enhance my observability to support the stack trace when capturing errors manually?

We are using the debian agent.

Bumping for visibility

Try using Elastic\Apm\ElasticApm::captureThrowable($e) instead of createErrorFromThrowable($e), and set elastic_apm.stack_trace_limit = -1 in your agent config. Restart PHP after the change and check if the stack trace appears in the error document.

Hi Rafa, this method does not exist.

Got it in that case you can stick with createErrorFromThrowable($e) but make sure you send it with ElasticApm::captureError() or attach it to a transaction/span.

Also check your config:

elastic_apm.stack_trace_limit = -1

Without that, the agent won’t include the stack trace even if the error is captured.

What’s your PHP agent version? Some older builds didn’t include full stack traces with createErrorFromThrowable.

Hi Rafa and other readers.

I’ve did additional debugging, i pulled the source of the PHP lib on my machine and integrated it into our app.

It appears the Stack trace is making its way through the entire library, all the way to the event sink, and to the elastic_apm_send_to_server method.

Debug data:

Something is going wrong, either in the C extension or on a UI level.

The config above appears to be respected by the PHP extension, but it appears that the issue is occurring on the C agent level.

Thanks

Here’s a sample visualisation of the issue i’m having

Note: we are using https://github.com/elastic/apm-agent-php/releases/download/v1.15.0/apm-agent-php_1.15.0_amd64.deb

Here’s another example.

The culprit, error id etc is coming through, but not displaying.

Note how Culprit at the top box is N/A.

Hi Oliver, thanks for digging deeper and sharing the debug details.

If the stack trace is visible all the way to elastic_apm_send_to_server but disappears in Kibana, that strongly suggests it’s being dropped either by the C extension or on the UI side. Since you’re already on 1.15.0, I’d recommend:

Double-check elastic_apm.stack_trace_limit is not set to 0.

Try upgrading to the latest release (>= 1.15.1) there have been fixes around error payload serialization.

If it still happens, it might be worth opening a GitHub issue with the debug output, as this looks like an agent bug rather than configuration

Have you tried reproducing with a minimal script that just throws an exception and calls createErrorFromThrowable? That could help isolate if it’s something in the integration layer vs. the core agent.