@salesforce/lds-instrumentation 1.130.10 → 1.131.0-dev9

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.
@@ -91,7 +91,7 @@ var FragmentReadResultState;
91
91
  ({
92
92
  state: FragmentReadResultState.Missing,
93
93
  });
94
- // engine version: 0.138.8-480e18f2
94
+ // engine version: 0.138.8-244.1-492a715e
95
95
 
96
96
  const DurableEnvironmentEventDiscriminator = 'durable';
97
97
  function isDurableEnvironmentEvent(event) {
@@ -927,13 +927,36 @@ function logAdapterCacheMissOutOfTtlDuration(name, config, currentCacheMissTimes
927
927
  }
928
928
  }
929
929
  }
930
+ /**
931
+ * Starts an o11y Activity using the supplied o11y Instrumention and adapterName.
932
+ * If a requestContext is supplied, we check for the existence of a requestCorrelator containing an ObservabilityContext.
933
+ * If an ObservabilityContext is defined, we build an object that conforms to the ApiOptions interface required by the startActivity API
934
+ */
935
+ function startAdapterActivity(instrumentation, adapterName, requestContext) {
936
+ if (requestContext === undefined ||
937
+ requestContext.requestCorrelator === undefined ||
938
+ requestContext.requestCorrelator.observabilityContext === undefined) {
939
+ return instrumentation.startActivity(adapterName);
940
+ }
941
+ const { traceId, ...rest } = requestContext.requestCorrelator
942
+ .observabilityContext;
943
+ const apiOptions = {
944
+ instrumentationContext: rest,
945
+ };
946
+ if (traceId !== undefined) {
947
+ apiOptions.instrumentationContext.parentId = traceId;
948
+ }
949
+ return instrumentation.startActivity(adapterName, apiOptions);
950
+ }
930
951
  function instrumentAdapter(adapter, metadata, adapterInstrumentationOptions) {
931
952
  const { apiFamily, name, ttl } = metadata;
932
953
  let trackL1Hits = false;
933
954
  let trackL2Hits = false;
955
+ let trackCacheMisses = false;
934
956
  let reportObserver = undefined;
935
957
  if (adapterInstrumentationOptions !== undefined) {
936
- ({ trackL1Hits, trackL2Hits, reportObserver } = adapterInstrumentationOptions);
958
+ ({ trackL1Hits, trackL2Hits, trackCacheMisses, reportObserver } =
959
+ adapterInstrumentationOptions);
937
960
  }
938
961
  const adapterName = normalizeAdapterName(name, apiFamily);
939
962
  /**
@@ -986,7 +1009,7 @@ function instrumentAdapter(adapter, metadata, adapterInstrumentationOptions) {
986
1009
  // increment cache policy metrics
987
1010
  incrementAdapterCachePolicyType(requestContext);
988
1011
  // start collecting
989
- const activity = ldsInstrumentation.startActivity(adapterName);
1012
+ const activity = startAdapterActivity(ldsInstrumentation, adapterName, requestContext);
990
1013
  return runAdapterWithReport(metadata.name, adapter, config, requestContext || {}, (report) => {
991
1014
  const { executionTime } = report;
992
1015
  switch (report.result) {
@@ -1021,10 +1044,14 @@ function instrumentAdapter(adapter, metadata, adapterInstrumentationOptions) {
1021
1044
  case 'cache-miss':
1022
1045
  {
1023
1046
  ldsInstrumentation.trackValue(cacheMissDurationByAdapterMetric, executionTime);
1024
- // TODO [W-10484306]: Remove typecasting after this type bug is solved
1025
- activity.stop('cache-miss');
1026
1047
  ldsInstrumentation.incrementCounter(ADAPTER_CACHE_MISS_COUNT_METRIC_NAME, 1);
1027
1048
  ldsInstrumentation.incrementCounter(cacheMissCountByAdapterMetric, 1);
1049
+ if (trackCacheMisses) {
1050
+ activity.stop('cache-miss');
1051
+ }
1052
+ else {
1053
+ activity.discard();
1054
+ }
1028
1055
  if (ttl !== undefined) {
1029
1056
  logAdapterCacheMissOutOfTtlDuration(adapterName, config, Date.now(), ttl, cacheMissOutOfTtlCountByAdapterMetric, cacheMissOutOfTtlDurationByAdapterMetric);
1030
1057
  }
@@ -1039,7 +1066,6 @@ function instrumentAdapter(adapter, metadata, adapterInstrumentationOptions) {
1039
1066
  if (isAdapterError(error)) {
1040
1067
  activity.error(error);
1041
1068
  }
1042
- // TODO [W-10484306]: Remove typecasting after this type bug is solved
1043
1069
  activity.stop('error');
1044
1070
  }
1045
1071
  break;
@@ -1360,7 +1386,6 @@ function setupInstrumentation(luvio, store) {
1360
1386
  setupStoreStatsCollection(luvio, instrumentStoreStatsCallback(store));
1361
1387
  setStoreScheduler(store);
1362
1388
  setStoreEventObservers(store);
1363
- // TODO [W-10061321]: use periodic logger to log aggregated store stats
1364
1389
  }
1365
1390
  function instrumentStoreMethods(luvio, _store) {
1366
1391
  instrumentMethods(luvio, [
@@ -1427,5 +1452,5 @@ function setStoreEventObservers(store) {
1427
1452
  }
1428
1453
  const instrumentation = new Instrumentation();
1429
1454
 
1430
- export { Instrumentation, LRUCache, metricKeys as METRIC_KEYS, handleIngestedNewData, handleOnDataOutOfTtlDurationUpdate, incrementCounterMetric, incrementGetRecordNormalInvokeCount, incrementGetRecordNotifyChangeAllowCount, incrementGetRecordNotifyChangeDropCount, incrementNotifyRecordUpdateAvailableAllowCount, incrementNotifyRecordUpdateAvailableDropCount, instrumentAdapter, instrumentLuvio, instrumentMethods, instrumentStoreMethods, instrumentation, setInstrumentationHooks, setLdsAdaptersUiapiInstrumentation, setLdsNetworkAdapterInstrumentation, setStoreEventObservers, setupInstrumentation, updatePercentileHistogramMetric };
1431
- // version: 1.130.10-0fac4c295
1455
+ export { Instrumentation, LRUCache, metricKeys as METRIC_KEYS, handleIngestedNewData, handleOnDataOutOfTtlDurationUpdate, incrementCounterMetric, incrementGetRecordNormalInvokeCount, incrementGetRecordNotifyChangeAllowCount, incrementGetRecordNotifyChangeDropCount, incrementNotifyRecordUpdateAvailableAllowCount, incrementNotifyRecordUpdateAvailableDropCount, instrumentAdapter, instrumentLuvio, instrumentMethods, instrumentStoreMethods, instrumentation, setInstrumentationHooks, setLdsAdaptersUiapiInstrumentation, setLdsNetworkAdapterInstrumentation, setStoreEventObservers, setupInstrumentation, startAdapterActivity, updatePercentileHistogramMetric };
1456
+ // version: 1.131.0-dev9-5f88f31bc
@@ -1,7 +1,9 @@
1
- import type { Luvio, InMemoryStore, Adapter, CacheMissOutOfTtlEvent, DataOutOfTtlDurationUpdateEvent } from '@luvio/engine';
1
+ import type { AdapterRequestContext, Luvio, InMemoryStore, Adapter, CacheMissOutOfTtlEvent, DataOutOfTtlDurationUpdateEvent } from '@luvio/engine';
2
+ import type { Activity, Instrumentation as o11yInstrumentation } from 'o11y/dist/modules/o11y/client/interfaces';
2
3
  import type { Registration as LdsUiapiRegistration } from '@salesforce/lds-adapters-uiapi';
3
4
  import type { Registration as LdsNetworkAdapterRegistration } from '@salesforce/lds-network-adapter';
4
5
  import type { AdapterReport } from '@salesforce/lds-utils-adapters';
6
+ import type { ObservabilityContext } from '@salesforce/nimbus-plugin-lds';
5
7
  export * as METRIC_KEYS from './metric-keys';
6
8
  export { LRUCache } from './utils/lru-cache';
7
9
  interface AdapterMetadata {
@@ -26,8 +28,18 @@ export type ReportObserver = (report: AdapterReport) => void;
26
28
  interface AdapterInstrumentationOptions {
27
29
  trackL1Hits: boolean;
28
30
  trackL2Hits: boolean;
31
+ trackCacheMisses: boolean;
29
32
  reportObserver?: ReportObserver;
30
33
  }
34
+ export interface RequestCorrelator {
35
+ observabilityContext?: ObservabilityContext;
36
+ }
37
+ /**
38
+ * Starts an o11y Activity using the supplied o11y Instrumention and adapterName.
39
+ * If a requestContext is supplied, we check for the existence of a requestCorrelator containing an ObservabilityContext.
40
+ * If an ObservabilityContext is defined, we build an object that conforms to the ApiOptions interface required by the startActivity API
41
+ */
42
+ export declare function startAdapterActivity(instrumentation: o11yInstrumentation, adapterName: string, requestContext?: AdapterRequestContext): Activity;
31
43
  export declare function instrumentAdapter<C, D>(adapter: Adapter<C, D>, metadata: AdapterMetadata, adapterInstrumentationOptions?: AdapterInstrumentationOptions): Adapter<C, D>;
32
44
  /**
33
45
  * Wraps methods to collect runtime performance using o11y's trackValue API
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-instrumentation",
3
- "version": "1.130.10",
3
+ "version": "1.131.0-dev9",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "Instrumentation utils for Lightning Data Service",
6
6
  "main": "dist/ldsInstrumentation.js",
@@ -33,22 +33,22 @@
33
33
  "release:corejar": "yarn build && ../core-build/scripts/core.js --name=lds-instrumentation"
34
34
  },
35
35
  "dependencies": {
36
- "@salesforce/lds-bindings": "*",
37
- "@salesforce/lds-default-luvio": "*",
38
- "@salesforce/lds-utils-adapters": "*",
36
+ "@salesforce/lds-bindings": "1.131.0-244.8",
37
+ "@salesforce/lds-default-luvio": "1.131.0-244.8",
38
+ "@salesforce/lds-utils-adapters": "1.131.0-244.8",
39
39
  "o11y": "244.0.0",
40
40
  "o11y_schema": "244.0.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@salesforce/lds-adapters-uiapi": "*",
44
- "@salesforce/lds-network-adapter": "*"
43
+ "@salesforce/lds-adapters-uiapi": "1.131.0-244.8",
44
+ "@salesforce/lds-network-adapter": "1.131.0-244.8"
45
45
  },
46
46
  "luvioBundlesize": [
47
47
  {
48
48
  "path": "./dist/ldsInstrumentation.js",
49
49
  "maxSize": {
50
50
  "none": "60 kB",
51
- "min": "25 kB",
51
+ "min": "26 kB",
52
52
  "compressed": "11 kB"
53
53
  }
54
54
  }