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 screenSharing from '../OpenViduInternal/ScreenSharing/Screen-Capturing';
import {OpenViduLoggerConfiguration} from "../OpenViduInternal/Logger/OpenViduLoggerConfiguration";
/**
* @hidden
*/
@ -107,6 +108,12 @@ export class OpenVidu {
* @hidden
*/
webrtcStatsInterval: number = -1;
/**
* @hidden
*/
sendBrowserLogs: OpenViduLoggerConfiguration = OpenViduLoggerConfiguration.disabled;
/**
* @hidden
*/

View File

@ -1190,6 +1190,7 @@ export class Session extends EventDispatcher {
} else {
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 recorder = queryParams['recorder'];
const webrtcStatsInterval = queryParams['webrtcStatsInterval'];
const sendBrowserLogs = queryParams['sendBrowserLogs'];
if (!!secret) {
this.openvidu.secret = secret;
@ -1462,6 +1464,9 @@ export class Session extends EventDispatcher {
if (!!webrtcStatsInterval) {
this.openvidu.webrtcStatsInterval = +webrtcStatsInterval;
}
if(!!sendBrowserLogs) {
this.openvidu.sendBrowserLogs = sendBrowserLogs;
}
this.openvidu.wsUri = 'wss://' + url.host + '/openvidu';
this.openvidu.httpUri = 'https://' + url.host;

View File

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

File diff suppressed because it is too large Load Diff