@jaypie/constructs 1.2.60 → 1.2.62

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.
@@ -1,5 +1,6 @@
1
1
  import * as lambda from "aws-cdk-lib/aws-lambda";
2
2
  export interface AddDatadogLayerOptions {
3
3
  datadogApiKeyArn?: string;
4
+ serviceTag?: string;
4
5
  }
5
6
  export declare function addDatadogLayers(lambdaFunction: lambda.Function, options?: AddDatadogLayerOptions): boolean;
@@ -2,6 +2,7 @@ export interface JaypieLambdaEnvOptions {
2
2
  initialEnvironment?: {
3
3
  [key: string]: string;
4
4
  };
5
+ serviceTag?: string;
5
6
  }
6
7
  export declare function jaypieLambdaEnv(options?: JaypieLambdaEnvOptions): {
7
8
  [key: string]: string;
package/dist/esm/index.js CHANGED
@@ -263,6 +263,7 @@ class JaypieAccountLoggingBucket extends Construct {
263
263
 
264
264
  function addDatadogLayers(lambdaFunction, options = {}) {
265
265
  const datadogApiKeyArn = options?.datadogApiKeyArn;
266
+ const resolvedService = options?.serviceTag || process.env.PROJECT_SERVICE;
266
267
  const resolvedDatadogApiKeyArn = datadogApiKeyArn ||
267
268
  process.env.DATADOG_API_KEY_ARN ||
268
269
  process.env.CDK_ENV_DATADOG_API_KEY_ARN;
@@ -276,12 +277,12 @@ function addDatadogLayers(lambdaFunction, options = {}) {
276
277
  DD_ENV: process.env.PROJECT_ENV || "",
277
278
  DD_PROFILING_ENABLED: "false",
278
279
  DD_SERVERLESS_APPSEC_ENABLED: "false",
279
- DD_SERVICE: process.env.PROJECT_SERVICE || "",
280
+ DD_SERVICE: resolvedService || "",
280
281
  DD_SITE: CDK$2.DATADOG.SITE,
281
282
  DD_TAGS: `${CDK$2.TAG.SPONSOR}:${process.env.PROJECT_SPONSOR || ""}`,
282
283
  DD_TRACE_OTEL_ENABLED: "false",
283
284
  };
284
- // Add environment variables only if they don't already exist
285
+ // Apply Datadog environment variables (overwrites existing keys)
285
286
  Object.entries(datadogEnvVars).forEach(([key, value]) => {
286
287
  lambdaFunction.addEnvironment(key, value);
287
288
  });
@@ -291,7 +292,7 @@ function addDatadogLayers(lambdaFunction, options = {}) {
291
292
  nodeLayerVersion: CDK$2.DATADOG.LAYER.NODE,
292
293
  extensionLayerVersion: CDK$2.DATADOG.LAYER.EXTENSION,
293
294
  env: process.env.PROJECT_ENV,
294
- service: process.env.PROJECT_SERVICE,
295
+ service: resolvedService,
295
296
  version: process.env.PROJECT_VERSION,
296
297
  });
297
298
  datadogLambda.addLambdaFunctions([lambdaFunction]);
@@ -702,7 +703,7 @@ function isValidSubdomain(subdomain) {
702
703
  }
703
704
 
704
705
  function jaypieLambdaEnv(options = {}) {
705
- const { initialEnvironment = {} } = options;
706
+ const { initialEnvironment = {}, serviceTag } = options;
706
707
  // Start with empty environment - we'll only add valid values
707
708
  let environment = {};
708
709
  // First, add all valid string values from initialEnvironment
@@ -731,6 +732,11 @@ function jaypieLambdaEnv(options = {}) {
731
732
  environment[key] = defaultValue;
732
733
  }
733
734
  });
735
+ // Apply serviceTag as DD_SERVICE unless explicitly overridden.
736
+ // Precedence: explicit environment > serviceTag > process.env.PROJECT_SERVICE
737
+ if (serviceTag && !environment.DD_SERVICE) {
738
+ environment.DD_SERVICE = serviceTag;
739
+ }
734
740
  // Default environment variables from process.env if present
735
741
  const defaultEnvVars = [
736
742
  "DATADOG_API_KEY_ARN",
@@ -1602,7 +1608,7 @@ class JaypieLambda extends Construct {
1602
1608
  // Resolve environment from array or object syntax
1603
1609
  const initialEnvironment = resolveEnvironment(environmentInput);
1604
1610
  // Get base environment with defaults
1605
- const environment = jaypieLambdaEnv({ initialEnvironment });
1611
+ const environment = jaypieLambdaEnv({ initialEnvironment, serviceTag });
1606
1612
  // Resolve secrets from mixed array (strings and JaypieSecret instances)
1607
1613
  // Use Stack.of(this) to ensure secrets are shared at stack level across all constructs
1608
1614
  const secrets = resolveSecrets(Stack.of(this), secretsInput);
@@ -1679,7 +1685,10 @@ class JaypieLambda extends Construct {
1679
1685
  }
1680
1686
  : undefined,
1681
1687
  });
1682
- addDatadogLayers(this._lambda, { datadogApiKeyArn });
1688
+ addDatadogLayers(this._lambda, {
1689
+ datadogApiKeyArn,
1690
+ serviceTag: environment.DD_SERVICE,
1691
+ });
1683
1692
  // Grant secret read permissions
1684
1693
  Object.values(envSecrets).forEach((secret) => {
1685
1694
  secret.grantRead(this._lambda);