3

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?

ankitjaininfo
  • 11,961
  • 7
  • 52
  • 75
Pradeep Jaiswar
  • 1,785
  • 7
  • 27
  • 48

4 Answers4

3

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!

2

Sumo Logic is actively working to add CORS headers to the HTTP Data API (HTTP Source) Responses. I do not have a firm date for this yet, but should be available very soon. If you would like to get notified when this available, please vote / subscribe to the idea at : https://sumologic.aha.io/ideas/SL-I-2085

Cheers Brian Goleno Sumo Logic, Product Management

1

Here is a simplified version of what we're using in our company to send SL events from client-side:

https://github.com/oriadam/Sumologic-as-GA

Feel free to use it for any purpose. Credit not needed.

This is what we're using to display the data later:

http://github.com/oriadam/sumologic_google_charts

oriadam
  • 7,747
  • 2
  • 50
  • 48
1

I have used Sumologic for client-side application. Sumologic can accept Ajax calls from web browser and it support JSONP. All you need to create a collector/source at Sumologic and use the logging end-point to make a GET call.

$.ajax({
        crossDomain: true,
        url : "<SUMOLOGIC.LOGGING_ENDPOINT>",
        data : dataString,
        dataType:"jsonp"
});

You can do this on window.onerror() to capture all UI/Javascript errors. We do this to capture line, column, source file, location/URL, user-agent, timezone, etc.

ankitjaininfo
  • 11,961
  • 7
  • 52
  • 75