@nsshunt/stsobservability 1.0.41 → 1.0.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,14 +17,14 @@ var __privateWrapper = (obj, member, setter, getter) => ({
17
17
  return __privateGet(obj, member, getter);
18
18
  }
19
19
  });
20
- var _a, _label, _options, _data, _val, _interval, _timeoutComputeVelocity, _lastVelocity, _delta, _maxVelocity, _timerInterval, _copy, _velocity, _velocityVal, _valStack, _averageValStack, _maxAverageValStack, _maxAverageIterations, _valStackMaxLength, _valStackAverage, _timeStamp, _maxTimeDiff, _vaTimeDiff, _velocityTimeDiff, _autoComputeVelocity, _autoComputeVelocityTimeout, _countDiff, _timeDiff, _deltaCountDiff, _deltaTimeDif, _minTimeForReporting, _averageVelocity, _InstrumentVelocity_instances, ComputeVelocityByTimeDiff_fn, ComputeVelocity_fn, SetupAutoComputeVelocity_fn, GetVelocityStackAverage_fn, GetVal_fn, SetVal_fn, GetVelocity_fn, GetMaxVelocity_fn, GetDelta_fn, GetTimeStamp_fn, GetCountDiff_fn, GetTimeDiff_fn, GetDeltaCountDiff_fn, GetDeltaTimeDif_fn, GetAverageVelocity_fn, _histogramData, _val2, _copy2, _InstrumentHistogram_instances, GetVal_fn2, SetVal_fn2, GetHistogramData_fn, SetHistogramData_fn, _messages, _readPos, _maxSize, _copy3, _useLatestMessages, _consoleLogging, _instrumentLogging, _winstonLogging, _stsLogger, _InstrumentLog_instances, DumpToConsole_fn, GetVal_fn3, SetVal_fn3, _start, _copy4, _pauseVal, _InstrumentTimerGauge_instances, GetVal_fn4, SetVal_fn4, _val3, _maxval, _lastObservedValue, _timeSeriesList, _maxSampleSize, _timerInterval2, _observer, _min, _max, _observations, _total, _copy5, _InstrumentGauge_instances, GetVal_fn5, SetVal_fn5, GetMin_fn, GetMax_fn, GetAverage_fn, GetAndResetMaxVal_fn, NumberCompare_fn, GetPercentileData_fn, _val4, _copy6, _InstrumentObject_instances, GetVal_fn6, SetVal_fn6, _tinyEmitter, _RequestCompleted, _instruments, _inPublish, _observer2, _publishState, _PublishInstrumentController_instances, GetInstrument_fn, ProcessTelemetryCommand_fn, CreateInstrument_fn, CreateInstruments_fn, GetPayloadData_fn, PublishTimeoutLoop_fn, UpdateState_fn, _httpsAgent, _kafkaLog, _maxLogLength, _socketSubscribeKeepAlive, _options2, _ObservabilityRESTAPISubscriber_instances, LogDebugMessage_fn, LogErrorMessage_fn, InvokeRESTAPI_fn, _GetData, SetupTimeout_fn, AddKeepAlive_fn, RemoveKeepAlive_fn, _messageWithAckPayloadRecords, _socket, _maxReties, _timeoutValue, _options3, _SocketIoMessageSender_instances, LogDebugMessage_fn2, GetSubscribeKeepAliveAckEventName_fn, _socketSubscribeKeepAlive2, _socket2, _options4, _socketIoMessageSender, _ObservabilitySocketIOSubscriber_instances, LogDebugMessage_fn3, LogErrorMessage_fn2, AddKeepAlive_fn2, RemoveKeepAlive_fn2, _observabilitySocketIOSubscriber, _subscriptions, _kafkaHelper, _serviceModel, _agentModel, _lambdaModel, _options5, _ObservabilitySubscriptionManager_instances, LogDebugMessage_fn4, LogErrorMessage_fn3, _options6, _sockets, _httpsAgent2, _SocketIoClientHelper_instances, LogDebugMessage_fn5, LogErrorMessage_fn4, EstablishSocketConnect_fn;
20
+ var _a, _label, _options, _data, _val, _interval, _timeoutComputeVelocity, _lastVelocity, _delta, _maxVelocity, _timerInterval, _copy, _velocity, _velocityVal, _valStack, _averageValStack, _maxAverageValStack, _maxAverageIterations, _valStackMaxLength, _valStackAverage, _timeStamp, _maxTimeDiff, _vaTimeDiff, _velocityTimeDiff, _autoComputeVelocity, _autoComputeVelocityTimeout, _countDiff, _timeDiff, _deltaCountDiff, _deltaTimeDif, _minTimeForReporting, _averageVelocity, _InstrumentVelocity_instances, ComputeVelocityByTimeDiff_fn, ComputeVelocity_fn, SetupAutoComputeVelocity_fn, GetVelocityStackAverage_fn, GetVal_fn, SetVal_fn, GetVelocity_fn, GetMaxVelocity_fn, GetDelta_fn, GetTimeStamp_fn, GetCountDiff_fn, GetTimeDiff_fn, GetDeltaCountDiff_fn, GetDeltaTimeDif_fn, GetAverageVelocity_fn, _histogramData, _val2, _copy2, _InstrumentHistogram_instances, GetVal_fn2, SetVal_fn2, GetHistogramData_fn, SetHistogramData_fn, _messages, _readPos, _maxSize, _copy3, _useLatestMessages, _consoleLogging, _instrumentLogging, _winstonLogging, _stsLogger, _InstrumentLog_instances, DumpToConsole_fn, GetVal_fn3, SetVal_fn3, _start, _copy4, _pauseVal, _InstrumentTimerGauge_instances, GetVal_fn4, SetVal_fn4, _val3, _maxval, _lastObservedValue, _timeSeriesList, _maxSampleSize, _timerInterval2, _observer, _min, _max, _observations, _total, _copy5, _InstrumentGauge_instances, GetVal_fn5, SetVal_fn5, GetMin_fn, GetMax_fn, GetAverage_fn, GetAndResetMaxVal_fn, NumberCompare_fn, GetPercentileData_fn, _val4, _copy6, _InstrumentObject_instances, GetVal_fn6, SetVal_fn6, _tinyEmitter, _RequestCompleted, _httpsAgent, _inPublish, _observer2, _publishState, _publisherTransport, _PublishInstruments_instances, PublishTimeoutLoop_fn, UpdateState_fn, _instruments, _worker, _publisher, _PublishInstrumentController_instances, GetInstrument_fn, ProcessTelemetryCommand_fn, CreateInstrument_fn, CreateInstruments_fn, _kafkaLog, _maxLogLength, _socketSubscribeKeepAlive, _options2, _ObservabilityRESTAPISubscriber_instances, LogDebugMessage_fn, LogErrorMessage_fn, InvokeRESTAPI_fn, _GetData, SetupTimeout_fn, AddKeepAlive_fn, RemoveKeepAlive_fn, _messageWithAckPayloadRecords, _socket, _maxReties, _timeoutValue, _options3, _SocketIoMessageSender_instances, LogDebugMessage_fn2, GetSubscribeKeepAliveAckEventName_fn, _socketSubscribeKeepAlive2, _socket2, _options4, _socketIoMessageSender, _ObservabilitySocketIOSubscriber_instances, LogDebugMessage_fn3, LogErrorMessage_fn2, AddKeepAlive_fn2, RemoveKeepAlive_fn2, _observabilitySocketIOSubscriber, _subscriptions, _kafkaHelper, _serviceModel, _agentModel, _lambdaModel, _options5, _ObservabilitySubscriptionManager_instances, LogDebugMessage_fn4, LogErrorMessage_fn3, _options6, _sockets, _httpsAgent2, _SocketIoClientHelper_instances, LogDebugMessage_fn5, LogErrorMessage_fn4, EstablishSocketConnect_fn;
21
21
  import _cloneDeep from "lodash.clonedeep";
22
22
  import isNode from "detect-node";
23
23
  import { STSOptionsBase } from "@nsshunt/stsutils";
24
24
  import { TinyEmitter } from "tiny-emitter";
25
- import { inject } from "vue";
26
25
  import https from "node:https";
27
26
  import axios from "axios";
27
+ import { inject } from "vue";
28
28
  import { io } from "socket.io-client";
29
29
  var Gauge = /* @__PURE__ */ ((Gauge2) => {
30
30
  Gauge2["ACTIVE_REQUEST_GAUGE"] = "a";
@@ -3898,343 +3898,6 @@ chalk.stderr = Chalk({ level: stderrColor ? stderrColor.level : 0 });
3898
3898
  chalk.stderr.supportsColor = stderrColor;
3899
3899
  var source = chalk;
3900
3900
  const chalk$1 = /* @__PURE__ */ getDefaultExportFromCjs(source);
3901
- var ePublishState = /* @__PURE__ */ ((ePublishState2) => {
3902
- ePublishState2[ePublishState2["init"] = 0] = "init";
3903
- ePublishState2[ePublishState2["started"] = 1] = "started";
3904
- ePublishState2[ePublishState2["stopping"] = 2] = "stopping";
3905
- return ePublishState2;
3906
- })(ePublishState || {});
3907
- const _PublishInstrumentController = class _PublishInstrumentController extends STSOptionsBase {
3908
- constructor(options) {
3909
- super(options);
3910
- __privateAdd(this, _PublishInstrumentController_instances);
3911
- __privateAdd(this, _instruments, {});
3912
- __privateAdd(this, _inPublish, false);
3913
- __privateAdd(this, _observer2, null);
3914
- __privateAdd(this, _publishState, 0);
3915
- __publicField(this, "LogEx", (message) => {
3916
- this.UpdateInstrument(Gauge.LOGGER, {
3917
- LogMessage: message
3918
- });
3919
- });
3920
- __privateMethod(this, _PublishInstrumentController_instances, UpdateState_fn).call(this, 0, "constructor()");
3921
- this.SetupInstrumentation();
3922
- this.StartPublish();
3923
- }
3924
- get options() {
3925
- return super.options;
3926
- }
3927
- async Publish() {
3928
- if (__privateGet(this, _inPublish)) {
3929
- return false;
3930
- }
3931
- try {
3932
- __privateSet(this, _inPublish, true);
3933
- if (Object.keys(__privateGet(this, _instruments)).length > 0) {
3934
- const instrumentPayload = __privateMethod(this, _PublishInstrumentController_instances, GetPayloadData_fn).call(this, this.options.processContext, __privateGet(this, _instruments));
3935
- return await this.options.publisherTransport.Publish(instrumentPayload);
3936
- } else {
3937
- return true;
3938
- }
3939
- } catch (error) {
3940
- return false;
3941
- } finally {
3942
- __privateSet(this, _inPublish, false);
3943
- }
3944
- }
3945
- async StartPublish() {
3946
- if (__privateGet(this, _publishState) !== 0) {
3947
- this.options.logger.debug(chalk$1.yellow(`StartPublish:${this.options.processContext.nid}: StartPublish called when not currently in the init state. Current State: [${__privateGet(this, _publishState)}]`));
3948
- return false;
3949
- }
3950
- __privateMethod(this, _PublishInstrumentController_instances, UpdateState_fn).call(this, 1, "StartPublish()");
3951
- __privateMethod(this, _PublishInstrumentController_instances, PublishTimeoutLoop_fn).call(this, this.options.publishInterval);
3952
- return true;
3953
- }
3954
- async EndPublish() {
3955
- if (__privateGet(this, _publishState) !== 1) {
3956
- this.options.logger.debug(chalk$1.yellow(`EndPublish:${this.options.processContext.nid}: EndPublish called when not within the started state. Current State: [${__privateGet(this, _publishState)}]`));
3957
- return false;
3958
- }
3959
- __privateMethod(this, _PublishInstrumentController_instances, UpdateState_fn).call(this, 2, "EndPublish() (1)");
3960
- if (__privateGet(this, _observer2) !== null) {
3961
- clearInterval(__privateGet(this, _observer2));
3962
- __privateSet(this, _observer2, null);
3963
- await this.Publish();
3964
- }
3965
- await this.options.publisherTransport.Close();
3966
- __privateMethod(this, _PublishInstrumentController_instances, UpdateState_fn).call(this, 0, "EndPublish() (2)");
3967
- return true;
3968
- }
3969
- SetupInstrumentation() {
3970
- if (!this.options.instrumentDefinitions) {
3971
- this.options.logger.debug(chalk$1.yellow(`SetupInstrumentation:${this.options.processContext.nid}: No instrument(s) defined within supplied options.`));
3972
- return;
3973
- }
3974
- if (!this.options.processContext) {
3975
- this.options.logger.debug(chalk$1.yellow(`SetupInstrumentation: No context defined within supplied options.`));
3976
- return;
3977
- }
3978
- __privateMethod(this, _PublishInstrumentController_instances, CreateInstruments_fn).call(this, this.options.instrumentDefinitions);
3979
- }
3980
- /**
3981
- * Check if an instrument exists within the managed instrument collection
3982
- * @param instrumentName
3983
- * @returns
3984
- */
3985
- InstrumentExists(instrumentName) {
3986
- if (__privateGet(this, _instruments)[instrumentName]) {
3987
- return true;
3988
- }
3989
- return false;
3990
- }
3991
- /**
3992
- * Update instrument telemetry.
3993
- * @param instrumentName
3994
- * @param telemetry
3995
- */
3996
- UpdateInstrument(instrumentName, telemetry) {
3997
- if (__privateGet(this, _instruments)[instrumentName]) {
3998
- __privateMethod(this, _PublishInstrumentController_instances, ProcessTelemetryCommand_fn).call(this, instrumentName, telemetry);
3999
- } else {
4000
- this.options.logger.debug(chalk$1.red(`UpdateInstrument:${this.options.processContext.nid}: Attempted to UpdateInstrument before initialised.`));
4001
- }
4002
- }
4003
- /**
4004
- * Add additional instrument publishers. Usually invoked when adding workers to the app and/or async runners within a worker.
4005
- * @param processContext
4006
- * @returns Returns the newly created PublishInstrumentController
4007
- */
4008
- AddPublishInstrumentController(processContext) {
4009
- const options = { ...this.options };
4010
- options.processContext = processContext;
4011
- return new _PublishInstrumentController(options);
4012
- }
4013
- /*
4014
- #GetHttpAgentInstruments(): InstrumentDefinitions {
4015
- if (isNode) {
4016
- return [ ];
4017
- } else {
4018
- return [
4019
- [ Gauge.REQUEST_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Total number of requests serviced
4020
- [ Gauge.ERROR_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ],
4021
- [ Gauge.RETRY_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ],
4022
- [ Gauge.AUTHENTICATION_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Total number of new token requests
4023
- [ Gauge.AUTHENTICATION_ERROR_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Total number of new token requests errors
4024
- [ Gauge.AUTHENTICATION_RETRY_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Total number of new token requests retries
4025
- [ Gauge.ACTIVE_REQUEST_GAUGE, GaugeTypes.INSTRUMENT_GAUGE, { // Total number of runners (in-flight) requests
4026
- interval: this.options.instrumentationObservationInterval,
4027
- sampleSize: this.options.instrumentationTimeWindow } as InstrumentGaugeOptions],
4028
- [ Gauge.DURATION_GAUGE, GaugeTypes.INSTRUMENT_GAUGE, { // Duration of latest http(s) request.
4029
- interval: this.options.instrumentationObservationInterval,
4030
- sampleSize: this.options.instrumentationTimeWindow } as InstrumentGaugeOptions],
4031
- [ Gauge.DURATION_HISTOGRAM_GAUGE, GaugeTypes.INSTRUMENT_HISTOGRAM ],
4032
- [ Gauge.VELOCITY_GAUGE, GaugeTypes.INSTRUMENT_VELOCITY ], // Requests per second
4033
- [ Gauge.CORE_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Thread count (for http agents)
4034
- [ Gauge.LATENCY_GAUGE, GaugeTypes.INSTRUMENT_GAUGE, {
4035
- interval: this.options.instrumentationObservationInterval,
4036
- sampleSize: this.options.instrumentationTimeWindow } as InstrumentGaugeOptions],
4037
- [ Gauge.LATENCY_HISTOGRAM_GAUGE, GaugeTypes.INSTRUMENT_HISTOGRAM ],
4038
- [ Gauge.CHILD_COUNT, GaugeTypes.INSTRUMENT_GAUGE ], // Number of async runners idle or running
4039
- ]
4040
- }
4041
- }
4042
- */
4043
- /*
4044
- #GetHttpNodeServerInstruments(): InstrumentDefinitions {
4045
- if (isNode) {
4046
- if (this.options.httpServer === true) {
4047
- return [
4048
- [ Gauge.REQUEST_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Total number of requests serviced
4049
- [ Gauge.AUTHENTICATION_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Total number of new token requests
4050
- [ Gauge.AUTHENTICATION_ERROR_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Total number of new token requests errors
4051
- [ Gauge.AUTHENTICATION_RETRY_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Total number of new token requests retries
4052
-
4053
- [ Gauge.ACTIVE_REQUEST_GAUGE, GaugeTypes.INSTRUMENT_GAUGE, {
4054
- interval: this.options.instrumentationObservationInterval,
4055
- sampleSize: this.options.instrumentationTimeWindow } as InstrumentGaugeOptions],
4056
- [ Gauge.DURATION_GAUGE, GaugeTypes.INSTRUMENT_GAUGE, {
4057
- interval: this.options.instrumentationObservationInterval,
4058
- sampleSize: this.options.instrumentationTimeWindow } as InstrumentGaugeOptions],
4059
- [ Gauge.DURATION_HISTOGRAM_GAUGE, GaugeTypes.INSTRUMENT_HISTOGRAM ],
4060
- [ Gauge.CONNECTION_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE, {
4061
- interval: this.options.instrumentationObservationInterval,
4062
- sampleSize: this.options.instrumentationTimeWindow } as InstrumentGaugeOptions],
4063
-
4064
- [ Gauge.CONNECTION_POOL_TOTAL_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ],
4065
- [ Gauge.CONNECTION_POOL_IDLE_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ],
4066
- [ Gauge.CONNECTION_POOL_WAITING_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ],
4067
- [ Gauge.VELOCITY_GAUGE, GaugeTypes.INSTRUMENT_VELOCITY ], // Requests per second
4068
- [ Gauge.ERROR_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ],
4069
- [ Gauge.RETRY_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ],
4070
- [ Gauge.LATENCY_GAUGE, GaugeTypes.INSTRUMENT_GAUGE, {
4071
- interval: this.options.instrumentationObservationInterval,
4072
- sampleSize: this.options.instrumentationTimeWindow } as InstrumentGaugeOptions],
4073
- [ Gauge.LATENCY_HISTOGRAM_GAUGE, GaugeTypes.INSTRUMENT_HISTOGRAM ],
4074
- [ Gauge.CORE_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ]
4075
- ]
4076
- } else {
4077
- return [ ];
4078
- }
4079
- } else {
4080
- return [ ];
4081
- }
4082
- }
4083
- */
4084
- /*
4085
- #GetAdditionalInstruments(): InstrumentDefinitions {
4086
- if (this.options.instrumentDefinitions) {
4087
- return this.options.instrumentDefinitions;
4088
- } else {
4089
- return [ ];
4090
- }
4091
- }
4092
- */
4093
- /*
4094
- #SetupInstruments() {
4095
- this.options.logger.debug(chalk.yellow(`#SetupInstruments:${this.options.processContext.nid}: Started`));
4096
-
4097
- const standardInstruments: InstrumentDefinitions = [
4098
- [ Gauge.TIMER_GAUGE, GaugeTypes.INSTRUMENT_TIMER ],
4099
- [ Gauge.LOGGER, GaugeTypes.INSTRUMENT_LOG, {
4100
- consoleLogging: this.options.consoleLogging,
4101
- instrumentLogging: this.options.instrumentLogging } as InstrumentLogOptions],
4102
- [ Gauge.NETWORK_RX_GAUGE , GaugeTypes.INSTRUMENT_VELOCITY ],
4103
- [ Gauge.NETWORK_TX_GAUGE, GaugeTypes.INSTRUMENT_VELOCITY ]
4104
- ];
4105
-
4106
- let nodeStandardInstruments: InstrumentDefinitions = [ ];
4107
- if (isNode) {
4108
- nodeStandardInstruments = [
4109
- [ Gauge.CPU_LOAD_GAUGE, GaugeTypes.INSTRUMENT_GAUGE, {
4110
- interval: this.options.instrumentationObservationInterval,
4111
- sampleSize: this.options.instrumentationTimeWindow } as InstrumentGaugeOptions],
4112
- [ Gauge.OBJECT_GAUGE, GaugeTypes.INSTRUMENT_OBJECT, {
4113
- label:'InstrumentObjectMaster' } as InstrumentObjectOptions]
4114
- ];
4115
- }
4116
-
4117
- const instruments: InstrumentDefinitions = [
4118
- ...standardInstruments,
4119
- ...nodeStandardInstruments,
4120
- ...this.#GetHttpAgentInstruments(),
4121
- ...this.#GetHttpNodeServerInstruments(),
4122
- ...this.#GetAdditionalInstruments()
4123
- ]
4124
-
4125
- this.options.logger.debug(chalk.green(`#SetupInstruments:${this.options.processContext.nid}: Completed`));
4126
- }
4127
- */
4128
- };
4129
- _instruments = new WeakMap();
4130
- _inPublish = new WeakMap();
4131
- _observer2 = new WeakMap();
4132
- _publishState = new WeakMap();
4133
- _PublishInstrumentController_instances = new WeakSet();
4134
- GetInstrument_fn = function(instrumentName) {
4135
- return __privateGet(this, _instruments)[instrumentName];
4136
- };
4137
- ProcessTelemetryCommand_fn = function(instrumentName, telemetry) {
4138
- const instrument = __privateMethod(this, _PublishInstrumentController_instances, GetInstrument_fn).call(this, instrumentName);
4139
- if (instrument) {
4140
- instrument.ProcessTelemetry(telemetry);
4141
- }
4142
- };
4143
- // Instrument factory
4144
- CreateInstrument_fn = function(instrumentType, options) {
4145
- let instrument;
4146
- switch (instrumentType) {
4147
- case GaugeTypes.INSTRUMENT_GAUGE:
4148
- instrument = new InstrumentGauge(options);
4149
- break;
4150
- case GaugeTypes.INSTRUMENT_HISTOGRAM:
4151
- instrument = new InstrumentHistogram(options);
4152
- break;
4153
- case GaugeTypes.INSTRUMENT_LOG:
4154
- instrument = new InstrumentLog(options);
4155
- break;
4156
- case GaugeTypes.INSTRUMENT_OBJECT:
4157
- instrument = new InstrumentObject(options);
4158
- break;
4159
- case GaugeTypes.INSTRUMENT_TIMER:
4160
- instrument = new InstrumentTimerGauge(options);
4161
- break;
4162
- case GaugeTypes.INSTRUMENT_VELOCITY:
4163
- instrument = new InstrumentVelocity(options);
4164
- break;
4165
- default:
4166
- throw new Error(`Gauge type: [${instrumentType} not known.]`);
4167
- }
4168
- return instrument;
4169
- };
4170
- CreateInstruments_fn = function(payload) {
4171
- payload.forEach((instrumentDefinition) => {
4172
- const g = instrumentDefinition[0];
4173
- const gt = instrumentDefinition[1];
4174
- const instrumentBaseOptions = instrumentDefinition[2];
4175
- const instrument = __privateMethod(this, _PublishInstrumentController_instances, CreateInstrument_fn).call(this, gt, instrumentBaseOptions);
4176
- __privateGet(this, _instruments)[g] = instrument;
4177
- });
4178
- };
4179
- GetPayloadData_fn = function(context, instruments) {
4180
- const payloadInstruments = {};
4181
- for (const [key, value] of Object.entries(instruments)) {
4182
- if (value instanceof InstrumentLog) {
4183
- payloadInstruments[key] = { ...value.WithUseLatestMessages(true) };
4184
- } else {
4185
- payloadInstruments[key] = { ...value };
4186
- }
4187
- }
4188
- return {
4189
- context,
4190
- instruments: payloadInstruments
4191
- };
4192
- };
4193
- PublishTimeoutLoop_fn = function(publishInterval) {
4194
- __privateSet(this, _observer2, setTimeout(async () => {
4195
- const start = performance.now();
4196
- await this.Publish();
4197
- const end = performance.now();
4198
- const diff = end - start;
4199
- if (__privateGet(this, _publishState) === 1) {
4200
- __privateMethod(this, _PublishInstrumentController_instances, PublishTimeoutLoop_fn).call(this, this.options.publishInterval - diff);
4201
- }
4202
- }, publishInterval));
4203
- if (isNode) __privateGet(this, _observer2).unref();
4204
- };
4205
- UpdateState_fn = function(newState, comment) {
4206
- const previousState = __privateGet(this, _publishState);
4207
- __privateSet(this, _publishState, newState);
4208
- this.options.logger.debug(chalk$1.yellow(`#UpdateState:${this.options.processContext.nid}: Previous State: [${previousState}]. Current State: [${__privateGet(this, _publishState)}]. Comment: [${comment}]`));
4209
- };
4210
- let PublishInstrumentController = _PublishInstrumentController;
4211
- const STSInstrumentControllerPluginKey = Symbol("instrumentController");
4212
- const GetSTSInstrumentControllerPluginKey = () => STSInstrumentControllerPluginKey;
4213
- const CompareSTSInstrumentControllerPluginKey = (val) => val === STSInstrumentControllerPluginKey;
4214
- const useSTSInstrumentControllerPlugin = () => inject(STSInstrumentControllerPluginKey);
4215
- const GetSTSInstrumentController = (app) => {
4216
- return app.config.globalProperties.$sts[STSInstrumentControllerPluginKey];
4217
- };
4218
- const STSInstrumentControllerPlugin = {
4219
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4220
- install: (app, options) => {
4221
- options.logger.debug(chalk$1.yellow(`STSInstrumentControllerPlugin:install:Start`));
4222
- const aic = new PublishInstrumentController(options);
4223
- if (!app.config.globalProperties.$sts) {
4224
- options.logger.debug(chalk$1.cyan(`STSInstrumentControllerPlugin:install: [app.config.globalProperties.$sts] does not exist.`));
4225
- app.config.globalProperties.$sts = {};
4226
- options.logger.debug(chalk$1.cyan(`STSInstrumentControllerPlugin:install: created empty [app.config.globalProperties.$sts].`));
4227
- } else {
4228
- options.logger.debug(chalk$1.cyan(`STSInstrumentControllerPlugin:install: [app.config.globalProperties.$sts] already exists.`));
4229
- }
4230
- app.config.globalProperties.$sts.aic = aic;
4231
- app.config.globalProperties.$sts[STSInstrumentControllerPluginKey] = aic;
4232
- options.logger.debug(chalk$1.cyan(`STSInstrumentControllerPlugin:install: AgentInstrumentController installed into [app.config.globalProperties.$sts] using: [${String(STSInstrumentControllerPluginKey)}].`));
4233
- app.provide(STSInstrumentControllerPluginKey, aic);
4234
- options.logger.debug(chalk$1.cyan(`STSInstrumentControllerPlugin:install: AgentInstrumentController installed into 'provide' using: [${String(STSInstrumentControllerPluginKey)}].`));
4235
- options.logger.debug(chalk$1.green(`STSInstrumentControllerPlugin:install:End`));
4236
- }
4237
- };
4238
3901
  function utf8Count(str) {
4239
3902
  var strLength = str.length;
4240
3903
  var byteLength = 0;
@@ -4963,6 +4626,289 @@ class PublishTransportRESTServer extends STSOptionsBase {
4963
4626
  }
4964
4627
  }
4965
4628
  _httpsAgent = new WeakMap();
4629
+ class PublishInstruments extends STSOptionsBase {
4630
+ constructor(options) {
4631
+ super(options);
4632
+ __privateAdd(this, _PublishInstruments_instances);
4633
+ __privateAdd(this, _inPublish, false);
4634
+ __privateAdd(this, _observer2, null);
4635
+ __privateAdd(this, _publishState, 0);
4636
+ __privateAdd(this, _publisherTransport, null);
4637
+ __privateSet(this, _publisherTransport, null);
4638
+ switch (options.publishTransportBaseOptions.transportType) {
4639
+ case TransportType.RESTAPI:
4640
+ __privateSet(this, _publisherTransport, new PublishTransportRESTServer(options.publishTransportBaseOptions));
4641
+ break;
4642
+ }
4643
+ __privateMethod(this, _PublishInstruments_instances, UpdateState_fn).call(this, 0, "constructor()");
4644
+ }
4645
+ get options() {
4646
+ return super.options;
4647
+ }
4648
+ async Publish() {
4649
+ if (__privateGet(this, _inPublish)) {
4650
+ return false;
4651
+ }
4652
+ if (__privateGet(this, _publisherTransport)) {
4653
+ try {
4654
+ __privateSet(this, _inPublish, true);
4655
+ const instrumentPayload = this.options.publishInstrumentController.GetPayloadData();
4656
+ return await __privateGet(this, _publisherTransport).Publish(instrumentPayload);
4657
+ } catch (error) {
4658
+ return false;
4659
+ } finally {
4660
+ __privateSet(this, _inPublish, false);
4661
+ }
4662
+ } else {
4663
+ return false;
4664
+ }
4665
+ }
4666
+ async StartPublish() {
4667
+ if (__privateGet(this, _publishState) !== 0) {
4668
+ this.options.logger.debug(chalk$1.yellow(`StartPublish:${this.options.processContext.nid}: StartPublish called when not currently in the init state. Current State: [${__privateGet(this, _publishState)}]`));
4669
+ return false;
4670
+ }
4671
+ __privateMethod(this, _PublishInstruments_instances, UpdateState_fn).call(this, 1, "StartPublish()");
4672
+ __privateMethod(this, _PublishInstruments_instances, PublishTimeoutLoop_fn).call(this, this.options.publishInterval);
4673
+ return true;
4674
+ }
4675
+ async EndPublish() {
4676
+ if (__privateGet(this, _publishState) !== 1) {
4677
+ this.options.logger.debug(chalk$1.yellow(`EndPublish:${this.options.processContext.nid}: EndPublish called when not within the started state. Current State: [${__privateGet(this, _publishState)}]`));
4678
+ return false;
4679
+ }
4680
+ __privateMethod(this, _PublishInstruments_instances, UpdateState_fn).call(this, 2, "EndPublish() (1)");
4681
+ if (__privateGet(this, _observer2) !== null) {
4682
+ clearInterval(__privateGet(this, _observer2));
4683
+ __privateSet(this, _observer2, null);
4684
+ await this.Publish();
4685
+ }
4686
+ if (__privateGet(this, _publisherTransport)) {
4687
+ await __privateGet(this, _publisherTransport).Close();
4688
+ }
4689
+ __privateMethod(this, _PublishInstruments_instances, UpdateState_fn).call(this, 0, "EndPublish() (2)");
4690
+ return true;
4691
+ }
4692
+ }
4693
+ _inPublish = new WeakMap();
4694
+ _observer2 = new WeakMap();
4695
+ _publishState = new WeakMap();
4696
+ _publisherTransport = new WeakMap();
4697
+ _PublishInstruments_instances = new WeakSet();
4698
+ PublishTimeoutLoop_fn = function(publishInterval) {
4699
+ __privateSet(this, _observer2, setTimeout(async () => {
4700
+ const start = performance.now();
4701
+ await this.Publish();
4702
+ const end = performance.now();
4703
+ const diff = end - start;
4704
+ if (__privateGet(this, _publishState) === 1) {
4705
+ __privateMethod(this, _PublishInstruments_instances, PublishTimeoutLoop_fn).call(this, this.options.publishInterval - diff);
4706
+ }
4707
+ }, publishInterval));
4708
+ if (isNode) __privateGet(this, _observer2).unref();
4709
+ };
4710
+ UpdateState_fn = function(newState, comment) {
4711
+ const previousState = __privateGet(this, _publishState);
4712
+ __privateSet(this, _publishState, newState);
4713
+ this.options.logger.debug(chalk$1.yellow(`#UpdateState:${this.options.processContext.nid}: Previous State: [${previousState}]. Current State: [${__privateGet(this, _publishState)}]. Comment: [${comment}]`));
4714
+ };
4715
+ var ePublishState = /* @__PURE__ */ ((ePublishState2) => {
4716
+ ePublishState2[ePublishState2["init"] = 0] = "init";
4717
+ ePublishState2[ePublishState2["started"] = 1] = "started";
4718
+ ePublishState2[ePublishState2["stopping"] = 2] = "stopping";
4719
+ return ePublishState2;
4720
+ })(ePublishState || {});
4721
+ const _PublishInstrumentController = class _PublishInstrumentController extends STSOptionsBase {
4722
+ constructor(options) {
4723
+ super(options);
4724
+ __privateAdd(this, _PublishInstrumentController_instances);
4725
+ __privateAdd(this, _instruments, {});
4726
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4727
+ __privateAdd(this, _worker);
4728
+ // Worker
4729
+ __privateAdd(this, _publisher, null);
4730
+ __publicField(this, "LogEx", (message) => {
4731
+ this.UpdateInstrument(Gauge.LOGGER, {
4732
+ LogMessage: message
4733
+ });
4734
+ });
4735
+ this.SetupInstrumentation();
4736
+ if (this.options.CreateWorkerFactory) {
4737
+ __privateSet(this, _worker, this.options.CreateWorkerFactory());
4738
+ } else {
4739
+ const publishInstrumentsOptions = {
4740
+ logger: options.logger,
4741
+ processContext: options.processContext,
4742
+ publishInterval: options.publishInterval,
4743
+ publishInstrumentController: this,
4744
+ publishTransportBaseOptions: options.publishTransportBaseOptions
4745
+ };
4746
+ __privateSet(this, _publisher, new PublishInstruments(publishInstrumentsOptions));
4747
+ this.StartPublish();
4748
+ }
4749
+ }
4750
+ get options() {
4751
+ return super.options;
4752
+ }
4753
+ async StartPublish() {
4754
+ if (__privateGet(this, _worker)) {
4755
+ return true;
4756
+ } else {
4757
+ return __privateGet(this, _publisher).StartPublish();
4758
+ }
4759
+ }
4760
+ async EndPublish() {
4761
+ if (__privateGet(this, _worker)) {
4762
+ return true;
4763
+ } else {
4764
+ return __privateGet(this, _publisher).EndPublish();
4765
+ }
4766
+ }
4767
+ async Publish() {
4768
+ if (__privateGet(this, _worker)) {
4769
+ return true;
4770
+ } else {
4771
+ return __privateGet(this, _publisher).Publish();
4772
+ }
4773
+ }
4774
+ GetPayloadData() {
4775
+ const context = this.options.processContext;
4776
+ const instruments = __privateGet(this, _instruments);
4777
+ const payloadInstruments = {};
4778
+ for (const [key, value] of Object.entries(instruments)) {
4779
+ if (value instanceof InstrumentLog) {
4780
+ payloadInstruments[key] = { ...value.WithUseLatestMessages(true) };
4781
+ } else {
4782
+ payloadInstruments[key] = { ...value };
4783
+ }
4784
+ }
4785
+ return {
4786
+ context,
4787
+ instruments: payloadInstruments
4788
+ };
4789
+ }
4790
+ SetupInstrumentation() {
4791
+ if (!this.options.instrumentDefinitions) {
4792
+ this.options.logger.debug(chalk$1.yellow(`SetupInstrumentation:${this.options.processContext.nid}: No instrument(s) defined within supplied options.`));
4793
+ return;
4794
+ }
4795
+ if (!this.options.processContext) {
4796
+ this.options.logger.debug(chalk$1.yellow(`SetupInstrumentation: No context defined within supplied options.`));
4797
+ return;
4798
+ }
4799
+ __privateMethod(this, _PublishInstrumentController_instances, CreateInstruments_fn).call(this, this.options.instrumentDefinitions);
4800
+ }
4801
+ /**
4802
+ * Check if an instrument exists within the managed instrument collection
4803
+ * @param instrumentName
4804
+ * @returns
4805
+ */
4806
+ InstrumentExists(instrumentName) {
4807
+ if (__privateGet(this, _instruments)[instrumentName]) {
4808
+ return true;
4809
+ }
4810
+ return false;
4811
+ }
4812
+ /**
4813
+ * Update instrument telemetry.
4814
+ * @param instrumentName
4815
+ * @param telemetry
4816
+ */
4817
+ UpdateInstrument(instrumentName, telemetry) {
4818
+ if (__privateGet(this, _instruments)[instrumentName]) {
4819
+ __privateMethod(this, _PublishInstrumentController_instances, ProcessTelemetryCommand_fn).call(this, instrumentName, telemetry);
4820
+ } else {
4821
+ this.options.logger.debug(chalk$1.red(`UpdateInstrument:${this.options.processContext.nid}: Attempted to UpdateInstrument before initialised.`));
4822
+ }
4823
+ }
4824
+ /**
4825
+ * Add additional instrument publishers. Usually invoked when adding workers to the app and/or async runners within a worker.
4826
+ * @param processContext
4827
+ * @returns Returns the newly created PublishInstrumentController
4828
+ */
4829
+ AddPublishInstrumentController(processContext) {
4830
+ const options = { ...this.options };
4831
+ options.processContext = processContext;
4832
+ return new _PublishInstrumentController(options);
4833
+ }
4834
+ };
4835
+ _instruments = new WeakMap();
4836
+ _worker = new WeakMap();
4837
+ _publisher = new WeakMap();
4838
+ _PublishInstrumentController_instances = new WeakSet();
4839
+ GetInstrument_fn = function(instrumentName) {
4840
+ return __privateGet(this, _instruments)[instrumentName];
4841
+ };
4842
+ ProcessTelemetryCommand_fn = function(instrumentName, telemetry) {
4843
+ const instrument = __privateMethod(this, _PublishInstrumentController_instances, GetInstrument_fn).call(this, instrumentName);
4844
+ if (instrument) {
4845
+ instrument.ProcessTelemetry(telemetry);
4846
+ }
4847
+ };
4848
+ // Instrument factory
4849
+ CreateInstrument_fn = function(instrumentType, options) {
4850
+ let instrument;
4851
+ switch (instrumentType) {
4852
+ case GaugeTypes.INSTRUMENT_GAUGE:
4853
+ instrument = new InstrumentGauge(options);
4854
+ break;
4855
+ case GaugeTypes.INSTRUMENT_HISTOGRAM:
4856
+ instrument = new InstrumentHistogram(options);
4857
+ break;
4858
+ case GaugeTypes.INSTRUMENT_LOG:
4859
+ instrument = new InstrumentLog(options);
4860
+ break;
4861
+ case GaugeTypes.INSTRUMENT_OBJECT:
4862
+ instrument = new InstrumentObject(options);
4863
+ break;
4864
+ case GaugeTypes.INSTRUMENT_TIMER:
4865
+ instrument = new InstrumentTimerGauge(options);
4866
+ break;
4867
+ case GaugeTypes.INSTRUMENT_VELOCITY:
4868
+ instrument = new InstrumentVelocity(options);
4869
+ break;
4870
+ default:
4871
+ throw new Error(`Gauge type: [${instrumentType} not known.]`);
4872
+ }
4873
+ return instrument;
4874
+ };
4875
+ CreateInstruments_fn = function(payload) {
4876
+ payload.forEach((instrumentDefinition) => {
4877
+ const g = instrumentDefinition[0];
4878
+ const gt = instrumentDefinition[1];
4879
+ const instrumentBaseOptions = instrumentDefinition[2];
4880
+ const instrument = __privateMethod(this, _PublishInstrumentController_instances, CreateInstrument_fn).call(this, gt, instrumentBaseOptions);
4881
+ __privateGet(this, _instruments)[g] = instrument;
4882
+ });
4883
+ };
4884
+ let PublishInstrumentController = _PublishInstrumentController;
4885
+ const STSInstrumentControllerPluginKey = Symbol("instrumentController");
4886
+ const GetSTSInstrumentControllerPluginKey = () => STSInstrumentControllerPluginKey;
4887
+ const CompareSTSInstrumentControllerPluginKey = (val) => val === STSInstrumentControllerPluginKey;
4888
+ const useSTSInstrumentControllerPlugin = () => inject(STSInstrumentControllerPluginKey);
4889
+ const GetSTSInstrumentController = (app) => {
4890
+ return app.config.globalProperties.$sts[STSInstrumentControllerPluginKey];
4891
+ };
4892
+ const STSInstrumentControllerPlugin = {
4893
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4894
+ install: (app, options) => {
4895
+ options.logger.debug(chalk$1.yellow(`STSInstrumentControllerPlugin:install:Start`));
4896
+ const aic = new PublishInstrumentController(options);
4897
+ if (!app.config.globalProperties.$sts) {
4898
+ options.logger.debug(chalk$1.cyan(`STSInstrumentControllerPlugin:install: [app.config.globalProperties.$sts] does not exist.`));
4899
+ app.config.globalProperties.$sts = {};
4900
+ options.logger.debug(chalk$1.cyan(`STSInstrumentControllerPlugin:install: created empty [app.config.globalProperties.$sts].`));
4901
+ } else {
4902
+ options.logger.debug(chalk$1.cyan(`STSInstrumentControllerPlugin:install: [app.config.globalProperties.$sts] already exists.`));
4903
+ }
4904
+ app.config.globalProperties.$sts.aic = aic;
4905
+ app.config.globalProperties.$sts[STSInstrumentControllerPluginKey] = aic;
4906
+ options.logger.debug(chalk$1.cyan(`STSInstrumentControllerPlugin:install: AgentInstrumentController installed into [app.config.globalProperties.$sts] using: [${String(STSInstrumentControllerPluginKey)}].`));
4907
+ app.provide(STSInstrumentControllerPluginKey, aic);
4908
+ options.logger.debug(chalk$1.cyan(`STSInstrumentControllerPlugin:install: AgentInstrumentController installed into 'provide' using: [${String(STSInstrumentControllerPluginKey)}].`));
4909
+ options.logger.debug(chalk$1.green(`STSInstrumentControllerPlugin:install:End`));
4910
+ }
4911
+ };
4966
4912
  var SubscriptionTopic = /* @__PURE__ */ ((SubscriptionTopic2) => {
4967
4913
  SubscriptionTopic2["AllServicesCombined"] = "AllServicesCombined";
4968
4914
  SubscriptionTopic2["Services"] = "Services";
@@ -5787,13 +5733,6 @@ function v4(options, buf, offset) {
5787
5733
  var rnds = options.random || (options.rng || rng)();
5788
5734
  rnds[6] = rnds[6] & 15 | 64;
5789
5735
  rnds[8] = rnds[8] & 63 | 128;
5790
- if (buf) {
5791
- offset = offset || 0;
5792
- for (var i = 0; i < 16; ++i) {
5793
- buf[offset + i] = rnds[i];
5794
- }
5795
- return buf;
5796
- }
5797
5736
  return unsafeStringify(rnds);
5798
5737
  }
5799
5738
  var messageStatus = /* @__PURE__ */ ((messageStatus2) => {