@lwrjs/shared-utils 0.17.2-alpha.12 → 0.17.2-alpha.15

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
@@ -8,6 +8,9 @@ var __export = (target, all) => {
8
8
  // packages/@lwrjs/shared-utils/src/env.ts
9
9
  __markAsModule(exports);
10
10
  __export(exports, {
11
+ B3_PARENT_ID: () => B3_PARENT_ID,
12
+ B3_SAMPLED: () => B3_SAMPLED,
13
+ B3_SPAN_ID: () => B3_SPAN_ID,
11
14
  B3_TRACE_ID: () => B3_TRACE_ID,
12
15
  CORRELATION_ID: () => CORRELATION_ID,
13
16
  MRT_REQUEST_CLASS: () => MRT_REQUEST_CLASS,
@@ -16,6 +19,7 @@ __export(exports, {
16
19
  TRUE_CLIENT_IP: () => TRUE_CLIENT_IP,
17
20
  buildEnvironmentContext: () => buildEnvironmentContext,
18
21
  getFeatureFlags: () => getFeatureFlags,
22
+ getTraceHeaders: () => getTraceHeaders,
19
23
  isLambdaEnv: () => isLambdaEnv,
20
24
  isLocalDev: () => isLocalDev,
21
25
  parseRequestDepth: () => parseRequestDepth
@@ -69,8 +73,11 @@ function buildEnvironmentContext(runtimeParams) {
69
73
  };
70
74
  }
71
75
  var TRUE_CLIENT_IP = "true-client-ip";
72
- var B3_TRACE_ID = "x-b3-traceid";
73
76
  var CORRELATION_ID = "x-correlation-id";
77
+ var B3_TRACE_ID = "x-b3-traceid";
78
+ var B3_SPAN_ID = "x-b3-spandid";
79
+ var B3_PARENT_ID = "x-b3-parentid";
80
+ var B3_SAMPLED = "x-b3-sampled";
74
81
  var MRT_REQUEST_CLASS = "x-mobify-request-class";
75
82
  var ROUTE_CORE_HEADER = "x-sfdc-route-core";
76
83
  var REQUEST_DEPTH_HEADER = "x-sfdc-request-depth";
@@ -102,3 +109,19 @@ function parseRequestDepth(headers = {}, query = {}) {
102
109
  }
103
110
  return maxDepth;
104
111
  }
112
+ function getTraceHeaders(runtimeParams, span) {
113
+ const headers = {};
114
+ if (runtimeParams.trueClientIP)
115
+ headers[TRUE_CLIENT_IP] = runtimeParams.trueClientIP;
116
+ if (runtimeParams.correlationID)
117
+ headers[CORRELATION_ID] = runtimeParams.correlationID;
118
+ if (span?.traceId) {
119
+ headers[B3_TRACE_ID] = span.traceId;
120
+ headers[B3_SAMPLED] = parseTracingFlag() ? "1" : "0";
121
+ }
122
+ if (span?.spanId)
123
+ headers[B3_SPAN_ID] = span.spanId;
124
+ if (span?.parentSpanId)
125
+ headers[B3_PARENT_ID] = span.parentSpanId;
126
+ return headers;
127
+ }
package/build/es/env.d.ts CHANGED
@@ -17,10 +17,18 @@ export declare function isLocalDev(): boolean;
17
17
  */
18
18
  export declare function buildEnvironmentContext(runtimeParams: RuntimeParams): EnvironmentContext;
19
19
  export declare const TRUE_CLIENT_IP = "true-client-ip";
20
- export declare const B3_TRACE_ID = "x-b3-traceid";
21
20
  export declare const CORRELATION_ID = "x-correlation-id";
21
+ export declare const B3_TRACE_ID = "x-b3-traceid";
22
+ export declare const B3_SPAN_ID = "x-b3-spandid";
23
+ export declare const B3_PARENT_ID = "x-b3-parentid";
24
+ export declare const B3_SAMPLED = "x-b3-sampled";
22
25
  export declare const MRT_REQUEST_CLASS = "x-mobify-request-class";
23
26
  export declare const ROUTE_CORE_HEADER = "x-sfdc-route-core";
24
27
  export declare const REQUEST_DEPTH_HEADER = "x-sfdc-request-depth";
25
28
  export declare function parseRequestDepth(headers?: Headers, query?: Record<string, string>): number;
29
+ export declare function getTraceHeaders(runtimeParams: RuntimeParams, span?: {
30
+ traceId: string;
31
+ spanId: string;
32
+ parentSpanId?: string;
33
+ }): HeadersInit;
26
34
  //# sourceMappingURL=env.d.ts.map
package/build/es/env.js CHANGED
@@ -91,8 +91,11 @@ export function buildEnvironmentContext(runtimeParams) {
91
91
  }
92
92
  // headers used by LWR-Node and LWR@MRT
93
93
  export const TRUE_CLIENT_IP = 'true-client-ip'; // public IP of the original request source, eg: 13.123.12.3
94
- export const B3_TRACE_ID = 'x-b3-traceid'; // trace ID shared across service boundaries for a page request, eg: 463ac35c9f6413ad48485a3953bb6124
95
94
  export const CORRELATION_ID = 'x-correlation-id'; // shared correlation ID for the request
95
+ export const B3_TRACE_ID = 'x-b3-traceid'; // trace ID shared across service boundaries for a page request, set to inbound B3 header || lwr.handle.view trace ID
96
+ export const B3_SPAN_ID = 'x-b3-spandid'; // span ID for a trace
97
+ export const B3_PARENT_ID = 'x-b3-parentid'; // parent span ID for a trace
98
+ export const B3_SAMPLED = 'x-b3-sampled'; // "0" = tracing is off, "1" = tracing is on
96
99
  export const MRT_REQUEST_CLASS = 'x-mobify-request-class'; // contains the site base path, eg: basePath=/mysite
97
100
  export const ROUTE_CORE_HEADER = 'x-sfdc-route-core'; // helps route requests to Core efficiently, value: true
98
101
  export const REQUEST_DEPTH_HEADER = 'x-sfdc-request-depth'; // tracks the request depth to prevent cycles to the LWR server, eg: 2
@@ -126,4 +129,20 @@ export function parseRequestDepth(headers = {}, query = {}) {
126
129
  }
127
130
  return maxDepth;
128
131
  }
132
+ export function getTraceHeaders(runtimeParams, span) {
133
+ const headers = {};
134
+ if (runtimeParams.trueClientIP)
135
+ headers[TRUE_CLIENT_IP] = runtimeParams.trueClientIP;
136
+ if (runtimeParams.correlationID)
137
+ headers[CORRELATION_ID] = runtimeParams.correlationID;
138
+ if (span?.traceId) {
139
+ headers[B3_TRACE_ID] = span.traceId;
140
+ headers[B3_SAMPLED] = parseTracingFlag() ? '1' : '0';
141
+ }
142
+ if (span?.spanId)
143
+ headers[B3_SPAN_ID] = span.spanId;
144
+ if (span?.parentSpanId)
145
+ headers[B3_PARENT_ID] = span.parentSpanId;
146
+ return headers;
147
+ }
129
148
  //# sourceMappingURL=env.js.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.17.2-alpha.12",
7
+ "version": "0.17.2-alpha.15",
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.17.2-alpha.12",
40
+ "@lwrjs/diagnostics": "0.17.2-alpha.15",
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,13 +50,13 @@
50
50
  "slugify": "^1.4.5"
51
51
  },
52
52
  "devDependencies": {
53
- "@lwrjs/types": "0.17.2-alpha.12",
53
+ "@lwrjs/types": "0.17.2-alpha.15",
54
54
  "@types/mime-types": "2.1.4",
55
55
  "@types/path-to-regexp": "^1.7.0",
56
56
  "memfs": "^4.13.0"
57
57
  },
58
58
  "engines": {
59
- "node": ">=18.0.0"
59
+ "node": ">=20.0.0"
60
60
  },
61
- "gitHead": "f5d7c20e7aec008c06db8d5e289c8cb1e3467005"
61
+ "gitHead": "91299b871adb9aea8c743d830dd62bce418a0933"
62
62
  }