DataDog / datadog-cdk-constructs

CDK construct library to automagically instrument your Lambda functions with Datadog
Apache License 2.0
65 stars 28 forks source link

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

Open pviolette3 opened 4 days ago

pviolette3 commented 4 days ago

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.

https://github.com/DataDog/datadog-cdk-constructs/issues/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

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 :)

lym953 commented 7 hours ago

Thanks for reporting! I think DD_SERVICE, DD_ENV, and DD_VERSION should be set in this case. I'm going to track this issue internally. For now, you can set a dummy extension_layer_version to have the environment variables set.

lym953 commented 7 hours ago

Internal ticket: https://datadoghq.atlassian.net/browse/SVLS-5931