openvidu-browser: Parametrized send openvidu browser logs, disabled by default

pull/621/head
cruizba 2021-04-07 17:29:51 +02:00
parent 29a8b864cb
commit 5287ed631f
6 changed files with 22407 additions and 22374 deletions

View File

@ -32,6 +32,7 @@ import { PlatformUtils } from '../OpenViduInternal/Utils/Platform';
import * as screenSharingAuto from '../OpenViduInternal/ScreenSharing/Screen-Capturing-Auto'; import * as screenSharingAuto from '../OpenViduInternal/ScreenSharing/Screen-Capturing-Auto';
import * as screenSharing from '../OpenViduInternal/ScreenSharing/Screen-Capturing'; import * as screenSharing from '../OpenViduInternal/ScreenSharing/Screen-Capturing';
import {OpenViduLoggerConfiguration} from "../OpenViduInternal/Logger/OpenViduLoggerConfiguration";
/** /**
* @hidden * @hidden
*/ */
@ -107,6 +108,12 @@ export class OpenVidu {
* @hidden * @hidden
*/ */
webrtcStatsInterval: number = -1; webrtcStatsInterval: number = -1;
/**
* @hidden
*/
sendBrowserLogs: OpenViduLoggerConfiguration = OpenViduLoggerConfiguration.disabled;
/** /**
* @hidden * @hidden
*/ */

View File

@ -1190,6 +1190,7 @@ export class Session extends EventDispatcher {
} else { } else {
logger.warn('You were not connected to the session ' + this.sessionId); logger.warn('You were not connected to the session ' + this.sessionId);
} }
logger.flush();
} }
/** /**
@ -1452,6 +1453,7 @@ export class Session extends EventDispatcher {
const secret = queryParams['secret']; const secret = queryParams['secret'];
const recorder = queryParams['recorder']; const recorder = queryParams['recorder'];
const webrtcStatsInterval = queryParams['webrtcStatsInterval']; const webrtcStatsInterval = queryParams['webrtcStatsInterval'];
const sendBrowserLogs = queryParams['sendBrowserLogs'];
if (!!secret) { if (!!secret) {
this.openvidu.secret = secret; this.openvidu.secret = secret;
@ -1462,6 +1464,9 @@ export class Session extends EventDispatcher {
if (!!webrtcStatsInterval) { if (!!webrtcStatsInterval) {
this.openvidu.webrtcStatsInterval = +webrtcStatsInterval; this.openvidu.webrtcStatsInterval = +webrtcStatsInterval;
} }
if(!!sendBrowserLogs) {
this.openvidu.sendBrowserLogs = sendBrowserLogs;
}
this.openvidu.wsUri = 'wss://' + url.host + '/openvidu'; this.openvidu.wsUri = 'wss://' + url.host + '/openvidu';
this.openvidu.httpUri = 'https://' + url.host; this.openvidu.httpUri = 'https://' + url.host;

View File

@ -1,5 +1,6 @@
import {JL} from 'jsnlog' import {JL} from 'jsnlog'
import {OpenVidu} from "../../OpenVidu/OpenVidu"; import {OpenVidu} from "../../OpenVidu/OpenVidu";
import {OpenViduLoggerConfiguration} from "./OpenViduLoggerConfiguration";
export class OpenViduLogger { export class OpenViduLogger {
@ -7,7 +8,6 @@ export class OpenViduLogger {
private JSNLOG_URL: string = "/openvidu/elk/openvidu-browser-logs"; private JSNLOG_URL: string = "/openvidu/elk/openvidu-browser-logs";
private MAX_JSNLOG_BATCH_LOG_MESSAGES: number = 50; private MAX_JSNLOG_BATCH_LOG_MESSAGES: number = 50;
private MAX_JSNLOG_MAX_BACTH_MESSAGES: number = 1000;
private MAX_MSECONDS_BATCH_MESSAGES: number = 5000; private MAX_MSECONDS_BATCH_MESSAGES: number = 5000;
private openvidu: OpenVidu; private openvidu: OpenVidu;
@ -16,6 +16,7 @@ export class OpenViduLogger {
private isProdMode = false; private isProdMode = false;
private isJSNLogEnabled = true; private isJSNLogEnabled = true;
private isJSNLogSetup = false; private isJSNLogSetup = false;
private customAppenders: JL.JSNLogAjaxAppender[] = [];
private constructor() {} private constructor() {}
@ -25,27 +26,29 @@ export class OpenViduLogger {
*/ */
static configureJSNLog(openVidu: OpenVidu, sessionId: string, connectionId: string, token: string) { static configureJSNLog(openVidu: OpenVidu, sessionId: string, connectionId: string, token: string) {
// If instance is not null, JSNLog is enabled and is OpenVidu Pro // If instance is not null, JSNLog is enabled and is OpenVidu Pro
if (this.instance && this.instance.isJSNLogEnabled && openVidu.webrtcStatsInterval > -1) { if (this.instance && this.instance.isJSNLogEnabled && openVidu.webrtcStatsInterval > -1 && openVidu.sendBrowserLogs === OpenViduLoggerConfiguration.debug) {
this.instance.info("Configuring JSNLogs."); this.instance.info("Configuring JSNLogs.");
try { try {
this.instance.openvidu = openVidu; this.instance.openvidu = openVidu;
// Use connection id as user and token as password // Use connection id as user and token as password
const openViduJSNLogHeaders = (xhr) => { const openViduJSNLogHeaders = (xhr) => {
xhr.setRequestHeader('Authorization', "Basic " + btoa(connectionId + ":" + token)); xhr.setRequestHeader('Authorization', "Basic " + btoa(`${connectionId}%/%${sessionId}` + ":" + token));
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest') xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
// Additional headers for OpenVidu // Additional headers for OpenVidu
xhr.setRequestHeader('OV-Connection-Id', connectionId); xhr.setRequestHeader('OV-Connection-Id', btoa(connectionId));
xhr.setRequestHeader('OV-Session-Id', sessionId); xhr.setRequestHeader('OV-Session-Id', btoa(sessionId));
xhr.setRequestHeader('OV-Token', btoa(token));
} }
const customAppender: any = JL.createAjaxAppender("openvidu-browser-logs-appender-" + connectionId); const customAppender: any = JL.createAjaxAppender("openvidu-browser-logs-appender-" + connectionId);
customAppender.setOptions({ customAppender.setOptions({
beforeSend: openViduJSNLogHeaders, beforeSend: openViduJSNLogHeaders,
maxBatchSize: 1000,
batchSize: this.instance.MAX_JSNLOG_BATCH_LOG_MESSAGES, batchSize: this.instance.MAX_JSNLOG_BATCH_LOG_MESSAGES,
maxBatchSize: 1000,
batchTimeout: this.instance.MAX_MSECONDS_BATCH_MESSAGES batchTimeout: this.instance.MAX_MSECONDS_BATCH_MESSAGES
}); });
this.instance.customAppenders.push(customAppender);
// Avoid circular dependencies // Avoid circular dependencies
const logSerializer = (obj): string => { const logSerializer = (obj): string => {
@ -94,7 +97,7 @@ export class OpenViduLogger {
if (!this.isProdMode) { if (!this.isProdMode) {
this.LOG_FNS[0].apply(this.logger, arguments); this.LOG_FNS[0].apply(this.logger, arguments);
} }
if (this.isMonitoringLogEnabled()) { if (this.isDebugLogEnabled()) {
JL().info(arguments); JL().info(arguments);
} }
} }
@ -103,7 +106,7 @@ export class OpenViduLogger {
if (!this.isProdMode) { if (!this.isProdMode) {
this.LOG_FNS[1].apply(this.logger, arguments); this.LOG_FNS[1].apply(this.logger, arguments);
} }
if (this.isMonitoringLogEnabled()) { if (this.isDebugLogEnabled()) {
JL().debug(arguments); JL().debug(arguments);
} }
} }
@ -112,7 +115,7 @@ export class OpenViduLogger {
if (!this.isProdMode) { if (!this.isProdMode) {
this.LOG_FNS[2].apply(this.logger, arguments); this.LOG_FNS[2].apply(this.logger, arguments);
} }
if (this.isMonitoringLogEnabled()) { if (this.isDebugLogEnabled()) {
JL().info(arguments); JL().info(arguments);
} }
} }
@ -121,18 +124,26 @@ export class OpenViduLogger {
if (!this.isProdMode) { if (!this.isProdMode) {
this.LOG_FNS[3].apply(this.logger, arguments); this.LOG_FNS[3].apply(this.logger, arguments);
} }
if (this.isMonitoringLogEnabled()) { if (this.isDebugLogEnabled()) {
JL().warn(arguments); JL().warn(arguments);
} }
} }
error(...args: any[]) { error(...args: any[]) {
this.LOG_FNS[4].apply(this.logger, arguments); this.LOG_FNS[4].apply(this.logger, arguments);
if (this.isMonitoringLogEnabled()) { if (this.isDebugLogEnabled()) {
JL().error(arguments); JL().error(arguments);
} }
} }
flush() {
if(this.isDebugLogEnabled()) {
for(const appender of this.customAppenders) {
if (appender.sendBatch) appender.sendBatch();
}
}
}
enableProdMode(){ enableProdMode(){
this.isProdMode = true; this.isProdMode = true;
} }
@ -141,7 +152,7 @@ export class OpenViduLogger {
this.isJSNLogEnabled = false; this.isJSNLogEnabled = false;
} }
private isMonitoringLogEnabled() { private isDebugLogEnabled() {
return this.isJSNLogEnabled && this.isJSNLogSetup; return this.isJSNLogEnabled && this.isJSNLogSetup;
} }

View File

@ -0,0 +1,4 @@
export enum OpenViduLoggerConfiguration {
disabled = 'disabled',
debug = 'debug'
}

View File

@ -1,5 +1,8 @@
{ {
"$schema": "./node_modules/@angular/cli/lib/config/schema.json", "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"cli": {
"analytics": false
},
"version": 1, "version": 1,
"newProjectRoot": "projects", "newProjectRoot": "projects",
"projects": { "projects": {

File diff suppressed because it is too large Load Diff