Treblle / treblle-laravel

The official Treblle SDK for Laravel. Seamlessly integrate Treblle to manage communication with your dashboard, send errors, and secure sensitive data.
https://www.treblle.com/
MIT License
129 stars 24 forks source link

3.0.8: JsonException - TreblleMiddleware@149 #69

Closed djimnz closed 1 year ago

djimnz commented 1 year ago

Version

Description

Following the Laravel Package installation documentation. And running my API via Vapor, I'm encountering an issue with your middleware. Currently, I cannot install treblle-laravel version ^4 since my composer is configured for stable packages only.

Here the logs:

{
"exception": 
{
"class": 
"JsonException",
"message": 
"Syntax error",
"code": 
4,
"file": 
"/var/task/vendor/treblle/treblle-laravel/src/Middlewares/TreblleMiddleware.php:149"
},
"aws_request_id": 
"2d63be31-855d-4c62-9fb4-2c7d5d3a9346"
}

Thank you!

Expected behavior

Recording API calls onto Treblle.

alphaolomi commented 1 year ago

+1 Running on Octane (RoadRunner server)

JustSteveKing commented 1 year ago

@alphaolomi and @djimnz are you both using Laravel Vapor? Which versions?

Please try installing version 4.0.34 directly and let me know what issues you are having. Also ensure that the configuration is published and ENV variables are set.

alphaolomi commented 1 year ago

OCTANE

Config is present and all required envs are added.

"laravel/octane": "^2.0",

"treblle/treblle-laravel": "^4.0", // 4.0.34

 Environment ............................................ 
  Application Name ........................ My Laravel App  
  Laravel Version ................................ 10.14.1  
  PHP Version ..................................... 8.1.20  
  Composer Version ................................. 2.5.8  
  Environment ...................................... local  
  Debug Mode ..................................... ENABLED  
  URL ..................................... localhost:8000  
  Maintenance Mode ................................... OFF  
TypeError: Treblle\Middlewares\TreblleMiddleware::handle(): Return value must be of type Illuminate\Http\Response|Illuminate\Http\JsonResponse, Illuminate\Http\RedirectResponse returned
JustSteveKing commented 1 year ago

You are adding the middleware to a route that it shouldn't be on. An API should return a JSON response or a Response directly - not a Redirect

djimnz commented 1 year ago

@JustSteveKing I confirm that last version of Treblle for Laravel is now working well! Thank you.

Is there a way to send the data to Treblle via Queue system? This is currently slowing down my API quite much.

Thank you!

JustSteveKing commented 1 year ago

Hey @djimnz that unfortunately is not possible. The Treblle middleware executes at the end of the process once your API has already sent a response. This is terminating middleware