From af7764f3f046fa8e4669a58cdc6b5fe8018a8c6d Mon Sep 17 00:00:00 2001 From: Munir Abdinur Date: Sat, 29 Oct 2022 22:09:04 -0400 Subject: [PATCH] feat(ddtrace): disable telemetry collection by default --- datadog_lambda/tracing.py | 14 ++++++++++++++ datadog_lambda/wrapper.py | 2 ++ 2 files changed, 16 insertions(+) diff --git a/datadog_lambda/tracing.py b/datadog_lambda/tracing.py index 4db7db981..2273b38fb 100644 --- a/datadog_lambda/tracing.py +++ b/datadog_lambda/tracing.py @@ -968,6 +968,20 @@ def mark_trace_as_error_for_5xx_responses(context, status_code, span): span.error = 1 +def disable_instrumentation_telemetry_by_default(): + """ + As of ddtrace v1.5 instrumentation telemetry collection is enabled by default. + This feature can add 5-10% overhead to the tracer and increase cold start. + Setting ``DD_INSTRUMENTATION_TELEMETRY_ENABLED=False`` will disable this feature. + + Instrumentation Telemetry Collection is enabled when the first trace is sent to the + Agent. This feature must be disabled before tracing is configured. + """ + + if "DD_INSTRUMENTATION_TELEMETRY_ENABLED" not in os.environ: + os.environ["DD_INSTRUMENTATION_TELEMETRY_ENABLED"] = "false" + + class InferredSpanInfo(object): BASE_NAME = "_inferred_span" SYNCHRONICITY = f"{BASE_NAME}.synchronicity" diff --git a/datadog_lambda/wrapper.py b/datadog_lambda/wrapper.py index 88508ab33..1b72e5934 100644 --- a/datadog_lambda/wrapper.py +++ b/datadog_lambda/wrapper.py @@ -23,6 +23,7 @@ from datadog_lambda.patch import patch_all from datadog_lambda.tracing import ( extract_dd_trace_context, + disable_instrumentation_telemetry_by_default, create_dd_dummy_metadata_subsegment, inject_correlation_ids, dd_tracing_enabled, @@ -136,6 +137,7 @@ def __init__(self, func): os.environ["DD_REQUESTS_SERVICE_NAME"] = os.environ.get( "DD_SERVICE", "aws.lambda" ) + disable_instrumentation_telemetry_by_default() # Patch third-party libraries for tracing patch_all()