Skip to content

Datadog

This construct can be used to add Datadog instrumentation into Remix Applications. It's also easy to use in other lambda based setups.

Note: The general purpose Fargate integration is not yet ready.

Usage Example (Remix)

To add Datadog integration for the RemixApp, use the Datadog construct from the remix-tools package.

Usage Example (general Lambda)

For general purpose Lambda instrumentation, the API is slightly different:

import { Datadog } from '@pit-shared/cdk/datadog'
import * as lambda from 'aws-cdk-lib/aws-lambda'

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

const datadog = new Datadog(scope, 'datadog', {
    apiKey: 'api key',
    env: 'dev', // one of dev, stage or prod
    service: 'service-name',
    team: 'ai-experience',
    cluster: 'api-ecosystems',
    costCategory: 'operational',
    repositoryUrl: 'github.com/pit-shared/remix-tools',
    version: 'service version',
    tags: ['tag-name:tag-value'],
})

const fn = new lambda.Function(scope, 'lambda', {
    runtime: lambda.Runtime.NODEJS_LATEST,
    code: lambda.Code.fromInline(`export const handler = () => { ... }`),
    handler: 'index.handler',
})
datadog.instrumentLambda(fn)

Usage Example (Docker Lambda)

For general purpose Lambda instrumentation, the API is slightly different:

import { Datadog } from '@pit-shared/cdk/datadog'
import * as lambda from 'aws-cdk-lib/aws-lambda'

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

const datadog = new Datadog(scope, 'datadog', {
    apiKey: 'api key',
    env: 'dev', // one of dev, stage or prod
    service: 'service-name',
    team: 'ai-experience',
    cluster: 'api-ecosystems',
    costCategory: 'operational',
    repositoryUrl: 'github.com/pit-shared/remix-tools',
    version: 'service version',
    tags: ['tag-name:tag-value'],
})

const fn = new lambda.DockerImageFunction(scope, 'lambda', {
    //...
    code: lambda.DockerImageCode.fromImageAsset('/path/to/dockerimage', {
        // ...
        buildArgs: {
            NODE_VERSION: '22',
            ...datadog?.getDockerLambdaBuildArgs(),
        },
    }),
})
datadog.instrumentDockerLambda(fn)

Usage Example (general Fargate)

For general purpose Fargate instrumentation, use this API:

import { Datadog } from '@pit-shared/cdk/datadog'
import { FargateApp } from '@pit-shared/cdk/fargate'
import * as ecs from 'aws-cdk-lib/aws-ecs'

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

class MyFargateApp extends FargateApp {
    protected getContainerImage(): ecs.ContainerImage {
        return ecs.ContainerImage.fromRegistry('node:latest')
    }
}

const datadog = new Datadog(scope, 'datadog', {
    apiKey: 'api key',
    env: 'dev', // one of dev, stage or prod
    service: 'service-name',
    team: 'ai-experience',
    cluster: 'api-ecosystems',
    costCategory: 'operational',
    repositoryUrl: 'github.com/pit-shared/remix-tools',
    version: 'service version',
    tags: ['tag-name:tag-value'],
})

new MyFargateApp(scope, 'fargate', {
    datadog, // <-- connect datadog with your app
    dns: {
        domainName: 'example.com',
        hostedZoneId: '1234',
        zoneName: 'example.com',
    },
    network: {
        vpcId: 'vpc-1234567890abcdef0',
        internetGatewayId: 'igw-1234',
    },
})

Usage Example (using a Secret for the Api-Key)

import { Datadog } from '@pit-shared/cdk/datadog'
import { FargateApp } from '@pit-shared/cdk/fargate'
import * as ecs from 'aws-cdk-lib/aws-ecs'
import * as sm from 'aws-cdk-lib/aws-secretsmanager'

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

class MyFargateApp extends FargateApp {
    protected getContainerImage(): ecs.ContainerImage {
        return ecs.ContainerImage.fromRegistry('node:latest')
    }
}

const datadog = new Datadog(scope, 'datadog', {
    apiKey: sm.Secret.fromSecretPartialArn(
        scope,
        'dd-secret',
        'arn:aws:secretsmanager:eu-central-1:1234:secret:dd-secret',
    ),
    env: 'dev', // one of dev, stage or prod
    service: 'service-name',
    team: 'ai-experience',
    cluster: 'api-ecosystems',
    costCategory: 'operational',
    repositoryUrl: 'github.com/pit-shared/remix-tools',
    version: 'service version',
    tags: ['tag-name:tag-value'],
})

new MyFargateApp(scope, 'fargate', {
    datadog, // <-- connect datadog with your app
    dns: {
        domainName: 'example.com',
        hostedZoneId: '1234',
        zoneName: 'example.com',
    },
    network: {
        vpcId: 'vpc-1234567890abcdef0',
        internetGatewayId: 'igw-1234',
    },
})

API

The Datadog construct does support the following properties:

/**
 * The Datadog API Key, as a string or a secret.
 */
apiKey?: string | ISecret
/**
 * The environment the service is running in.
 */
env: Environment
/**
 * The service name.
 */
service: string
/**
 * the team the service belongs to.
 */
team: Team
/**
 * The cluster the team belongs to.
 */
cluster: Cluster
/**
 * The cost category the service belongs to.
 */
costCategory: CostCategory
/**
 * The service version.
 */
version: string
/**
 * The tags to be added to the service.
 */
tags?: `${string}:${string}`[]
/**
 * whether the logging sidecars should be essential or not.
 */
essential?: boolean
/**
 * enable DD tracing
 */
trace?: boolean
/**
 * enable DD logs
 */
logs?: boolean
/**
 * enable DD asm
 */
asm?: boolean
/**
 * whether to add version tags to AWS resources.
 */
versionResources?: boolean
/**
 * The log-group to use, otherwise a new one is created.
 */
logGroup?: logs.ILogGroup
/**
 * the repository URL of the service, used for source code integration.
 */
repositoryUrl:
    | `github.com/${string}/${string}`
    | `git@github.com:${string}/${string}`
    | `https://github.com/${string}/${string}`
    | `git://github.com/${string}/${string}`