@lwrjs/shared-utils 0.20.2 → 0.20.3

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"),
@@ -61,6 +62,14 @@ function parseTracingFlag() {
61
62
  const tracingValue = process.env.LWR_TRACING?.toLowerCase();
62
63
  return tracingValue && tracingValue !== "off" ? process.env.LWR_TRACING : void 0;
63
64
  }
65
+ function shouldEnableB3Headers() {
66
+ const flags = getFeatureFlags();
67
+ const isMRT = isLambdaEnv() || process.env.MRT_REQUEST_CLASS || process.env.MOBIFY_PROPERTY_ID;
68
+ if (isMRT) {
69
+ return flags.MRT_B3_TRACING !== false;
70
+ }
71
+ return true;
72
+ }
64
73
  function isLambdaEnv() {
65
74
  return process.env.AWS_LAMBDA_FUNCTION_NAME !== void 0;
66
75
  }
@@ -131,7 +140,7 @@ function getTraceHeaders(runtimeParams, span) {
131
140
  headers[TRUE_CLIENT_IP] = runtimeParams.trueClientIP;
132
141
  if (runtimeParams.correlationID)
133
142
  headers[CORRELATION_ID] = runtimeParams.correlationID;
134
- if (!getFeatureFlags().DISABLE_B3_TRACING) {
143
+ if (shouldEnableB3Headers()) {
135
144
  if (span?.traceId) {
136
145
  headers[B3_TRACE_ID] = span.traceId;
137
146
  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.
@@ -54,13 +57,32 @@ function parseStringFlag(flag) {
54
57
  return value || undefined;
55
58
  }
56
59
  /**
57
- * Helper function to parse the LWR_TRACING flag.
58
- * Returns the value if it's not 'off' and is defined, otherwise returns false.
60
+ * Helper function to parse the LWR_TRACING flag for OpenTelemetry spans/instrumentation.
61
+ * Returns the value if it's not 'off' and is defined, otherwise returns undefined.
62
+ * This controls OpenTelemetry spans, NOT B3 distributed tracing headers.
59
63
  */
60
64
  function parseTracingFlag() {
61
65
  const tracingValue = process.env.LWR_TRACING?.toLowerCase();
62
66
  return tracingValue && tracingValue !== 'off' ? process.env.LWR_TRACING : undefined;
63
67
  }
68
+ /**
69
+ * Helper function to determine if B3 distributed tracing headers should be enabled.
70
+ * Uses MRT_B3_TRACING for MRT sites, always enabled for non-MRT sites.
71
+ * Separates OpenTelemetry spans (LWR_TRACING) from B3 header propagation.
72
+ *
73
+ * @returns true if B3 distributed tracing headers should be set
74
+ */
75
+ function shouldEnableB3Headers() {
76
+ const flags = getFeatureFlags();
77
+ // Check if this is an MRT environment
78
+ const isMRT = isLambdaEnv() || process.env.MRT_REQUEST_CLASS || process.env.MOBIFY_PROPERTY_ID;
79
+ if (isMRT) {
80
+ // For MRT sites, use the MRT-specific distributed tracing flag
81
+ return flags.MRT_B3_TRACING !== false;
82
+ }
83
+ // For non-MRT sites, always enable B3 headers
84
+ return true;
85
+ }
64
86
  /**
65
87
  * This function is used to determine if the current environment is a lambda.
66
88
  *
@@ -167,7 +189,9 @@ export function getTraceHeaders(runtimeParams, span) {
167
189
  headers[TRUE_CLIENT_IP] = runtimeParams.trueClientIP;
168
190
  if (runtimeParams.correlationID)
169
191
  headers[CORRELATION_ID] = runtimeParams.correlationID;
170
- if (!getFeatureFlags().DISABLE_B3_TRACING) {
192
+ // Set B3 distributed tracing headers for request correlation across microservices
193
+ // These headers are controlled independently from OpenTelemetry spans (LWR_TRACING)
194
+ if (shouldEnableB3Headers()) {
171
195
  if (span?.traceId) {
172
196
  headers[B3_TRACE_ID] = span.traceId;
173
197
  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.20.2",
7
+ "version": "0.20.3",
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.20.2",
40
+ "@lwrjs/diagnostics": "0.20.3",
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.20.2",
53
+ "@lwrjs/types": "0.20.3",
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": "be82aca54f9a3b6cd18a4aac86f2f96c0184a930"
61
+ "gitHead": "54759076bcb5d09e143a620e7653e2494658aefb"
62
62
  }