-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathtag.ts
More file actions
51 lines (46 loc) · 1.62 KB
/
Copy pathtag.ts
File metadata and controls
51 lines (46 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Unless explicitly stated otherwise all files in this repository are licensed
* under the Apache License Version 2.0.
*
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2020-2026 Datadog, Inc.
*/
import { Tags } from "aws-cdk-lib";
import * as lambda from "aws-cdk-lib/aws-lambda";
import * as sfn from "aws-cdk-lib/aws-stepfunctions";
import log from "loglevel";
import { TagKeys, DatadogLambdaProps, DatadogStepFunctionsProps } from "./index";
import { LambdaFunction } from "./interfaces";
const versionJson = require("../version.json");
export function setTags(
resource: LambdaFunction | sfn.StateMachine,
props: DatadogLambdaProps | DatadogStepFunctionsProps,
): void {
log.debug(`Adding datadog tags`);
const taggable = resource instanceof lambda.SingletonFunction ? resource.permissionsNode.defaultChild! : resource;
if (props.env) {
Tags.of(taggable).add(TagKeys.ENV, props.env);
}
if (props.service) {
Tags.of(taggable).add(TagKeys.SERVICE, props.service);
}
if (props.version) {
Tags.of(taggable).add(TagKeys.VERSION, props.version);
}
if (props.tags) {
const tagsArray = props.tags.split(",");
tagsArray.forEach((tag: string) => {
const [key, value] = tag.split(":");
if (key && value) {
Tags.of(taggable).add(key, value);
}
});
}
if (resource instanceof sfn.StateMachine) {
setStepFunctionTags(resource);
}
}
function setStepFunctionTags(stateMachine: sfn.StateMachine) {
Tags.of(stateMachine).add(TagKeys.DD_TRACE_ENABLED, "true");
Tags.of(stateMachine).add(TagKeys.CDK, `v${versionJson.version}`);
}