rollbar-php icon indicating copy to clipboard operation
rollbar-php copied to clipboard

No designated place for traceback in message item

Open ArturMoczulski opened this issue 5 years ago • 6 comments

Steps to reproduce:

  • set send_message_trace to true,
  • report a message item Rollbar::log(Level::INFO, 'Message from app');

Expected result The trace back should be visible in the Rollbar item details page just as when reporting an exception.

Result The trace back is not visible in the Rollbar item details page. It's under body.message.backtrace in unformatted and hard to read in occurrence details.

Impact across SDKs This is a problem that will appear across other SDKs as well as currently we just don't support backtrace for message items. Support for that needs to be implemented.

ArturMoczulski avatar Sep 28 '19 01:09 ArturMoczulski

@ArturMoczulski FWIW: at the API level, the current idea for these is that "message" items that contain tracebacks would be reported as tracebacks containing an explicit message. In those the message goes in trace.exception.description.

brianr avatar Sep 30 '19 05:09 brianr

+1 Please, this would be really great and I personally need it to go alongside SQL errors that I catch, and can only get the backtrace to appear in occurrences as @ArturMoczulski mentions

zanderwar avatar Apr 08 '20 01:04 zanderwar

This is good enough for me atm

function reportSqlError($sql, $error)
{
	$message = "SQL ERROR: {$error}\n\n";

	// maintain the layout, but reduce any excessive tabs or spaces
	$message .= preg_replace('/\t\s?/m', '', trim($sql)) . "\n\n";

	// build backtrace
	$e = new Exception();
	$trace = explode("\n", $e->getTraceAsString());

	// reverse array to make steps line up chronologically
	$trace = array_reverse($trace);

	// remove {main}
	array_shift($trace);

	// remove call to this method
	array_pop($trace);

	// renumber items
	$length = count($trace);
	$result = array();

	for ($i = 0; $i < $length; $i++)
	{
		$result[] = ($i + 1)  . ')' . substr($trace[$i], strpos($trace[$i], ' ')); // replace '#someNum' with '$i)', set the right ordering
	}

	$message .= implode("\n", $result);

	\Rollbar\Rollbar::log(\Rollbar\Payload\Level::CRITICAL, $message);
}

image

zanderwar avatar Apr 08 '20 23:04 zanderwar

Glad I'm not the only one suffering this issue, but so sad to see it's been like this for 4+ years!? I don't understand why the backtrace can't be used identically to what happens when there's an exception thrown? Is there any movement on this from the Rollbar PHP maintainers?

troygilbert avatar Sep 05 '23 15:09 troygilbert

Let me see if I can get this in either v4.1 or v4.2. For now, I will aim at v4.1.

danielmorell avatar Sep 15 '23 15:09 danielmorell

Any movement on this?

As a stopgap, are there any tools that can prettify the data contained in the backtrace field? I thought it was PHP serialized, but I'm unable to deserialize it, so I must be missing something.

troygilbert avatar Jan 03 '24 15:01 troygilbert