Splunk Enterprise

TypeError: Failed to fetch when using splunk-logging javascript library

sng_chewy
Engager

I'm using the splunk-logging library found here to setup event collection from a web app. 

I have followed the Basic Example in the repo's README and also from the how to page

The error I'm seeing is ERROR: TypeError: Failed to fetch CONTEXT from line 32 in splunklogger.js. The code that sets up the logger looks like the following. 

const config = {
token: splunkToken,
url: splunkUrl
};
const SplunkLogger = require('splunk-logging').Logger;
const logger = new SplunkLogger(config);

const payload = {
message: 'hello world',
metadata: {
index: 'hms'
sourcetype: 'ui'
}
};

logger.send(payload, (error, resp, body) => {
console.log(error);
});

 

As I'm writing this out I'm wondering if the error I'm getting is because I'm using the logger from the browser, so there is a cross origin issue. Is this the issue or is there an issue in the code?

Padmaja
New Member

Hi,

Even I'm facing the issue while picking the library classes.

Module '"splunk-logging"' has no exported member 'SplunkLoggingService'.

 

Have installed splunk-javascript package.. pls let me know any other installations need to be done.

0 Karma

noygafni
Engager

Actually I discovered it is a cors error, so it is impossible to send logs directly to splunk from the browser

0 Karma

noygafni
Engager

Did you manage to solve this? I get the exact same error trying to log from browser

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...