Skip to content

Log Group Tagger

The Log Group Tagger is a utility for tagging AWS CloudWatch Log Groups which are created implicitly by AWS and are not part of your CDK stack.

import { LogGroupTagger } from '@pit-shared/cdk/log-group-tagger'
import { Datadog } from '@pit-shared/cdk/datadog'
import * as logs from 'aws-cdk-lib/aws-logs'

declare const scope: import('aws-cdk-lib').Stack

const datadog = new Datadog(scope, 'Datadog', {
    env: 'production',
    service: 'my-service',
    team: 'architects',
    cluster: 'other',
    costCategory: 'operational',
    repositoryUrl: 'github.com/pit-shared/my-service',
    version: '1.0.0',
})

new LogGroupTagger(scope, 'MyLogGroupTagger', {
    logGroupPattern: '/foo/bar',
    retention: logs.RetentionDays.ONE_WEEK,
    datadog,
})

Whenever ever a LogGroup is created that matches the pattern it will get tagged with the provided tags. This will pull the relevant tags from the provided Datadog construct.

API

/**
 * The LogGroup Pattern to watch out for.
 */
logGroupPattern: string
/**
 * Datadog integration for the custom resource.
 */
datadog?: Datadog
/**
 * The log-group to use for the Lambda function logs.
 * If none is given a new log-group will be created.
 */
logGroup?: logs.ILogGroup
/**
 * The retention period for the log group.
 */
retention?: logs.RetentionDays