Skip to content

Commit

Permalink
fix: Write to InfluxDB even when there is no app ID present
Browse files Browse the repository at this point in the history
Fixes #678
  • Loading branch information
Göran Sander committed Nov 28, 2023
1 parent 958236e commit b92cd2d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 18 additions & 8 deletions src/lib/post-to-influxdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,22 @@ function postUserEventToInfluxdb(msg) {
userDirectory: msg.user_directory,
userId: msg.user_id,
origin: msg.origin,
appId: msg.appId,
appName: msg.appName,
uaBrowserName: msg.ua.browser.name,
uaBrowserMajorVersion: msg.ua.browser.major,
uaOsName: msg.ua.os.name,
uaOsVersion: msg.ua.os.version,
};

// Add app id and name to tags if available
if (msg?.appId) tags.appId = msg.appId;
if (msg?.appName) tags.appName = msg.appName;

// Add user agent info to tags if available
if (msg?.ua?.browser?.name) tags.uaBrowserName = msg?.ua?.browser?.name;
if (msg?.ua?.browser?.major) tags.uaBrowserMajorVersion = msg?.ua?.browser?.major;
if (msg?.ua?.os?.name) tags.uaOsName = msg?.ua?.os?.name;
if (msg?.ua?.os?.version) tags.uaOsVersion = msg?.ua?.os?.version;





// Add custom tags from config file to payload
if (
globals.config.has('Butler-SOS.userEvents.tags') &&
Expand All @@ -454,12 +462,14 @@ function postUserEventToInfluxdb(msg) {
fields: {
userFull: tags.userFull,
userId: tags.userId,
appId: msg.appId,
appName: msg.appName,
},
},
];

// Add app id and name to fields if available
if (msg?.appId) datapoint[0].fields.appId = msg.appId;
if (msg?.appName) datapoint[0].fields.appName = msg.appName;

globals.influx
.writePoints(datapoint)
.then(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/udp_handlers_user_activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function udpInitUserActivityServer() {

// Do we have an app id to app name lookup table?
// If so, get the app name from the app id
if (msgObj.appId.length > 0) {
if (msgObj?.appId?.length > 0) {
const app = globals?.appNames.find((element) => element.id === msgObj.appId);
if (app?.name === undefined) {
msgObj.appName = '<unknown app name>';
Expand Down

0 comments on commit b92cd2d

Please sign in to comment.