@salesforce/lds-instrumentation 1.208.0 → 1.209.0

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.
@@ -948,7 +948,7 @@ function logAdapterCacheMissOutOfTtlDuration(name, config, currentCacheMissTimes
948
948
  function startAdapterActivity(instrumentation, adapterName, requestContext) {
949
949
  if (requestContext === undefined ||
950
950
  requestContext.requestCorrelator === undefined ||
951
- requestContext.requestCorrelator.observabilityContext === undefined) {
951
+ getObservabilityContext(requestContext) === undefined) {
952
952
  return instrumentation.startActivity(adapterName);
953
953
  }
954
954
  const { traceId, ...rest } = requestContext.requestCorrelator
@@ -1023,6 +1023,8 @@ function instrumentAdapter(adapter, metadata, adapterInstrumentationOptions) {
1023
1023
  incrementAdapterCachePolicyType(requestContext);
1024
1024
  // start collecting
1025
1025
  const activity = startAdapterActivity(ldsInstrumentation, adapterName, requestContext);
1026
+ // swap in activity's Id if observabilityContext exists
1027
+ updateRequestContext(activity, requestContext);
1026
1028
  return runAdapterWithReport(metadata.name, adapter, config, requestContext || {}, (report) => {
1027
1029
  const { executionTime } = report;
1028
1030
  switch (report.result) {
@@ -1107,6 +1109,26 @@ function instrumentAdapter(adapter, metadata, adapterInstrumentationOptions) {
1107
1109
  ? instrumentGraphqlAdapter(instrumentedAdapter)
1108
1110
  : instrumentedAdapter;
1109
1111
  }
1112
+ /**
1113
+ * Replaces observabilityContext's traceId with parentActivity's Id since traceId
1114
+ * is treated as parentId when observabilityContext is passed to native as part of
1115
+ * the network request.
1116
+ * @param parentActivity
1117
+ * @param requestContext
1118
+ */
1119
+ function updateRequestContext(parentActivity, requestContext) {
1120
+ if (requestContext !== undefined) {
1121
+ const observabilityContext = getObservabilityContext(requestContext);
1122
+ if (observabilityContext !== undefined) {
1123
+ observabilityContext.traceId = parentActivity.getId();
1124
+ }
1125
+ }
1126
+ }
1127
+ function getObservabilityContext(requestContext) {
1128
+ return requestContext.requestCorrelator !== undefined
1129
+ ? requestContext.requestCorrelator.observabilityContext
1130
+ : undefined;
1131
+ }
1110
1132
  /**
1111
1133
  * Any graphql get adapter specific instrumentation that we need to log
1112
1134
  * @param snapshot from either in-memory or built after a network hit
@@ -1466,4 +1488,4 @@ function setStoreEventObservers(store) {
1466
1488
  const instrumentation = new Instrumentation();
1467
1489
 
1468
1490
  export { Instrumentation, LRUCache, metricKeys as METRIC_KEYS, handleIngestedNewData, handleOnDataOutOfTtlDurationUpdate, incrementCounterMetric, incrementGetRecordNormalInvokeCount, incrementGetRecordNotifyChangeAllowCount, incrementGetRecordNotifyChangeDropCount, incrementNotifyRecordUpdateAvailableAllowCount, incrementNotifyRecordUpdateAvailableDropCount, instrumentAdapter, instrumentLuvio, instrumentMethods, instrumentStoreMethods, instrumentation, logObjectInfoChanged, setInstrumentationHooks, setLdsAdaptersUiapiInstrumentation, setLdsNetworkAdapterInstrumentation, setStoreEventObservers, setupInstrumentation, startAdapterActivity, updatePercentileHistogramMetric };
1469
- // version: 1.208.0-75bd0667c
1491
+ // version: 1.209.0-6b633d53a
@@ -7,5 +7,6 @@ export declare const activity: {
7
7
  error: typeof error;
8
8
  discard: typeof discard;
9
9
  terminate: typeof terminate;
10
+ getId: () => string;
10
11
  };
11
12
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-instrumentation",
3
- "version": "1.208.0",
3
+ "version": "1.209.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "Instrumentation utils for Lightning Data Service",
6
6
  "main": "dist/ldsInstrumentation.js",