-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(botocore): inject trace context into stepfunction start_execution…
… input (#10262) In #7514 , I added a feature to patch start_execution calls to AWS stepfunctions and inject trace context into the input object. That feature suffered a regression in #8937 , and the whole stepfunctions integration was refactored to use the Core API in #9005 . This PR re-adds the injection of trace context into the start_execution input, and adds a few unit tests to detect the same regression in the future. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
- Loading branch information
Showing
7 changed files
with
123 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
BOTOCORE_STEPFUNCTIONS_INPUT_KEY = "botocore_stepfunctions_input" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
releasenotes/notes/fix-botocore-stepfunction-patching-9993630697956278.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fixes: | ||
- | | ||
botocore: This fix resolves a regression where trace context was not being injected into the input of Stepfunction | ||
start_execution commands. This re-enables distributed tracing when a Python service invokes a properly instrumented Step Function. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import json | ||
|
||
from ddtrace import Pin | ||
from ddtrace.contrib.internal.botocore.services.stepfunctions import update_stepfunction_input | ||
from ddtrace.ext import SpanTypes | ||
from ddtrace.internal import core | ||
|
||
|
||
def test_update_stepfunction_input(): | ||
params = { | ||
"stateMachineArn": "arn:aws:states:us-east-1:425362996713:stateMachine:agocs_inner_state_machine", | ||
"input": "{}", | ||
} | ||
pin = Pin() | ||
with core.context_with_data( | ||
"botocore.patched_stepfunctions_api_call", | ||
span_name="states.command", | ||
service="aws.states", | ||
span_type=SpanTypes.HTTP, | ||
call_key="patched_stepfunctions_api_call", | ||
instance=None, | ||
args=( | ||
"StartExecution", | ||
{ | ||
"stateMachineArn": "arn:aws:states:us-east-1:425362996713:stateMachine:agocs_inner_state_machine", | ||
"input": "{}", | ||
}, | ||
), | ||
params=params, | ||
endpoint_name="states", | ||
operation="StartExecution", | ||
pin=pin, | ||
) as ctx: | ||
update_stepfunction_input(ctx, params) | ||
assert params["input"] | ||
input_obj = json.loads(params["input"]) | ||
assert "_datadog" in input_obj | ||
assert "x-datadog-trace-id" in input_obj["_datadog"] | ||
assert "x-datadog-parent-id" in input_obj["_datadog"] | ||
assert "x-datadog-tags" in input_obj["_datadog"] | ||
assert "_dd.p.tid" in input_obj["_datadog"]["x-datadog-tags"] | ||
|
||
|
||
def test_update_stepfunction_input_does_not_mutate_non_dict_input(): | ||
params = { | ||
"stateMachineArn": "arn:aws:states:us-east-1:425362996713:stateMachine:agocs_inner_state_machine", | ||
"input": "hello", | ||
} | ||
pin = Pin() | ||
with core.context_with_data( | ||
"botocore.patched_stepfunctions_api_call", | ||
span_name="states.command", | ||
service="aws.states", | ||
span_type=SpanTypes.HTTP, | ||
call_key="patched_stepfunctions_api_call", | ||
instance=None, | ||
args=( | ||
"StartExecution", | ||
{ | ||
"stateMachineArn": "arn:aws:states:us-east-1:425362996713:stateMachine:agocs_inner_state_machine", | ||
"input": "hello", | ||
}, | ||
), | ||
params=params, | ||
endpoint_name="states", | ||
operation="StartExecution", | ||
pin=pin, | ||
) as ctx: | ||
update_stepfunction_input(ctx, params) | ||
assert params["input"] | ||
assert params["input"] == "hello" | ||
|
||
params = { | ||
"stateMachineArn": "arn:aws:states:us-east-1:425362996713:stateMachine:agocs_inner_state_machine", | ||
"input": "[1, 2, 3]", | ||
} | ||
pin = Pin() | ||
with core.context_with_data( | ||
"botocore.patched_stepfunctions_api_call", | ||
span_name="states.command", | ||
service="aws.states", | ||
span_type=SpanTypes.HTTP, | ||
call_key="patched_stepfunctions_api_call", | ||
instance=None, | ||
args=( | ||
"StartExecution", | ||
{ | ||
"stateMachineArn": "arn:aws:states:us-east-1:425362996713:stateMachine:agocs_inner_state_machine", | ||
"input": "[1, 2, 3]", | ||
}, | ||
), | ||
params=params, | ||
endpoint_name="states", | ||
operation="StartExecution", | ||
pin=pin, | ||
) as ctx: | ||
update_stepfunction_input(ctx, params) | ||
assert params["input"] | ||
assert params["input"] == "[1, 2, 3]" |