@lwrjs/shared-utils 0.19.7 → 0.19.8

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.
package/build/cjs/env.cjs CHANGED
@@ -39,6 +39,7 @@ function getFeatureFlags() {
39
39
  LEGACY_LOADER: parseBooleanFlag("LEGACY_LOADER"),
40
40
  LWR_TRACING: parseTracingFlag(),
41
41
  DISABLE_B3_TRACING: parseBooleanFlag("DISABLE_B3_TRACING"),
42
+ MRT_B3_TRACING: parseBooleanFlag("MRT_B3_TRACING"),
42
43
  MAX_VIEW_CACHE_TTL: parseStringFlag("MAX_VIEW_CACHE_TTL"),
43
44
  REEVALUATE_MODULES: parseBooleanFlag("REEVALUATE_MODULES"),
44
45
  SSR_COMPILER_ENABLED: parseBooleanFlag("SSR_COMPILER_ENABLED"),
@@ -62,6 +63,14 @@ function parseTracingFlag() {
62
63
  const tracingValue = process.env.LWR_TRACING?.toLowerCase();
63
64
  return tracingValue && tracingValue !== "off" ? process.env.LWR_TRACING : void 0;
64
65
  }
66
+ function shouldEnableB3Headers() {
67
+ const flags = getFeatureFlags();
68
+ const isMRT = isLambdaEnv() || process.env.MRT_REQUEST_CLASS || process.env.MOBIFY_PROPERTY_ID;
69
+ if (isMRT) {
70
+ return flags.MRT_B3_TRACING !== false;
71
+ }
72
+ return true;
73
+ }
65
74
  function isLambdaEnv() {
66
75
  return process.env.AWS_LAMBDA_FUNCTION_NAME !== void 0;
67
76
  }
@@ -132,7 +141,7 @@ function getTraceHeaders(runtimeParams, span) {
132
141
  headers[TRUE_CLIENT_IP] = runtimeParams.trueClientIP;
133
142
  if (runtimeParams.correlationID)
134
143
  headers[CORRELATION_ID] = runtimeParams.correlationID;
135
- if (!getFeatureFlags().DISABLE_B3_TRACING) {
144
+ if (shouldEnableB3Headers()) {
136
145
  if (span?.traceId) {
137
146
  headers[B3_TRACE_ID] = span.traceId;
138
147
  headers[B3_SAMPLED] = parseTracingFlag() ? "1" : "0";
package/build/es/env.js CHANGED
@@ -15,7 +15,10 @@ export function getFeatureFlags() {
15
15
  // Enable metrics log level 'off', 'default' or 'verbose'
16
16
  LWR_TRACING: parseTracingFlag(),
17
17
  // Turn off distributed tracing (B3 headers, traceparent meta tag, MRT span exporting)
18
+ // Legacy flag - kept for backward compatibility but no longer controls B3 headers
18
19
  DISABLE_B3_TRACING: parseBooleanFlag('DISABLE_B3_TRACING'),
20
+ // Control x-b3-* distributed tracing headers specifically for MRT sites
21
+ MRT_B3_TRACING: parseBooleanFlag('MRT_B3_TRACING'),
19
22
  // Max size of ViewDefinition time to live
20
23
  MAX_VIEW_CACHE_TTL: parseStringFlag('MAX_VIEW_CACHE_TTL'),
21
24
  // Forces SSR to re-evaluate modules for every page render. By default, modules are evaluated only once.
@@ -56,13 +59,32 @@ function parseStringFlag(flag) {
56
59
  return value || undefined;
57
60
  }
58
61
  /**
59
- * Helper function to parse the LWR_TRACING flag.
60
- * Returns the value if it's not 'off' and is defined, otherwise returns false.
62
+ * Helper function to parse the LWR_TRACING flag for OpenTelemetry spans/instrumentation.
63
+ * Returns the value if it's not 'off' and is defined, otherwise returns undefined.
64
+ * This controls OpenTelemetry spans, NOT B3 distributed tracing headers.
61
65
  */
62
66
  function parseTracingFlag() {
63
67
  const tracingValue = process.env.LWR_TRACING?.toLowerCase();
64
68
  return tracingValue && tracingValue !== 'off' ? process.env.LWR_TRACING : undefined;
65
69
  }
70
+ /**
71
+ * Helper function to determine if B3 distributed tracing headers should be enabled.
72
+ * Uses MRT_B3_TRACING for MRT sites, always enabled for non-MRT sites.
73
+ * Separates OpenTelemetry spans (LWR_TRACING) from B3 header propagation.
74
+ *
75
+ * @returns true if B3 distributed tracing headers should be set
76
+ */
77
+ function shouldEnableB3Headers() {
78
+ const flags = getFeatureFlags();
79
+ // Check if this is an MRT environment
80
+ const isMRT = isLambdaEnv() || process.env.MRT_REQUEST_CLASS || process.env.MOBIFY_PROPERTY_ID;
81
+ if (isMRT) {
82
+ // For MRT sites, use the MRT-specific distributed tracing flag
83
+ return flags.MRT_B3_TRACING !== false;
84
+ }
85
+ // For non-MRT sites, always enable B3 headers
86
+ return true;
87
+ }
66
88
  /**
67
89
  * This function is used to determine if the current environment is a lambda.
68
90
  *
@@ -169,7 +191,9 @@ export function getTraceHeaders(runtimeParams, span) {
169
191
  headers[TRUE_CLIENT_IP] = runtimeParams.trueClientIP;
170
192
  if (runtimeParams.correlationID)
171
193
  headers[CORRELATION_ID] = runtimeParams.correlationID;
172
- if (!getFeatureFlags().DISABLE_B3_TRACING) {
194
+ // Set B3 distributed tracing headers for request correlation across microservices
195
+ // These headers are controlled independently from OpenTelemetry spans (LWR_TRACING)
196
+ if (shouldEnableB3Headers()) {
173
197
  if (span?.traceId) {
174
198
  headers[B3_TRACE_ID] = span.traceId;
175
199
  headers[B3_SAMPLED] = parseTracingFlag() ? '1' : '0';
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.19.7",
7
+ "version": "0.19.8",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -37,7 +37,7 @@
37
37
  "build/**/*.d.ts"
38
38
  ],
39
39
  "dependencies": {
40
- "@lwrjs/diagnostics": "0.19.7",
40
+ "@lwrjs/diagnostics": "0.19.8",
41
41
  "es-module-lexer": "^1.5.4",
42
42
  "fast-json-stable-stringify": "^2.1.0",
43
43
  "magic-string": "^0.30.9",
@@ -50,7 +50,7 @@
50
50
  "slugify": "^1.4.5"
51
51
  },
52
52
  "devDependencies": {
53
- "@lwrjs/types": "0.19.7",
53
+ "@lwrjs/types": "0.19.8",
54
54
  "@types/mime-types": "2.1.4",
55
55
  "@types/path-to-regexp": "^1.7.0",
56
56
  "memfs": "^4.13.0"
@@ -58,5 +58,5 @@
58
58
  "engines": {
59
59
  "node": ">=20.0.0"
60
60
  },
61
- "gitHead": "66223bcb48c4e0b18bfffb78fcd45c6cefa80874"
61
+ "gitHead": "318e3e2bde6d04a218cc11849f791b7de85e6f9e"
62
62
  }