@adobe/spacecat-shared-utils 1.36.3 → 1.37.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [@adobe/spacecat-shared-utils-v1.37.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.36.3...@adobe/spacecat-shared-utils-v1.37.0) (2025-04-28)
2
+
3
+
4
+ ### Features
5
+
6
+ * **xray:** non-aws ie local friendly xray instrumentation ([#710](https://github.com/adobe/spacecat-shared/issues/710)) ([5184b4d](https://github.com/adobe/spacecat-shared/commit/5184b4dc3ddff8a6e44d12129475fa323533be2c))
7
+
1
8
  # [@adobe/spacecat-shared-utils-v1.36.3](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.36.2...@adobe/spacecat-shared-utils-v1.36.3) (2025-04-26)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-utils",
3
- "version": "1.36.3",
3
+ "version": "1.37.0",
4
4
  "description": "Shared modules of the Spacecat Services - utils",
5
5
  "type": "module",
6
6
  "engines": {
@@ -38,6 +38,7 @@
38
38
  "@adobe/spacecat-shared-data-access": "2.0.2",
39
39
  "chai": "5.2.0",
40
40
  "chai-as-promised": "8.0.1",
41
+ "esmock": "2.7.0",
41
42
  "husky": "9.1.7",
42
43
  "nock": "14.0.4",
43
44
  "sinon": "20.0.0",
package/src/index.js CHANGED
@@ -41,10 +41,15 @@ export {
41
41
  getQuery,
42
42
  } from './helpers.js';
43
43
 
44
+ export {
45
+ isAWSLambda,
46
+ } from './runtimes.js';
47
+
44
48
  export { sqsWrapper } from './sqs.js';
45
49
  export { sqsEventAdapter } from './sqs.js';
46
50
 
47
51
  export { logWrapper } from './log-wrapper.js';
52
+ export { xrayWrapper } from './xray.js';
48
53
 
49
54
  export {
50
55
  composeBaseURL,
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright 2025 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import { hasText } from './functions.js';
14
+
15
+ export function isAWSLambda() {
16
+ return hasText(process.env.AWS_EXECUTION_ENV) && process.env.AWS_EXECUTION_ENV.startsWith('AWS_Lambda');
17
+ }
@@ -14,6 +14,7 @@ import AWSXRay from 'aws-xray-sdk';
14
14
 
15
15
  import { fetch as adobeFetch } from './adobe-fetch.js';
16
16
  import { isNumber, isObject } from './functions.js';
17
+ import { isAWSLambda } from './runtimes.js';
17
18
 
18
19
  export const SPACECAT_USER_AGENT = 'Mozilla/5.0 (Linux; Android 11; moto g power (2022)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Mobile Safari/537.36 Spacecat/1.0';
19
20
 
@@ -150,6 +151,11 @@ const fetchWithTimeout = async (resource, options, signal) => {
150
151
  * @returns {Promise<Response>} The response from the fetch request.
151
152
  */
152
153
  export async function tracingFetch(url, options) {
154
+ // fallback to adobe fetch outside an aws lambda function
155
+ if (!isAWSLambda()) {
156
+ return adobeFetch;
157
+ }
158
+
153
159
  const parentSegment = AWSXRay.getSegment();
154
160
 
155
161
  options = isObject(options) ? { ...options } : {};
package/src/xray.js ADDED
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Copyright 2025 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import AWSXray from 'aws-xray-sdk';
14
+ import { isAWSLambda } from './runtimes.js';
15
+
16
+ export function xrayWrapper(fn) {
17
+ return async (req, context) => {
18
+ if (context.xray) {
19
+ return context.xray;
20
+ }
21
+
22
+ context.xray = {
23
+ instrument: (client) => (isAWSLambda() ? AWSXray.captureAWSv3Client(client) : client),
24
+ };
25
+
26
+ return fn(req, context);
27
+ };
28
+ }