Skip to content

Commit 572e5fa

Browse files
achen2401Amy Chenivan-c
authored
Frontend logging fixes (#221)
* cosri frontend logging fixes * Update src/helpers/utility.js Co-authored-by: Ivan Cvitkovic <[email protected]> * fix user check * Update src/helpers/utility.js Co-authored-by: Ivan Cvitkovic <[email protected]> --------- Co-authored-by: Amy Chen <[email protected]> Co-authored-by: Ivan Cvitkovic <[email protected]>
1 parent 2874f62 commit 572e5fa

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/components/Landing/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ export default class Landing extends Component {
419419
() => {
420420
this.initTocBot();
421421
writeToLog(index >= 1 ? "report tab" : "overview tab", "info", {
422-
tags: ["tab"],
422+
tags: ["tab", "analytics"],
423423
...this.getPatientLogParams(),
424424
});
425425

src/helpers/utility.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,21 @@ export function writeToLog(message, level, params) {
573573
if (!getEnvConfidentialAPIURL()) return;
574574
if (!message) return;
575575
const logLevel = level ? level : "info";
576-
const logParams = params ? params : {};
576+
// use Object.assign to prevent modification of original params
577+
const logParams = Object.assign({}, params ? params : {});
577578
if (!logParams.tags) logParams.tags = [];
578-
logParams.tags.push("cosri-frontend");
579-
579+
const COSRI_FRONTEND_TAG = "cosri-frontend";
580+
if (logParams.tags.indexOf(COSRI_FRONTEND_TAG) === -1) {
581+
logParams.tags.push(COSRI_FRONTEND_TAG);
582+
}
583+
if (Object.keys(logParams).indexOf("user") === -1) {
584+
const userId = getUserIdFromAccessToken();
585+
if (userId) {
586+
logParams.user = {
587+
username: userId
588+
};
589+
}
590+
}
580591
const auditURL = `${getEnvConfidentialAPIURL()}/auditlog`;
581592
const patientName = params.patientName ? params.patientName : "";
582593
let messageString = "";

0 commit comments

Comments
 (0)