Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

telemetry enhancement #116

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Added

- Improve telemetry to uniformly log all errors for reconnectable chat and reconnect availability

## [0.5.6]

### Fixed

- Fix error propagation when a call to an endpoint timesout
- Fix unit tests

### Added

- Error propagation when getchattoken returns an empty dashboard

## [0.5.5]

### Security

- Uptake [axios@1.7.4](https://www.npmjs.com/package/axios/v/1.7.4)

## [0.5.3] - 2024-06-18
Expand Down
8 changes: 6 additions & 2 deletions src/Common/Enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ export enum OCSDKTelemetryEvent {
GETCHATCONFIGFSTARTED = "GetChatConfig",
GETCHATCONFIGSUCCEEDED = "GetChatConfigSucceeded",
GETCHATCONFIGFAILED = "GetChatConfigFailed",
GETRECONNECTABLECHATS = "GetReconnnectableChats",
GETRECONNECTAVAILABILITY = "GetReconnnectableAvailability",
GETRECONNECTABLECHATSSTARTED = "GetReconnnectableChatsStarted",
GETRECONNECTABLECHATSSUCCEEDED = "GetReconnnectableChatsSucceeded",
GETRECONNECTABLECHATSFAILED = "GetReconnnectableChatsFailed",
GETRECONNECTAVAILABILITYSUCCEEDED = "GetReconnnectableAvailabilitySucceeded",
GETRECONNECTAVAILABILITYSTARTED = "GetReconnnectableAvailabilityStarted",
GETRECONNECTAVAILABILITYFAILED = "GetReconnnectableAvailabilityFailed",
GETCHATTOKENSTARTED = "GetChatTokenStarted",
GETCHATTOKENSUCCEEDED = "GetChatTokenSucceeded",
GETCHATTOKENFAILED = "GetChatTokenFailed",
Expand Down
14 changes: 7 additions & 7 deletions src/SDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export default class SDK implements ISDK {
public async getReconnectableChats(reconnectableChatsParams: IReconnectableChatsParams): Promise<ReconnectMappingRecord | void> {
const timer = Timer.TIMER();
const { authenticatedUserToken } = reconnectableChatsParams;
this.logWithLogger(LogLevel.INFO, OCSDKTelemetryEvent.GETRECONNECTABLECHATS, "Get Reconnectable chat Started");
this.logWithLogger(LogLevel.INFO, OCSDKTelemetryEvent.GETRECONNECTABLECHATSSTARTED, "Get Reconnectable chat Started");

const requestPath = `/${OmnichannelEndpoints.LiveChatGetReconnectableChatsPath}/${this.omnichannelConfiguration.orgId}/${this.omnichannelConfiguration.widgetId}/${this.omnichannelConfiguration.orgId}?channelId=${this.omnichannelConfiguration.channelId}`;
const requestHeaders: StringMap = Constants.defaultHeaders;
Expand Down Expand Up @@ -451,7 +451,7 @@ export default class SDK implements ISDK {

// Resolves only if it contains reconnectable chats response which only happens on status 200
if (data) {
this.logWithLogger(LogLevel.INFO, OCSDKTelemetryEvent.GETRECONNECTABLECHATS, "Get Reconnectable Chats Succeeded and old session returned", requestId, response, elapsedTimeInMilliseconds, requestPath, method, undefined, undefined, requestHeaders);
this.logWithLogger(LogLevel.INFO, OCSDKTelemetryEvent.GETRECONNECTABLECHATSSUCCEEDED, "Get Reconnectable Chats Succeeded and old session returned", requestId, response, elapsedTimeInMilliseconds, requestPath, method, undefined, undefined, requestHeaders);
resolve(data);
return;
}
Expand All @@ -460,7 +460,7 @@ export default class SDK implements ISDK {
return;
} catch (error) {
const elapsedTimeInMilliseconds = timer.milliSecondsElapsed;
this.logWithLogger(LogLevel.ERROR, OCSDKTelemetryEvent.GETRECONNECTABLECHATS, "Get Reconnectable Chats failed", requestId, undefined, elapsedTimeInMilliseconds, requestPath, method, error, undefined, requestHeaders);
this.logWithLogger(LogLevel.ERROR, OCSDKTelemetryEvent.GETRECONNECTABLECHATSFAILED, "Get Reconnectable Chats failed", requestId, undefined, elapsedTimeInMilliseconds, requestPath, method, error, undefined, requestHeaders);
if (isExpectedAxiosError(error, Constants.axiosTimeoutErrorCode)) {
reject( new Error(this.HTTPTimeOutErrorMessage));
}
Expand All @@ -476,7 +476,7 @@ export default class SDK implements ISDK {
*/
public async getReconnectAvailability(reconnectId: string): Promise<ReconnectAvailability | void> {
const timer = Timer.TIMER();
this.logWithLogger(LogLevel.INFO, OCSDKTelemetryEvent.GETRECONNECTAVAILABILITY, "Get Reconnectable availability Started");
this.logWithLogger(LogLevel.INFO, OCSDKTelemetryEvent.GETRECONNECTAVAILABILITYSTARTED, "Get Reconnectable availability Started");

const requestPath = `/${OmnichannelEndpoints.LiveChatReconnectAvailabilityPath}/${this.omnichannelConfiguration.orgId}/${this.omnichannelConfiguration.widgetId}/${reconnectId}`;
const requestHeaders: StringMap = Constants.defaultHeaders;
Expand All @@ -500,19 +500,19 @@ export default class SDK implements ISDK {
const elapsedTimeInMilliseconds = timer.milliSecondsElapsed;
const { data } = response;
if (data) {
this.logWithLogger(LogLevel.INFO, OCSDKTelemetryEvent.GETRECONNECTAVAILABILITY, "Get Reconnect availability succeeded", undefined, response, elapsedTimeInMilliseconds, requestPath, method, undefined, undefined, requestHeaders);
this.logWithLogger(LogLevel.INFO, OCSDKTelemetryEvent.GETRECONNECTAVAILABILITYSUCCEEDED, "Get Reconnect availability succeeded", undefined, response, elapsedTimeInMilliseconds, requestPath, method, undefined, undefined, requestHeaders);

resolve(data);
return;
}
// No data found so returning null
this.logWithLogger(LogLevel.WARN, OCSDKTelemetryEvent.GETRECONNECTAVAILABILITY, "Get Reconnect availability didn't send any valid data", undefined, response, elapsedTimeInMilliseconds, requestPath, method, undefined, undefined, requestHeaders);
this.logWithLogger(LogLevel.WARN, OCSDKTelemetryEvent.GETRECONNECTAVAILABILITYSUCCEEDED, "Get Reconnect availability didn't send any valid data", undefined, response, elapsedTimeInMilliseconds, requestPath, method, undefined, undefined, requestHeaders);

resolve();
return;
} catch (error) {
const elapsedTimeInMilliseconds = timer.milliSecondsElapsed;
this.logWithLogger(LogLevel.ERROR, OCSDKTelemetryEvent.GETRECONNECTAVAILABILITY, "Get Reconnect Availability failed", undefined, undefined, elapsedTimeInMilliseconds, requestPath, method, error, undefined, requestHeaders);
this.logWithLogger(LogLevel.ERROR, OCSDKTelemetryEvent.GETRECONNECTAVAILABILITYFAILED, "Get Reconnect Availability failed", undefined, undefined, elapsedTimeInMilliseconds, requestPath, method, error, undefined, requestHeaders);
if (isExpectedAxiosError(error, Constants.axiosTimeoutErrorCode)) {
reject( new Error(this.HTTPTimeOutErrorMessage));
}
Expand Down
Loading