* Add AMSClientLogger

* Update AriaTelemetry to detect AMS scenario type

* Pass AMSClientLogger

* Add tests

* Update package.json

* Update CHANGELOG.md
This commit is contained in:
xTEddie 2023-01-23 16:59:33 -05:00 коммит произвёл GitHub
Родитель a42cdc5f92
Коммит 72518537cc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 270 добавлений и 5956 удалений

Просмотреть файл

@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
- Add `CreateACSAdapter` telemetry event
- Improve `ChatSDK.createChatAdapter()` with retries using exponential backoff & additional details on failures
- Add `GetAgentAvailability` SDK method for auth chat
- Pass `logger` to AMSClient
### Fixed
- Fix `ChatAdapterOptionalParams.ACSAdapter.options.egressMiddleware` being used as `ingressMiddleware`

Просмотреть файл

@ -1,5 +1,5 @@
import LogLevel from '@microsoft/omnichannel-ic3core/lib/logging/LogLevel';
import {ACSAdapterLogger, ACSClientLogger, IC3ClientLogger, OCSDKLogger, CallingSDKLogger} from '../../src/utils/loggers';
import {ACSAdapterLogger, ACSClientLogger, IC3ClientLogger, OCSDKLogger, CallingSDKLogger, AMSClientLogger} from '../../src/utils/loggers';
describe('loggers', () => {
describe('IC3ClientLogger', () => {
@ -410,4 +410,71 @@ describe('loggers', () => {
expect(telemetry.info).toBeCalledTimes(1);
});
});
describe('AMSClientLogger', () => {
const omnichannelConfig = {
orgId: '',
orgUrl: '',
widgetId: ''
}
const telemetry = {
debug: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
info: jest.fn()
}
it('AMSClientLogger.logClientSdkTelemetryEvent() with LogLevel DEBUG should call telemetry.debug()', () => {
const logger = new AMSClientLogger(omnichannelConfig);
const eventData = {
Event: ''
};
logger.useTelemetry(telemetry as any);
logger.logClientSdkTelemetryEvent(LogLevel.DEBUG, eventData as any);
expect(telemetry.debug).toBeCalledTimes(1);
});
it('AMSClientLogger.logClientSdkTelemetryEvent() with LogLevel WARN should call telemetry.warn()', () => {
const logger = new AMSClientLogger(omnichannelConfig);
const eventData = {
Event: ''
};
logger.useTelemetry(telemetry as any);
logger.logClientSdkTelemetryEvent(LogLevel.WARN, eventData as any);
expect(telemetry.warn).toBeCalledTimes(1);
});
it('AMSClientLogger.logClientSdkTelemetryEvent() with LogLevel ERROR should call telemetry.error()', () => {
const logger = new AMSClientLogger(omnichannelConfig);
const eventData = {
Event: ''
};
logger.useTelemetry(telemetry as any);
logger.logClientSdkTelemetryEvent(LogLevel.ERROR, eventData as any);
expect(telemetry.error).toBeCalledTimes(1);
});
it('AMSClientLogger.logClientSdkTelemetryEvent() with LogLevel INFO should call telemetry.info()', () => {
const logger = new AMSClientLogger(omnichannelConfig);
const eventData = {
Event: ''
};
logger.useTelemetry(telemetry as any);
logger.logClientSdkTelemetryEvent(LogLevel.INFO, eventData as any);
expect(telemetry.info).toBeCalledTimes(1);
});
});
})

5957
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -42,7 +42,7 @@
"@azure/communication-chat": "1.1.1",
"@azure/communication-common": "1.1.0",
"@microsoft/ocsdk": "^0.3.3",
"@microsoft/omnichannel-amsclient": "^0.1.2",
"@microsoft/omnichannel-amsclient": "^0.1.3",
"@microsoft/omnichannel-ic3core": "^0.1.2"
}
}

Просмотреть файл

@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { ACSAdapterLogger, ACSClientLogger, CallingSDKLogger, IC3ClientLogger, OCSDKLogger, createACSAdapterLogger, createACSClientLogger, createCallingSDKLogger, createIC3ClientLogger, createOCSDKLogger } from "./utils/loggers";
import { ACSAdapterLogger, ACSClientLogger, CallingSDKLogger, IC3ClientLogger, OCSDKLogger, createACSAdapterLogger, createACSClientLogger, createCallingSDKLogger, createIC3ClientLogger, createOCSDKLogger, createAMSClientLogger, AMSClientLogger } from "./utils/loggers";
import ACSClient, { ACSConversation } from "./core/messaging/ACSClient";
import { ChatMessageReceivedEvent, ParticipantsRemovedEvent } from '@azure/communication-signaling';
import {SDKProvider as OCSDKProvider, uuidv4} from "@microsoft/ocsdk";
@ -9,7 +9,6 @@ import { defaultLocaleId, getLocaleStringFromId } from "./utils/locale";
import { loadScript, removeElementById } from "./utils/WebUtils";
import platform, { isBrowser } from "./utils/platform";
import validateSDKConfig, {defaultChatSDKConfig} from "./validators/SDKConfigValidators";
import ACSParticipantDisplayName from "./core/messaging/ACSParticipantDisplayName";
import AMSFileManager from "./external/ACSAdapter/AMSFileManager";
import AriaTelemetry from "./telemetry/AriaTelemetry";
@ -70,6 +69,7 @@ import OmnichannelErrorCodes from "./core/OmnichannelErrorCodes";
import OmnichannelMessage from "./core/messaging/OmnichannelMessage";
import OnNewMessageOptionalParams from "./core/messaging/OnNewMessageOptionalParams";
import PersonType from "@microsoft/omnichannel-ic3core/lib/model/PersonType";
import PluggableLogger from "@microsoft/omnichannel-amsclient/lib/PluggableLogger";
import PostChatContext from "./core/PostChatContext";
import ProtocolType from "@microsoft/omnichannel-ic3core/lib/interfaces/ProtocoleType";
import ScenarioMarker from "./telemetry/ScenarioMarker";
@ -115,6 +115,7 @@ class OmnichannelChatSDK {
private acsClientLogger: ACSClientLogger | null = null;
private acsAdapterLogger: ACSAdapterLogger | null = null;
private callingSdkLogger: CallingSDKLogger | null = null;
private amsClientLogger: AMSClientLogger | null = null;
private isPersistentChat = false;
private isChatReconnect = false;
private reconnectId: null | string = null;
@ -144,6 +145,7 @@ class OmnichannelChatSDK {
this.acsClientLogger = createACSClientLogger(this.omnichannelConfig);
this.acsAdapterLogger = createACSAdapterLogger(this.omnichannelConfig);
this.callingSdkLogger = createCallingSDKLogger(this.omnichannelConfig);
this.amsClientLogger = createAMSClientLogger(this.omnichannelConfig);
this.scenarioMarker.useTelemetry(this.telemetry);
this.ic3ClientLogger.useTelemetry(this.telemetry);
@ -151,6 +153,7 @@ class OmnichannelChatSDK {
this.acsClientLogger.useTelemetry(this.telemetry);
this.acsAdapterLogger.useTelemetry(this.telemetry);
this.callingSdkLogger.useTelemetry(this.telemetry);
this.amsClientLogger.useTelemetry(this.telemetry);
this.scenarioMarker.setRuntimeId(this.runtimeId);
this.ic3ClientLogger.setRuntimeId(this.runtimeId);
@ -158,6 +161,7 @@ class OmnichannelChatSDK {
this.acsClientLogger.setRuntimeId(this.runtimeId);
this.acsAdapterLogger.setRuntimeId(this.runtimeId);
this.callingSdkLogger.setRuntimeId(this.runtimeId);
this.amsClientLogger.setRuntimeId(this.runtimeId);
validateOmnichannelConfig(omnichannelConfig);
validateSDKConfig(chatSDKConfig);
@ -173,6 +177,7 @@ class OmnichannelChatSDK {
this.acsClientLogger?.setRequestId(this.requestId);
this.acsAdapterLogger?.setRequestId(this.requestId);
this.callingSdkLogger?.setRequestId(this.requestId);
this.amsClientLogger?.setRequestId(this.requestId);
}
/* istanbul ignore next */
@ -186,6 +191,7 @@ class OmnichannelChatSDK {
this.acsClientLogger?.setDebug(flag);
this.acsAdapterLogger?.setDebug(flag);
this.callingSdkLogger?.setDebug(flag);
this.amsClientLogger?.setDebug(flag);
}
public async initialize(optionalParams: InitializeOptionalParams = {}): Promise<ChatConfig> {
@ -210,7 +216,7 @@ class OmnichannelChatSDK {
framedMode: isBrowser(),
multiClient: true,
debug: false,
logger: undefined
logger: this.amsClientLogger as PluggableLogger
});
} else {
this.IC3Client = await this.getIC3Client();
@ -413,6 +419,7 @@ class OmnichannelChatSDK {
this.acsClientLogger?.setChatId(this.chatToken.chatId || '');
this.acsAdapterLogger?.setChatId(this.chatToken.chatId || '');
this.callingSdkLogger?.setChatId(this.chatToken.chatId || '');
this.amsClientLogger?.setChatId(this.chatToken.chatId || '');
let sessionInitOptionalParams: ISessionInitOptionalParams = {
initContext: {} as InitContext
@ -426,7 +433,7 @@ class OmnichannelChatSDK {
} else if (this.isChatReconnect && !this.chatSDKConfig.chatReconnect?.disable && !this.isPersistentChat) {
sessionInitOptionalParams.reconnectId = this.reconnectId as string;
}
if (this.liveChatConfig?.LiveWSAndLiveChatEngJoin?.msdyn_requestvisitorlocation === "true") {
const location = await getLocationInfo(this.scenarioMarker, this.chatToken.chatId as string, this.requestId);
sessionInitOptionalParams.initContext!.latitude = location.latitude;
@ -642,6 +649,9 @@ class OmnichannelChatSDK {
this.callingSdkLogger?.setRequestId(this.requestId);
this.callingSdkLogger?.setChatId('');
this.amsClientLogger?.setRequestId(this.requestId);
this.amsClientLogger?.setChatId('');
} catch (error) {
const exceptionDetails = {
response: "OCClientSessionCloseFailed"

Просмотреть файл

@ -112,6 +112,19 @@ interface CallingSDKContract {
ElapsedTimeInMilliseconds?: string;
}
interface AMSClientContract {
ChatSDKRuntimeId: string;
OrgId: string;
OrgUrl: string;
WidgetId: string;
RequestId?: string;
ChatId?: string;
Event?: string;
ExceptionDetails?: string;
ElapsedTimeInMilliseconds?: string;
AMSClientVersion: string;
}
enum Renderer {
ReactNative = 'ReactNative'
}
@ -219,6 +232,18 @@ class AriaTelemetry {
}
}
if (scenarioType == ScenarioType.AMSCLIENT) {
event = {
name: ScenarioType.AMSCLIENT,
properties: {
...AriaTelemetry.populateAMSClientBaseProperties(),
...properties,
LogLevel: LogLevel.INFO
},
priority: AWTEventPriority.High
}
}
/* istanbul ignore next */
this._debug && console.log(`[AriaTelemetry][info] ${scenarioType}`);
/* istanbul ignore next */
@ -302,6 +327,18 @@ class AriaTelemetry {
}
}
if (scenarioType == ScenarioType.AMSCLIENT) {
event = {
name: ScenarioType.AMSCLIENT,
properties: {
...AriaTelemetry.populateAMSClientBaseProperties(),
...properties,
LogLevel: LogLevel.DEBUG
},
priority: AWTEventPriority.High
}
}
/* istanbul ignore next */
this._debug && console.log(`[AriaTelemetry][debug] ${scenarioType}`);
/* istanbul ignore next */
@ -385,6 +422,18 @@ class AriaTelemetry {
}
}
if (scenarioType == ScenarioType.AMSCLIENT) {
event = {
name: ScenarioType.AMSCLIENT,
properties: {
...AriaTelemetry.populateAMSClientBaseProperties(),
...properties,
LogLevel: LogLevel.WARN
},
priority: AWTEventPriority.High
}
}
/* istanbul ignore next */
this._debug && console.log(`[AriaTelemetry][warn] ${scenarioType}`);
/* istanbul ignore next */
@ -468,6 +517,18 @@ class AriaTelemetry {
}
}
if (scenarioType == ScenarioType.AMSCLIENT) {
event = {
name: ScenarioType.AMSCLIENT,
properties: {
...AriaTelemetry.populateAMSClientBaseProperties(),
...properties,
LogLevel: LogLevel.ERROR
},
priority: AWTEventPriority.High
}
}
/* istanbul ignore next */
this._debug && console.log(`[AriaTelemetry][error] ${scenarioType}`);
/* istanbul ignore next */
@ -551,6 +612,18 @@ class AriaTelemetry {
}
}
if (scenarioType == ScenarioType.AMSCLIENT) {
event = {
name: ScenarioType.AMSCLIENT,
properties: {
...AriaTelemetry.populateAMSClientBaseProperties(),
...properties,
LogLevel: LogLevel.LOG
},
priority: AWTEventPriority.High
}
}
/* istanbul ignore next */
this._debug && console.log(`[AriaTelemetry][log]`);
/* istanbul ignore next */
@ -737,6 +810,21 @@ class AriaTelemetry {
ElapsedTimeInMilliseconds: ''
}
}
private static populateAMSClientBaseProperties(): AMSClientContract {
return {
ChatSDKRuntimeId: '',
OrgId: '',
OrgUrl: '',
WidgetId: '',
RequestId: '',
ChatId: '',
Event: '',
ExceptionDetails: '',
ElapsedTimeInMilliseconds: '',
AMSClientVersion: require('@microsoft/omnichannel-amsclient/package.json').version // eslint-disable-line @typescript-eslint/no-var-requires
}
}
}
export default AriaTelemetry;

Просмотреть файл

@ -5,6 +5,7 @@ enum ScenarioType {
ACSCLIENT = "occhatsdk_acsclientevents",
ACSADAPTER = "occhatsdk_acsadapterevents",
CALLINGSDK = "occhatsdk_callingsdkevents",
AMSCLIENT = "occhatsdk_amsclientevents",
UNDEFINED = "undefined",
}

Просмотреть файл

@ -494,6 +494,90 @@ export class CallingSDKLogger {
}
}
export class AMSClientLogger {
private debug = false;
private runtimeId = '';
private requestId = '';
private chatId = '';
private telemetry: typeof AriaTelemetry | null = null;
constructor(private omnichannelConfig: OmnichannelConfig) {
this.debug = false;
}
/* istanbul ignore next */
public setDebug(flag: boolean): void {
this.debug = flag;
}
public setRuntimeId(runtimeId: string): void {
this.runtimeId = runtimeId;
}
public setRequestId(requestId: string): void {
this.requestId = requestId;
}
public setChatId(chatId: string): void {
this.chatId = chatId;
}
public useTelemetry(telemetry: typeof AriaTelemetry): void {
/* istanbul ignore next */
this.debug && console.log(`[AMSClientLogger][useTelemetry]`);
this.telemetry = telemetry;
}
public logClientSdkTelemetryEvent(logLevel: LogLevel, event: any): void { // eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
/* istanbul ignore next */
this.debug && console.log(`[AMSClientLogger][logClientSdkTelemetryEvent][${logLevel}]`);
/* istanbul ignore next */
this.debug && console.log(event);
const baseProperties: AWTEventData["properties"] = {
ChatSDKRuntimeId: this.runtimeId,
OrgId: this.omnichannelConfig.orgId,
OrgUrl: this.omnichannelConfig.orgUrl,
WidgetId: this.omnichannelConfig.widgetId,
RequestId: this.requestId,
ChatId: this.chatId
};
const additionalProperties: AWTEventData["properties"] = {
...event,
ExceptionDetails: event.ExceptionDetails? JSON.stringify(event.ExceptionDetails): '',
};
switch(logLevel) {
case LogLevel.DEBUG:
this.telemetry?.debug({
...baseProperties,
...additionalProperties
}, ScenarioType.AMSCLIENT);
break;
case LogLevel.WARN:
this.telemetry?.warn({
...baseProperties,
...additionalProperties
}, ScenarioType.AMSCLIENT);
break;
case LogLevel.ERROR:
this.telemetry?.error({
...baseProperties,
...additionalProperties
}, ScenarioType.AMSCLIENT);
break;
case LogLevel.INFO:
default:
this.telemetry?.info({
...baseProperties,
...additionalProperties
}, ScenarioType.AMSCLIENT);
break;
}
}
}
export const createIC3ClientLogger = (omnichannelConfig: OmnichannelConfig, debug = false): IC3ClientLogger => {
const logger = new IC3ClientLogger(omnichannelConfig);
logger.setDebug(debug);
@ -522,4 +606,10 @@ export const createCallingSDKLogger = (omnichannelConfig: OmnichannelConfig, deb
const logger = new CallingSDKLogger(omnichannelConfig);
logger.setDebug(debug);
return logger;
}
export const createAMSClientLogger = (omnichannelConfig: OmnichannelConfig, debug = false): AMSClientLogger => {
const logger = new AMSClientLogger(omnichannelConfig);
logger.setDebug(debug);
return logger;
}