I already have sumologic working on my EC2. I also have a customer facing React application. I want to integrate sumologic for my client side application as well. Found two npm module for this
https://www.npmjs.com/package/logs-to-sumologic
https://www.npmjs.com/package/sumologic
But both seems to be not working and I also don't see the documentation for client side integration of sumologic.
Anyone using sumologic for client side?
I believe what you are running into with the NPM libraries, which look like they are designed to work server-side, is the fact that they are using POST requests to Sumo Logic. Making POST requests from the client side to any domain that didn't originate the actual Javascript is usually prevented by the browser (see Wikipedia for CORS for the gory details).
However, the HTTP Source endpoints also support GET requests. You can configure an HTTP Source as described here: https://help.sumologic.com/Send_Data/Sources/HTTP_Source. Once you have the URL, you can send a log line via Curl:
curl -v https://collectors.sumologic.com/receiver/v1/http/[UniqueHTTPCollectorCode]?[message_data]
(See also the documentation here: https://help.sumologic.com/Send_Data/Sources/HTTP_Source/Upload_Data_to_an_HTTP_Source)
The endpoint supports GET for exactly this reason; you can use this on the client side by making an "image" request, something like this:
var img = new Image();
img.src = 'https://collectors.sumologic.com/receiver/v1/http/[UniqueHTTPCollectorCode]?[message_data]'
You can look for an example that is using this technique to mimick "Google Analytics" with Sumo on Github, look for user oriadam and repository Sumologic-as-GA.
You have to hand-roll this at the moment, but please feel free to share your results!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With