Skip to content

Patch 1#1045

Closed
eric-teambridge wants to merge 3 commits intoDataDog:masterfrom
eric-teambridge:patch-1
Closed

Patch 1#1045
eric-teambridge wants to merge 3 commits intoDataDog:masterfrom
eric-teambridge:patch-1

Conversation

@eric-teambridge
Copy link
Copy Markdown
Contributor

@eric-teambridge eric-teambridge commented Jan 14, 2026

What does this PR do?

This change swaps the check to use the same split/startswith functionality that's used inside the conditional.

Motivation

extract_ddtags_from_message checks for a service tag override using if "service:" in which returns true if there's a tag key that ends with service, eg mail_send_service:production.

This causes the lambda to enter the conditional to extract the tag to a first class datadog tag, but the enclosed logic includes a non-defaulted generator which checks for startswith("service:"). Since this second check does not match the example, the generator has no elements, and the call to next causes the lambda to crash.

Testing Guidelines

Added a unit test that fails on main in the same way we experienced in prod. The test passes with this change.

Additional Notes

Logs from the lambda when this crash occurred in our prod environment:

[ERROR] StopIteration
Traceback (most recent call last):
File "/opt/python/datadog_lambda/wrapper.py", line 239, in call
"""Executes when the wrapped function gets called"""
File "/opt/python/ddtrace/contrib/internal/aws_lambda/patch.py", line 119, in call
self.response = self.func(*args, **kwargs)
File "/opt/python/datadog_lambda/wrapper.py", line 242, in call
self.response = self.func(event, context, **kwargs)
File "/opt/python/lambda_function.py", line 85, in datadog_forwarder
enriched = enrich(parsed, cache_layer)
File "/opt/python/steps/enrichment.py", line 30, in enrich
extract_ddtags_from_message(event)
File "/opt/python/steps/enrichment.py", line 171, in extract_ddtags_from_message
event[DD_SERVICE] = next(

NB: The log was cut off like that in cloudwatch.

Types of changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)
  • This PR passes the unit tests
  • This PR passes the installation tests (ask a Datadog member to run the tests)

extract_ddtags_from_message checks for a service tag override using `if "service:" in` which returns true if there's a tag key that ends with `service`, eg `mail_send_service:production`.

This causes the lambda to enter the conditional to extract the tag to a first class datadog tag, but the enclosed logic includes a non-defaulted generator which checks for `startswith("service:")`. Since this second check does _not_ match the example, the generator has no elements, and the call to `next` causes the lambda to crash. 

This change swaps the check to use the same split/startswith functionality that's used inside the conditional.
@eric-teambridge eric-teambridge requested a review from a team as a code owner January 14, 2026 23:02
@ViBiOh ViBiOh self-assigned this Jan 15, 2026
@ViBiOh
Copy link
Copy Markdown
Contributor

ViBiOh commented Jan 15, 2026

Hi @eric-teambridge

Thank you for spotting that and fixing it. There is a small code format issue on your pull-request (see failed Linter job). Once you'll fix it, I can merge and ask for a patch release.

@eric-teambridge
Copy link
Copy Markdown
Contributor Author

@ViBiOh Patched it, ran the linter locally, should be good now.

@ge0Aja
Copy link
Copy Markdown
Contributor

ge0Aja commented Jan 19, 2026

I created a rebased PR #1050 to solve the linter issues

@ge0Aja ge0Aja closed this Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants