Skip to content

Clarifying behavior of env, service, and version when extension_layer_version is not provided (ie because lambda docker image is used) #320

@pviolette3

Description

@pviolette3

Expected Behavior

Given below code, with lambda_handlers running Docker images,

    datadog = Datadog(
        stack,
        "Datadog",
        add_layers=False,  # Extension provided in Dockerfiles. We don't add layers here.
        # NOTE: Extension layer is NOT used however we do need it to add the tags we're specifying in the construct.
        # https://github.com/DataDog/datadog-cdk-constructs/blob/main/src/env.ts#L127
        **extension_layer_version=None,**
        api_key_secret=datadog_api_key,
        site="datadoghq.com",
        enable_datadog_logs=True,
        enable_datadog_tracing=True,
        enable_merge_xray_traces=True,
        inject_log_context=True,
        log_level="debug",
        capture_lambda_payload=True,
        env=stage_name,
        service=stack.stack_name,
        version=version,
    )
    datadog.add_lambda_functions(lambda_handlers)

the env, service, and version should correspond to the DD_ENV, DD_SERVICE, and DD_VERSION environment variables added to the lambda handlers.

It does seem that passing a dummy extension_layer_version=65 does add them again.

Actual Behavior

DD_SERVICE, DD_ENV, and DD_VERSION the variables seem not to get added if you don't pass extension_layer_version, and these are typically how one may find the relevant traces.

Noted here in the code that the constructs do not add these variables if the extension layer is unspecified: https://github.com/DataDog/datadog-cdk-constructs/blob/main/src/env.ts#L127-L140

It seems this may be intended behavior, but I am not sure why.

#185 seems related.

Steps to Reproduce the Problem

  1. Create a DockerImage lambda function which includes the datadog extension already.
  2. Create Datadog construct with no extension_layer_version.
  3. Deploy and note whether or not DD_SERVICE, DD_ENV, and DD_VERSION are set.

NOTE: Traces are showing up fine. It's just that the 3 common fields I'd search for in APM Traces are not tagged (ie searching by service, env, or version) so it appears as if it doesn't work.

Specifications

  • Datadog Lambda Layer version: 65 (installing via COPY --from=public.ecr.aws/datadog/lambda-extension:65 /opt/. /opt/ based on public.ecr.aws/lambda/python:3.10
    )
  • Node version: v20.12.0 (CDK)

datadog-cdk-constructs-v2==1.18.0

Stacktrace

There is no crash; this behavior may be WAI.

Would anyone be able to share?

BTW - thank you Datadog team for a great product. It is so useful :)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions