Skip to content
Draft
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
36 changes: 36 additions & 0 deletions packages/@webex/internal-plugin-metrics/src/new-metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import CallDiagnosticMetrics from './call-diagnostic/call-diagnostic-metrics';
import BehavioralMetrics from './behavioral-metrics';
import OperationalMetrics from './operational-metrics';
import BusinessMetrics from './business-metrics';
import PreLoginMetrics from './prelogin-metrics';
import {
RecursivePartial,
MetricEventProduct,
Expand Down Expand Up @@ -45,6 +46,7 @@ class Metrics extends WebexPlugin {
behavioralMetrics: BehavioralMetrics;
operationalMetrics: OperationalMetrics;
businessMetrics: BusinessMetrics;
preLoginMetrics: PreLoginMetrics;
isReady = false;

/**
Expand Down Expand Up @@ -87,6 +89,8 @@ class Metrics extends WebexPlugin {
this.webex.once('ready', () => {
// @ts-ignore
this.callDiagnosticMetrics = new CallDiagnosticMetrics({}, {parent: this.webex});
// @ts-ignore
this.preLoginMetrics = new PreLoginMetrics({}, {parent: this.webex});
this.isReady = true;
this.setDelaySubmitClientEvents({
shouldDelay: this.delaySubmitClientEvents,
Expand Down Expand Up @@ -251,6 +255,38 @@ class Metrics extends WebexPlugin {
return this.businessMetrics.submitBusinessEvent({name, payload, table, metadata});
}

/**
* Call Analyzer: Pre-Login Event
* @param args
*/
SubmitPreLoginEvent({
name,
preLoginId,
payload,
metadata,
}: {
name: string;
preLoginId: string;
payload: EventPayload;
metadata?: EventPayload;
}): Promise<void> {
if (!this.isReady) {
// @ts-ignore
this.webex.logger.log(
`NewMetrics: @submitPreLoginEvent. Attempted to submit before webex.ready: ${name}`
);

return Promise.resolve();
}

return this.preLoginMetrics.submitPreLoginEvent({
name,
preLoginId,
payload,
metadata,
});
}

/**
* Call Analyzer: Media Quality Event
* @param args
Expand Down
90 changes: 90 additions & 0 deletions packages/@webex/internal-plugin-metrics/src/prelogin-metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import GenericMetrics from './generic-metrics';
import {EventPayload, Table} from './metrics.types';
import PreLoginMetricsBatcher from './prelogin-metrics-batcher';

/**
* Builds a formatted event object for metrics submission.
* @param {string} name - Metric name
* @param {string} preLoginId - Pre-login user identifier
* @param {EventPayload} payload - Metric payload data
* @param {EventPayload} metadata - Additional metadata to include in the event
* @returns {object} Formatted metrics event object with type, eventPayload, and timestamp
*/
function buildEvent(
name: string,
preLoginId: string,
payload: EventPayload,
metadata: EventPayload
) {
const payloadWithPreLoginId = {...payload, preLoginId};

return {
type: ['business'],
eventPayload: {
key: name,
client_timestamp: new Date().toISOString(),
preLoginId,
...metadata,
value: payloadWithPreLoginId,
},
};
}

/**
* @description Util class to handle PreLogin Metrics
* @export
* @class PreLoginMetrics
*/
export default class PreLoginMetrics extends GenericMetrics {
// @ts-ignore
private preLoginMetricsBatcher: PreLoginMetricsBatcher;

/**
* Constructor
* @param {any[]} args - Constructor arguments
* @constructor
*/
constructor(...args) {
super(...args);
// @ts-ignore
this.logger = this.webex.logger;
// @ts-ignore
this.preLoginMetricsBatcher = new PreLoginMetricsBatcher({}, {parent: this.webex});
}

/**
* Submit a business metric to our metrics endpoint.
* Routes to the correct table with the correct schema payload by table.
* @see https://confluence-eng-gpk2.cisco.com/conf/display/WAP/Business+metrics++-%3E+ROMA
* @param {Object} options - The options object
* @param {string} options.name - Name of the metric
* @param {string} options.preLoginId - ID to identify pre-login user
* @param {EventPayload} options.payload - User payload of the metric
* @param {EventPayload} [options.metadata] - Optional metadata to include outside of eventPayload.value
* @returns {Promise<void>} Promise that resolves when the metric is submitted
*/
public submitPreLoginEvent({
name,
preLoginId,
payload,
metadata,
}: {
name: string;
preLoginId: string;
payload: EventPayload;
metadata?: EventPayload;
}): Promise<void> {
if (!metadata) {
metadata = {};
}
if (!metadata.appType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this , rather make sure agent desktop sends this, sdk or other clients might use this in future

metadata.appType = 'Web Client';
}

const finalEvent = buildEvent(name, preLoginId, payload, metadata);

this.preLoginMetricsBatcher.savePreLoginId(preLoginId);

return this.preLoginMetricsBatcher.request(finalEvent);
}
}
Loading