Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sumologic for JavaScript application

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

  1. https://www.npmjs.com/package/logs-to-sumologic

  2. 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?

like image 289
Pradeep Jaiswar Avatar asked Jan 19 '26 10:01

Pradeep Jaiswar


1 Answers

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!

like image 51
Christian Beedgen Avatar answered Jan 21 '26 23:01

Christian Beedgen