@nsshunt/stsobservability 1.0.48 → 1.0.50

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,10 +17,10 @@ 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, _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;
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, _wwClient, _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
- import { STSOptionsBase } from "@nsshunt/stsutils";
23
+ import { STSOptionsBase, WebWorkerMessageHandler, defaultLogger } from "@nsshunt/stsutils";
24
24
  import { TinyEmitter } from "tiny-emitter";
25
25
  import https from "node:https";
26
26
  import axios from "axios";
@@ -4652,8 +4652,11 @@ class PublishInstruments extends STSOptionsBase {
4652
4652
  if (__privateGet(this, _publisherTransport)) {
4653
4653
  try {
4654
4654
  __privateSet(this, _inPublish, true);
4655
- const instrumentPayload = this.options.publishInstrumentController.GetPayloadData();
4656
- return await __privateGet(this, _publisherTransport).Publish(instrumentPayload);
4655
+ if (this.options.publishInstrumentController) {
4656
+ const instrumentPayload = this.options.publishInstrumentController.GetPayloadData();
4657
+ return await __privateGet(this, _publisherTransport).Publish(instrumentPayload);
4658
+ }
4659
+ return false;
4657
4660
  } catch (error) {
4658
4661
  return false;
4659
4662
  } finally {
@@ -4723,18 +4726,46 @@ const _PublishInstrumentController = class _PublishInstrumentController extends
4723
4726
  super(options);
4724
4727
  __privateAdd(this, _PublishInstrumentController_instances);
4725
4728
  __privateAdd(this, _instruments, {});
4726
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4727
4729
  __privateAdd(this, _worker);
4728
4730
  // Worker
4729
4731
  __privateAdd(this, _publisher, null);
4732
+ __privateAdd(this, _wwClient, null);
4730
4733
  __publicField(this, "LogEx", (message) => {
4731
4734
  this.UpdateInstrument(Gauge.LOGGER, {
4732
4735
  LogMessage: message
4733
4736
  });
4734
4737
  });
4735
4738
  this.SetupInstrumentation();
4736
- if (this.options.CreateWorkerFactory) {
4737
- __privateSet(this, _worker, this.options.CreateWorkerFactory());
4739
+ if (this.options.useWorker === true) {
4740
+ const fileName = "./dist/publish/publishInstrumentsWebWorker.js";
4741
+ __privateSet(this, _worker, new Worker(fileName));
4742
+ __privateSet(this, _wwClient, new WebWorkerMessageHandler({
4743
+ logger: defaultLogger,
4744
+ role: "CLIENT",
4745
+ namespace: "mytestapp",
4746
+ groups: [],
4747
+ ignoreEvents: ["ping"],
4748
+ messagePort: __privateGet(this, _worker)
4749
+ }));
4750
+ __privateGet(this, _wwClient).Start();
4751
+ __privateGet(this, _wwClient).on("getpayload", (args, callback) => {
4752
+ const data = this.GetPayloadData();
4753
+ callback({
4754
+ data
4755
+ });
4756
+ });
4757
+ const publishInstrumentsOptions = {
4758
+ logger: options.logger,
4759
+ processContext: options.processContext,
4760
+ publishInterval: options.publishInterval,
4761
+ publishTransportBaseOptions: options.publishTransportBaseOptions
4762
+ };
4763
+ publishInstrumentsOptions.publishTransportBaseOptions.agentOptions = void 0;
4764
+ setTimeout(async () => {
4765
+ var _a2;
4766
+ await ((_a2 = __privateGet(this, _wwClient)) == null ? void 0 : _a2.emitex("options", publishInstrumentsOptions));
4767
+ this.StartPublish();
4768
+ }, 1e3);
4738
4769
  } else {
4739
4770
  const publishInstrumentsOptions = {
4740
4771
  logger: options.logger,
@@ -4751,21 +4782,27 @@ const _PublishInstrumentController = class _PublishInstrumentController extends
4751
4782
  return super.options;
4752
4783
  }
4753
4784
  async StartPublish() {
4785
+ var _a2;
4754
4786
  if (__privateGet(this, _worker)) {
4787
+ await ((_a2 = __privateGet(this, _wwClient)) == null ? void 0 : _a2.emitex("start", {}));
4755
4788
  return true;
4756
4789
  } else {
4757
4790
  return __privateGet(this, _publisher).StartPublish();
4758
4791
  }
4759
4792
  }
4760
4793
  async EndPublish() {
4794
+ var _a2;
4761
4795
  if (__privateGet(this, _worker)) {
4796
+ await ((_a2 = __privateGet(this, _wwClient)) == null ? void 0 : _a2.emitex("stop", {}));
4762
4797
  return true;
4763
4798
  } else {
4764
4799
  return __privateGet(this, _publisher).EndPublish();
4765
4800
  }
4766
4801
  }
4767
4802
  async Publish() {
4803
+ var _a2;
4768
4804
  if (__privateGet(this, _worker)) {
4805
+ await ((_a2 = __privateGet(this, _wwClient)) == null ? void 0 : _a2.emitex("publish", {}));
4769
4806
  return true;
4770
4807
  } else {
4771
4808
  return __privateGet(this, _publisher).Publish();
@@ -4835,6 +4872,7 @@ const _PublishInstrumentController = class _PublishInstrumentController extends
4835
4872
  _instruments = new WeakMap();
4836
4873
  _worker = new WeakMap();
4837
4874
  _publisher = new WeakMap();
4875
+ _wwClient = new WeakMap();
4838
4876
  _PublishInstrumentController_instances = new WeakSet();
4839
4877
  GetInstrument_fn = function(instrumentName) {
4840
4878
  return __privateGet(this, _instruments)[instrumentName];