@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;
@@ -299,6 +299,7 @@ class JaypieAccountLoggingBucket extends constructs.Construct {
299
299
 
300
300
  function addDatadogLayers(lambdaFunction, options = {}) {
301
301
  const datadogApiKeyArn = options?.datadogApiKeyArn;
302
+ const resolvedService = options?.serviceTag || process.env.PROJECT_SERVICE;
302
303
  const resolvedDatadogApiKeyArn = datadogApiKeyArn ||
303
304
  process.env.DATADOG_API_KEY_ARN ||
304
305
  process.env.CDK_ENV_DATADOG_API_KEY_ARN;
@@ -312,12 +313,12 @@ function addDatadogLayers(lambdaFunction, options = {}) {
312
313
  DD_ENV: process.env.PROJECT_ENV || "",
313
314
  DD_PROFILING_ENABLED: "false",
314
315
  DD_SERVERLESS_APPSEC_ENABLED: "false",
315
- DD_SERVICE: process.env.PROJECT_SERVICE || "",
316
+ DD_SERVICE: resolvedService || "",
316
317
  DD_SITE: CDK$2.DATADOG.SITE,
317
318
  DD_TAGS: `${CDK$2.TAG.SPONSOR}:${process.env.PROJECT_SPONSOR || ""}`,
318
319
  DD_TRACE_OTEL_ENABLED: "false",
319
320
  };
320
- // Add environment variables only if they don't already exist
321
+ // Apply Datadog environment variables (overwrites existing keys)
321
322
  Object.entries(datadogEnvVars).forEach(([key, value]) => {
322
323
  lambdaFunction.addEnvironment(key, value);
323
324
  });
@@ -327,7 +328,7 @@ function addDatadogLayers(lambdaFunction, options = {}) {
327
328
  nodeLayerVersion: CDK$2.DATADOG.LAYER.NODE,
328
329
  extensionLayerVersion: CDK$2.DATADOG.LAYER.EXTENSION,
329
330
  env: process.env.PROJECT_ENV,
330
- service: process.env.PROJECT_SERVICE,
331
+ service: resolvedService,
331
332
  version: process.env.PROJECT_VERSION,
332
333
  });
333
334
  datadogLambda.addLambdaFunctions([lambdaFunction]);
@@ -738,7 +739,7 @@ function isValidSubdomain(subdomain) {
738
739
  }
739
740
 
740
741
  function jaypieLambdaEnv(options = {}) {
741
- const { initialEnvironment = {} } = options;
742
+ const { initialEnvironment = {}, serviceTag } = options;
742
743
  // Start with empty environment - we'll only add valid values
743
744
  let environment = {};
744
745
  // First, add all valid string values from initialEnvironment
@@ -767,6 +768,11 @@ function jaypieLambdaEnv(options = {}) {
767
768
  environment[key] = defaultValue;
768
769
  }
769
770
  });
771
+ // Apply serviceTag as DD_SERVICE unless explicitly overridden.
772
+ // Precedence: explicit environment > serviceTag > process.env.PROJECT_SERVICE
773
+ if (serviceTag && !environment.DD_SERVICE) {
774
+ environment.DD_SERVICE = serviceTag;
775
+ }
770
776
  // Default environment variables from process.env if present
771
777
  const defaultEnvVars = [
772
778
  "DATADOG_API_KEY_ARN",
@@ -1638,7 +1644,7 @@ class JaypieLambda extends constructs.Construct {
1638
1644
  // Resolve environment from array or object syntax
1639
1645
  const initialEnvironment = resolveEnvironment(environmentInput);
1640
1646
  // Get base environment with defaults
1641
- const environment = jaypieLambdaEnv({ initialEnvironment });
1647
+ const environment = jaypieLambdaEnv({ initialEnvironment, serviceTag });
1642
1648
  // Resolve secrets from mixed array (strings and JaypieSecret instances)
1643
1649
  // Use Stack.of(this) to ensure secrets are shared at stack level across all constructs
1644
1650
  const secrets = resolveSecrets(cdk.Stack.of(this), secretsInput);
@@ -1715,7 +1721,10 @@ class JaypieLambda extends constructs.Construct {
1715
1721
  }
1716
1722
  : undefined,
1717
1723
  });
1718
- addDatadogLayers(this._lambda, { datadogApiKeyArn });
1724
+ addDatadogLayers(this._lambda, {
1725
+ datadogApiKeyArn,
1726
+ serviceTag: environment.DD_SERVICE,
1727
+ });
1719
1728
  // Grant secret read permissions
1720
1729
  Object.values(envSecrets).forEach((secret) => {
1721
1730
  secret.grantRead(this._lambda);