Skip to content

Commit 5817141

Browse files
committed
feat(aws): AWSX-1566 Adding storage tag HTTP header
Signed-off-by: Vincent Boutour <vincent.boutour@datadoghq.com>
1 parent d936bdd commit 5817141

3 files changed

Lines changed: 49 additions & 7 deletions

File tree

aws/logs_monitoring/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ For all configuration options and details, including [Multi-Region deployment][2
468468
[203]: https://docs.datadoghq.com/getting_started/site/#access-the-datadog-site
469469
[204]: https://app.datadoghq.com/organization-settings/api-keys
470470
[205]: https://registry.terraform.io/modules/DataDog/log-lambda-forwarder-datadog/aws/latest#multi-region-deployments
471+
471472
{{% /tab %}}
472473
{{% tab "Manual" %}}
473474
@@ -567,11 +568,17 @@ To test different patterns against your logs, turn on [debug logs](#troubleshoot
567568
568569
### Advanced (optional)
569570
571+
`DD_ENRICH_S3_TAGS`
572+
: Instruct Datadog Backend to enrich a log coming from a S3 bucket with the tag attached to this bucket. It's the equivalent behavior of `DD_FETCH_S3_TAG` but done after ingestion. This require Resource Collection to be enabled. Enabled by default.
573+
574+
`DD_ENRICH_CLOUDWATCH_TAGS`
575+
: Instruct Datadog Backend to enrich a log coming from a Cloudwatch logGroup with the tag attached to this logGroup. It's the equivalent behavior of `DD_FETCH_LOG_GROUP_TAGS` but done after ingestion. This require Resource Collection to be enabled.
576+
570577
`DD_FETCH_LAMBDA_TAGS`
571578
: Let the Forwarder fetch Lambda tags using GetResources API calls and apply them to logs, metrics, and traces. If set to true, permission `tag:GetResources` will be automatically added to the Lambda execution IAM role.
572579
573580
`DD_FETCH_LOG_GROUP_TAGS`
574-
: Let the forwarder fetch Log Group tags using ListTagsLogGroup and apply them to logs, metrics, and traces. If set to true, permission `logs:ListTagsForResource` will be automatically added to the Lambda execution IAM role.
581+
: [DEPRECATED, use DD_ENRICH_CLOUDWATCH_TAG] Let the forwarder fetch Log Group tags using ListTagsLogGroup and apply them to logs, metrics, and traces. If set to true, permission `logs:ListTagsForResource` will be automatically added to the Lambda execution IAM role.
575582
576583
`DD_FETCH_STEP_FUNCTIONS_TAGS`
577584
: Let the Forwarder fetch Step Functions tags using GetResources API calls and apply them to logs and traces (if Step Functions tracing is enabled). If set to true, permission `tag:GetResources` will be automatically added to the Lambda execution IAM role.

aws/logs_monitoring/logs/datadog_http_client.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44
# Copyright 2021 Datadog, Inc.
55

66

7-
import os
87
import logging
9-
8+
import os
109
from concurrent.futures import as_completed
10+
1111
from requests_futures.sessions import FuturesSession
12-
from logs.helpers import compress_logs
13-
from logs.exceptions import ScrubbingException
1412

13+
from logs.exceptions import ScrubbingException
14+
from logs.helpers import compress_logs
1515
from settings import (
16-
DD_USE_COMPRESSION,
1716
DD_COMPRESSION_LEVEL,
18-
DD_MAX_WORKERS,
1917
DD_FORWARDER_VERSION,
18+
DD_MAX_WORKERS,
19+
DD_USE_COMPRESSION,
20+
get_enrich_cloudwatch_tags,
21+
get_enrich_s3_tags,
2022
)
2123

2224
logger = logging.getLogger()
@@ -37,6 +39,10 @@ class DatadogHTTPClient(object):
3739
_HEADERS["DD-EVP-ORIGIN"] = "aws_forwarder"
3840
_HEADERS["DD-EVP-ORIGIN-VERSION"] = DD_FORWARDER_VERSION
3941

42+
storage_tag = get_dd_storage_tag_header()
43+
if storage_tag != "":
44+
_HEADERS["DD-STORAGE-TAG"] = storage_tag
45+
4046
def __init__(
4147
self, host, port, no_ssl, skip_ssl_validation, api_key, scrubber, timeout=10
4248
):
@@ -92,3 +98,17 @@ def __enter__(self):
9298

9399
def __exit__(self, ex_type, ex_value, traceback):
94100
self._close()
101+
102+
103+
def get_dd_storage_tag_header():
104+
storage_tag = ""
105+
106+
if get_enrich_s3_tags():
107+
storage_tag += "s3"
108+
109+
if get_enrich_cloudwatch_tags():
110+
if storage_tag != "":
111+
storage_tag += ","
112+
storage_tag += "cloudwatch"
113+
114+
return storage_tag

aws/logs_monitoring/settings.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ def __init__(self, name, pattern, placeholder, enabled=True):
250250
)
251251

252252

253+
DD_ENRICH_S3_TAGS = get_env_var("DD_ENRICH_S3_TAGS", default="true", boolean=True)
254+
255+
DD_ENRICH_CLOUDWATCH_TAGS = get_env_var(
256+
"DD_ENRICH_CLOUDWATCH_TAGS", default="false", boolean=True
257+
)
258+
259+
253260
def get_fetch_s3_tags():
254261
return DD_FETCH_S3_TAGS
255262

@@ -266,6 +273,14 @@ def get_fetch_step_functions_tags():
266273
return DD_FETCH_STEP_FUNCTIONS_TAGS
267274

268275

276+
def get_enrich_s3_tags():
277+
return DD_ENRICH_S3_TAGS
278+
279+
280+
def get_enrich_cloudwatch_tags():
281+
return DD_ENRICH_CLOUDWATCH_TAGS
282+
283+
269284
DD_SOURCE = "ddsource"
270285
DD_CUSTOM_TAGS = "ddtags"
271286
DD_SERVICE = "service"

0 commit comments

Comments
 (0)