You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@aws-lambda-powertools/tracer

Package Overview
Dependencies
Maintainers
3
Versions
111
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-lambda-powertools/tracer - npm Package Compare versions

Comparing version

to
2.24.0

4

lib/cjs/provider/ProviderService.d.ts

@@ -17,7 +17,7 @@ import type { Segment, Subsegment } from 'aws-xray-sdk-core';

/**
* @deprecated
* @deprecated Use {@link captureAWSv3Client} instead.
*/
captureAWS<T>(awssdk: T): T;
/**
* @deprecated
* @deprecated Use {@link captureAWSv3Client} instead.
*/

@@ -24,0 +24,0 @@ captureAWSClient<T>(service: T): T;

@@ -13,3 +13,3 @@ "use strict";

const commons_1 = require("@aws-lambda-powertools/commons");
const EnvironmentVariablesService_js_1 = require("../config/EnvironmentVariablesService.js");
const env_1 = require("@aws-lambda-powertools/commons/utils/env");
const utilities_js_1 = require("./utilities.js");

@@ -29,13 +29,13 @@ /**

/**
* @deprecated
* @deprecated Use {@link captureAWSv3Client} instead.
*/
captureAWS(awssdk) {
/* v8 ignore start */ captureAWS(awssdk) {
return captureAWS(awssdk);
}
} /* v8 ignore stop */
/**
* @deprecated
* @deprecated Use {@link captureAWSv3Client} instead.
*/
captureAWSClient(service) {
/* v8 ignore start */ captureAWSClient(service) {
return captureAWSClient(service);
}
} /* v8 ignore stop */
captureAWSv3Client(service) {

@@ -84,6 +84,8 @@ (0, commons_1.addUserAgentMiddleware)(service, 'tracer');

const { request } = message;
const method = request.method;
if (method === 'CONNECT')
return;
const parentSubsegment = this.getSegment();
const requestURL = (0, utilities_js_1.getRequestURL)(request);
if (parentSubsegment && requestURL) {
const method = request.method;
const subsegment = parentSubsegment.addNewSubsegment(requestURL.hostname);

@@ -93,3 +95,3 @@ subsegment.addAttribute('namespace', 'remote');

// @ts-expect-error
request.addHeader('X-Amzn-Trace-Id', `Root=${EnvironmentVariablesService_js_1.environmentVariablesService.getXrayTraceId()};Parent=${subsegment.id};Sampled=${subsegment.notTraced ? '0' : '1'}`);
request.addHeader('X-Amzn-Trace-Id', `Root=${(0, env_1.getXRayTraceIdFromEnv)()};Parent=${subsegment.id};Sampled=${subsegment.notTraced ? '0' : '1'}`);
subsegment.http = {

@@ -96,0 +98,0 @@ request: {

@@ -113,2 +113,3 @@ import { Utility } from '@aws-lambda-powertools/commons';

declare class Tracer extends Utility implements TracerInterface {
#private;
/**

@@ -141,6 +142,2 @@ * The provider service interface used by the Tracer.

/**
* The environment variables service used by the Tracer, is always initialized in the constructor in setOptions().
*/
private envVarsService;
/**
* The name of the service, is always initialized in the constructor in setOptions().

@@ -188,2 +185,4 @@ */

/**
* @deprecated Use {@link captureAWSv3Client | `captureAWSv3Client()`} instead.
*
* Patch all AWS SDK v2 clients and create traces when your application makes calls to AWS services.

@@ -207,3 +206,2 @@ *

*
* @deprecated Use {@link captureAWSv3Client} instead.
* @param aws - AWS SDK v2 import

@@ -213,2 +211,4 @@ */

/**
* @deprecated Use {@link captureAWSv3Client | `captureAWSv3Client()`} instead.
*
* Patch a specific AWS SDK v2 client and create traces when your application makes calls to that AWS service.

@@ -232,3 +232,3 @@ *

* ```
* @deprecated Use {@link captureAWSv3Client} instead.
*
* @param service - AWS SDK v2 client

@@ -469,7 +469,2 @@ */

/**
* Get for `envVarsService`.
* Used internally during initialization.
*/
private getEnvVarsService;
/**
* Determine if we are running inside an Amplify CLI process.

@@ -476,0 +471,0 @@ * Used internally during initialization.

@@ -18,4 +18,4 @@ "use strict";

const commons_1 = require("@aws-lambda-powertools/commons");
const env_1 = require("@aws-lambda-powertools/commons/utils/env");
const aws_xray_sdk_core_1 = __importDefault(require("aws-xray-sdk-core"));
const EnvironmentVariablesService_js_1 = require("./config/EnvironmentVariablesService.js");
const ProviderService_js_1 = require("./provider/ProviderService.js");

@@ -157,6 +157,13 @@ const { Subsegment: XraySubsegment } = aws_xray_sdk_core_1.default;

/**
* The environment variables service used by the Tracer, is always initialized in the constructor in setOptions().
* Cache environment variables once at init time.
*/
envVarsService;
// serviceName is always initialized in the constructor in setOptions()
#envConfig = {
awsExecutionEnv: '',
samLocal: '',
captureError: '',
captureHTTPsRequests: '',
captureResponse: '',
tracingEnabled: '',
serviceName: '',
};
/**

@@ -173,2 +180,3 @@ * The name of the service, is always initialized in the constructor in setOptions().

super();
this.#setEnvConfig();
this.setOptions(options);

@@ -247,2 +255,4 @@ this.provider = new ProviderService_js_1.ProviderService();

/**
* @deprecated Use {@link captureAWSv3Client | `captureAWSv3Client()`} instead.
*
* Patch all AWS SDK v2 clients and create traces when your application makes calls to AWS services.

@@ -266,11 +276,12 @@ *

*
* @deprecated Use {@link captureAWSv3Client} instead.
* @param aws - AWS SDK v2 import
*/
captureAWS(aws) {
/* v8 ignore start */ captureAWS(aws) {
if (!this.isTracingEnabled())
return aws;
return this.provider.captureAWS(aws);
}
} /* v8 ignore stop */
/**
* @deprecated Use {@link captureAWSv3Client | `captureAWSv3Client()`} instead.
*
* Patch a specific AWS SDK v2 client and create traces when your application makes calls to that AWS service.

@@ -294,3 +305,3 @@ *

* ```
* @deprecated Use {@link captureAWSv3Client} instead.
*
* @param service - AWS SDK v2 client

@@ -529,3 +540,3 @@ */

getRootXrayTraceId() {
return this.envVarsService.getXrayTraceId();
return (0, env_1.getXRayTraceIdFromEnv)();
}

@@ -572,3 +583,3 @@ /**

return false;
return this.envVarsService.getXrayTraceSampled();
return (0, env_1.isRequestXRaySampled)();
}

@@ -669,9 +680,2 @@ /**

/**
* Get for `envVarsService`.
* Used internally during initialization.
*/
getEnvVarsService() {
return this.envVarsService;
}
/**
* Determine if we are running inside an Amplify CLI process.

@@ -681,4 +685,3 @@ * Used internally during initialization.

isAmplifyCli() {
return (this.getEnvVarsService().getAwsExecutionEnv() ===
'AWS_Lambda_amplify-mock');
return this.#envConfig.awsExecutionEnv === 'AWS_Lambda_amplify-mock';
}

@@ -690,3 +693,3 @@ /**

isLambdaExecutionEnv() {
return this.getEnvVarsService().getAwsExecutionEnv() !== '';
return this.#envConfig.awsExecutionEnv !== '';
}

@@ -698,3 +701,3 @@ /**

isLambdaSamCli() {
return this.getEnvVarsService().getSamLocal() !== '';
return this.#envConfig.samLocal !== '';
}

@@ -712,4 +715,3 @@ /**

}
const envVarsValue = this.getEnvVarsService().getTracingCaptureError();
if (envVarsValue.toLowerCase() === 'false') {
if (this.#envConfig.captureError.toLowerCase() === 'false') {
this.captureError = false;

@@ -740,4 +742,3 @@ return;

}
const envVarsValue = this.getEnvVarsService().getCaptureHTTPsRequests();
if (envVarsValue.toLowerCase() === 'false') {
if (this.#envConfig.captureHTTPsRequests.toLowerCase() === 'false') {
this.captureHTTPsRequests = false;

@@ -758,4 +759,3 @@ return;

}
const envVarsValue = this.getEnvVarsService().getTracingCaptureResponse();
if (envVarsValue.toLowerCase() === 'false') {
if (this.#envConfig.captureResponse.toLowerCase() === 'false') {
this.captureResponse = false;

@@ -784,3 +784,2 @@ return;

const { enabled, serviceName, captureHTTPsRequests, customConfigService } = options;
this.envVarsService = EnvironmentVariablesService_js_1.environmentVariablesService;
this.setCustomConfigService(customConfigService);

@@ -811,5 +810,5 @@ this.setTracingEnabled(enabled);

}
const envVarsValue = this.getEnvVarsService().getServiceName();
if (envVarsValue !== undefined && this.isValidServiceName(envVarsValue)) {
this.serviceName = envVarsValue;
if (this.#envConfig.serviceName !== undefined &&
this.isValidServiceName(this.#envConfig.serviceName)) {
this.serviceName = this.#envConfig.serviceName;
return;

@@ -836,4 +835,3 @@ }

}
const envVarsValue = this.getEnvVarsService().getTracingEnabled();
if (envVarsValue.toLowerCase() === 'false') {
if (this.#envConfig.tracingEnabled.toLowerCase() === 'false') {
this.tracingEnabled = false;

@@ -848,3 +846,34 @@ return;

}
/**
* Set environment variables for the tracer.
* This method is called during initialization to ensure environment variables are available.
*/
#setEnvConfig() {
this.#envConfig.awsExecutionEnv = (0, env_1.getStringFromEnv)({
key: 'AWS_EXECUTION_ENV',
defaultValue: '',
});
this.#envConfig.samLocal = (0, env_1.getStringFromEnv)({
key: 'AWS_SAM_LOCAL',
defaultValue: '',
});
this.#envConfig.captureError = (0, env_1.getStringFromEnv)({
key: 'POWERTOOLS_TRACER_CAPTURE_ERROR',
defaultValue: '',
});
this.#envConfig.captureHTTPsRequests = (0, env_1.getStringFromEnv)({
key: 'POWERTOOLS_TRACER_CAPTURE_HTTPS_REQUESTS',
defaultValue: '',
});
this.#envConfig.captureResponse = (0, env_1.getStringFromEnv)({
key: 'POWERTOOLS_TRACER_CAPTURE_RESPONSE',
defaultValue: '',
});
this.#envConfig.tracingEnabled = (0, env_1.getStringFromEnv)({
key: 'POWERTOOLS_TRACE_ENABLED',
defaultValue: '',
});
this.#envConfig.serviceName = (0, env_1.getServiceName)();
}
}
exports.Tracer = Tracer;

@@ -1,2 +0,2 @@

export type { TracerOptions, CaptureLambdaHandlerOptions, CaptureMethodOptions, HandlerMethodDecorator, AnyClass, AnyClassMethod, MethodDecorator, TracerInterface, } from './Tracer.js';
export type { AnyClass, AnyClassMethod, CaptureLambdaHandlerOptions, CaptureMethodOptions, HandlerMethodDecorator, MethodDecorator, TracerInterface, TracerOptions, } from './Tracer.js';
//# sourceMappingURL=index.d.ts.map

@@ -17,7 +17,7 @@ import type { Segment, Subsegment } from 'aws-xray-sdk-core';

/**
* @deprecated
* @deprecated Use {@link captureAWSv3Client} instead.
*/
captureAWS<T>(awssdk: T): T;
/**
* @deprecated
* @deprecated Use {@link captureAWSv3Client} instead.
*/

@@ -24,0 +24,0 @@ captureAWSClient<T>(service: T): T;

@@ -7,3 +7,3 @@ import xraySdk from 'aws-xray-sdk-core';

import { addUserAgentMiddleware } from '@aws-lambda-powertools/commons';
import { environmentVariablesService } from '../config/EnvironmentVariablesService.js';
import { getXRayTraceIdFromEnv } from '@aws-lambda-powertools/commons/utils/env';
import { findHeaderAndDecode, getRequestURL, isHttpSubsegment, } from './utilities.js';

@@ -23,13 +23,13 @@ /**

/**
* @deprecated
* @deprecated Use {@link captureAWSv3Client} instead.
*/
captureAWS(awssdk) {
/* v8 ignore start */ captureAWS(awssdk) {
return captureAWS(awssdk);
}
} /* v8 ignore stop */
/**
* @deprecated
* @deprecated Use {@link captureAWSv3Client} instead.
*/
captureAWSClient(service) {
/* v8 ignore start */ captureAWSClient(service) {
return captureAWSClient(service);
}
} /* v8 ignore stop */
captureAWSv3Client(service) {

@@ -78,6 +78,8 @@ addUserAgentMiddleware(service, 'tracer');

const { request } = message;
const method = request.method;
if (method === 'CONNECT')
return;
const parentSubsegment = this.getSegment();
const requestURL = getRequestURL(request);
if (parentSubsegment && requestURL) {
const method = request.method;
const subsegment = parentSubsegment.addNewSubsegment(requestURL.hostname);

@@ -87,3 +89,3 @@ subsegment.addAttribute('namespace', 'remote');

// @ts-expect-error
request.addHeader('X-Amzn-Trace-Id', `Root=${environmentVariablesService.getXrayTraceId()};Parent=${subsegment.id};Sampled=${subsegment.notTraced ? '0' : '1'}`);
request.addHeader('X-Amzn-Trace-Id', `Root=${getXRayTraceIdFromEnv()};Parent=${subsegment.id};Sampled=${subsegment.notTraced ? '0' : '1'}`);
subsegment.http = {

@@ -90,0 +92,0 @@ request: {

@@ -113,2 +113,3 @@ import { Utility } from '@aws-lambda-powertools/commons';

declare class Tracer extends Utility implements TracerInterface {
#private;
/**

@@ -141,6 +142,2 @@ * The provider service interface used by the Tracer.

/**
* The environment variables service used by the Tracer, is always initialized in the constructor in setOptions().
*/
private envVarsService;
/**
* The name of the service, is always initialized in the constructor in setOptions().

@@ -188,2 +185,4 @@ */

/**
* @deprecated Use {@link captureAWSv3Client | `captureAWSv3Client()`} instead.
*
* Patch all AWS SDK v2 clients and create traces when your application makes calls to AWS services.

@@ -207,3 +206,2 @@ *

*
* @deprecated Use {@link captureAWSv3Client} instead.
* @param aws - AWS SDK v2 import

@@ -213,2 +211,4 @@ */

/**
* @deprecated Use {@link captureAWSv3Client | `captureAWSv3Client()`} instead.
*
* Patch a specific AWS SDK v2 client and create traces when your application makes calls to that AWS service.

@@ -232,3 +232,3 @@ *

* ```
* @deprecated Use {@link captureAWSv3Client} instead.
*
* @param service - AWS SDK v2 client

@@ -469,7 +469,2 @@ */

/**
* Get for `envVarsService`.
* Used internally during initialization.
*/
private getEnvVarsService;
/**
* Determine if we are running inside an Amplify CLI process.

@@ -476,0 +471,0 @@ * Used internally during initialization.

@@ -12,4 +12,4 @@ /**

import { Utility } from '@aws-lambda-powertools/commons';
import { getServiceName, getStringFromEnv, getXRayTraceIdFromEnv, isRequestXRaySampled, } from '@aws-lambda-powertools/commons/utils/env';
import xraySdk from 'aws-xray-sdk-core';
import { environmentVariablesService, } from './config/EnvironmentVariablesService.js';
import { ProviderService } from './provider/ProviderService.js';

@@ -151,6 +151,13 @@ const { Subsegment: XraySubsegment } = xraySdk;

/**
* The environment variables service used by the Tracer, is always initialized in the constructor in setOptions().
* Cache environment variables once at init time.
*/
envVarsService;
// serviceName is always initialized in the constructor in setOptions()
#envConfig = {
awsExecutionEnv: '',
samLocal: '',
captureError: '',
captureHTTPsRequests: '',
captureResponse: '',
tracingEnabled: '',
serviceName: '',
};
/**

@@ -167,2 +174,3 @@ * The name of the service, is always initialized in the constructor in setOptions().

super();
this.#setEnvConfig();
this.setOptions(options);

@@ -241,2 +249,4 @@ this.provider = new ProviderService();

/**
* @deprecated Use {@link captureAWSv3Client | `captureAWSv3Client()`} instead.
*
* Patch all AWS SDK v2 clients and create traces when your application makes calls to AWS services.

@@ -260,11 +270,12 @@ *

*
* @deprecated Use {@link captureAWSv3Client} instead.
* @param aws - AWS SDK v2 import
*/
captureAWS(aws) {
/* v8 ignore start */ captureAWS(aws) {
if (!this.isTracingEnabled())
return aws;
return this.provider.captureAWS(aws);
}
} /* v8 ignore stop */
/**
* @deprecated Use {@link captureAWSv3Client | `captureAWSv3Client()`} instead.
*
* Patch a specific AWS SDK v2 client and create traces when your application makes calls to that AWS service.

@@ -288,3 +299,3 @@ *

* ```
* @deprecated Use {@link captureAWSv3Client} instead.
*
* @param service - AWS SDK v2 client

@@ -523,3 +534,3 @@ */

getRootXrayTraceId() {
return this.envVarsService.getXrayTraceId();
return getXRayTraceIdFromEnv();
}

@@ -566,3 +577,3 @@ /**

return false;
return this.envVarsService.getXrayTraceSampled();
return isRequestXRaySampled();
}

@@ -663,9 +674,2 @@ /**

/**
* Get for `envVarsService`.
* Used internally during initialization.
*/
getEnvVarsService() {
return this.envVarsService;
}
/**
* Determine if we are running inside an Amplify CLI process.

@@ -675,4 +679,3 @@ * Used internally during initialization.

isAmplifyCli() {
return (this.getEnvVarsService().getAwsExecutionEnv() ===
'AWS_Lambda_amplify-mock');
return this.#envConfig.awsExecutionEnv === 'AWS_Lambda_amplify-mock';
}

@@ -684,3 +687,3 @@ /**

isLambdaExecutionEnv() {
return this.getEnvVarsService().getAwsExecutionEnv() !== '';
return this.#envConfig.awsExecutionEnv !== '';
}

@@ -692,3 +695,3 @@ /**

isLambdaSamCli() {
return this.getEnvVarsService().getSamLocal() !== '';
return this.#envConfig.samLocal !== '';
}

@@ -706,4 +709,3 @@ /**

}
const envVarsValue = this.getEnvVarsService().getTracingCaptureError();
if (envVarsValue.toLowerCase() === 'false') {
if (this.#envConfig.captureError.toLowerCase() === 'false') {
this.captureError = false;

@@ -734,4 +736,3 @@ return;

}
const envVarsValue = this.getEnvVarsService().getCaptureHTTPsRequests();
if (envVarsValue.toLowerCase() === 'false') {
if (this.#envConfig.captureHTTPsRequests.toLowerCase() === 'false') {
this.captureHTTPsRequests = false;

@@ -752,4 +753,3 @@ return;

}
const envVarsValue = this.getEnvVarsService().getTracingCaptureResponse();
if (envVarsValue.toLowerCase() === 'false') {
if (this.#envConfig.captureResponse.toLowerCase() === 'false') {
this.captureResponse = false;

@@ -778,3 +778,2 @@ return;

const { enabled, serviceName, captureHTTPsRequests, customConfigService } = options;
this.envVarsService = environmentVariablesService;
this.setCustomConfigService(customConfigService);

@@ -805,5 +804,5 @@ this.setTracingEnabled(enabled);

}
const envVarsValue = this.getEnvVarsService().getServiceName();
if (envVarsValue !== undefined && this.isValidServiceName(envVarsValue)) {
this.serviceName = envVarsValue;
if (this.#envConfig.serviceName !== undefined &&
this.isValidServiceName(this.#envConfig.serviceName)) {
this.serviceName = this.#envConfig.serviceName;
return;

@@ -830,4 +829,3 @@ }

}
const envVarsValue = this.getEnvVarsService().getTracingEnabled();
if (envVarsValue.toLowerCase() === 'false') {
if (this.#envConfig.tracingEnabled.toLowerCase() === 'false') {
this.tracingEnabled = false;

@@ -842,3 +840,34 @@ return;

}
/**
* Set environment variables for the tracer.
* This method is called during initialization to ensure environment variables are available.
*/
#setEnvConfig() {
this.#envConfig.awsExecutionEnv = getStringFromEnv({
key: 'AWS_EXECUTION_ENV',
defaultValue: '',
});
this.#envConfig.samLocal = getStringFromEnv({
key: 'AWS_SAM_LOCAL',
defaultValue: '',
});
this.#envConfig.captureError = getStringFromEnv({
key: 'POWERTOOLS_TRACER_CAPTURE_ERROR',
defaultValue: '',
});
this.#envConfig.captureHTTPsRequests = getStringFromEnv({
key: 'POWERTOOLS_TRACER_CAPTURE_HTTPS_REQUESTS',
defaultValue: '',
});
this.#envConfig.captureResponse = getStringFromEnv({
key: 'POWERTOOLS_TRACER_CAPTURE_RESPONSE',
defaultValue: '',
});
this.#envConfig.tracingEnabled = getStringFromEnv({
key: 'POWERTOOLS_TRACE_ENABLED',
defaultValue: '',
});
this.#envConfig.serviceName = getServiceName();
}
}
export { Tracer };

@@ -1,2 +0,2 @@

export type { TracerOptions, CaptureLambdaHandlerOptions, CaptureMethodOptions, HandlerMethodDecorator, AnyClass, AnyClassMethod, MethodDecorator, TracerInterface, } from './Tracer.js';
export type { AnyClass, AnyClassMethod, CaptureLambdaHandlerOptions, CaptureMethodOptions, HandlerMethodDecorator, MethodDecorator, TracerInterface, TracerOptions, } from './Tracer.js';
//# sourceMappingURL=index.d.ts.map
{
"name": "@aws-lambda-powertools/tracer",
"version": "2.23.0",
"version": "2.24.0",
"description": "The tracer package for the Powertools for AWS Lambda (TypeScript) library",

@@ -28,3 +28,3 @@ "author": {

"dependencies": {
"@aws-lambda-powertools/commons": "^2.23.0",
"@aws-lambda-powertools/commons": "^2.24.0",
"aws-xray-sdk-core": "^3.10.3"

@@ -31,0 +31,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet