You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[serverless] Create EventBridge Instrumentation and Inject Trace Context (#6096)
## Summary of changes
This creates a new instrumentation for EventBridge and intercepts
`PutEvents` and `PutEventsAsync` to inject trace context. This allows
the agent to combine spans from a distributed (serverless) architecture
into a single trace.
This PR only injects trace context. I'm working on [PR
1](DataDog/datadog-agent#29414) and [PR
2](DataDog/datadog-agent#29551) to update the
Lambda extension to use this trace context to create EventBridge spans.
I am also working on a similar PR in
[dd-trace-java](DataDog/dd-trace-java#7613) and
dd-trace-go.
## Reason for change
SNS and SQS are already supported, and the tracer currently injects
trace context into message attributes fields for them. However,
EventBridge wasn't supported, and this PR aims to fix this problem.
## Implementation details
I followed the
[documentation](https://github.com/DataDog/dd-trace-dotnet/blob/master/docs/development/AutomaticInstrumentation.md)
to create an instrumentation. Much of the logic was mirrored from the
[existing
implementation](https://github.com/DataDog/dd-trace-dotnet/tree/master/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/SNS)
of SNS, since EventBridge and SNS are extremely similar.
Overall, AWS's EventBridge API is lacking some features, so we have to
do some hacky solutions.
- SNS and SQS call their custom input field messageAttributes, and
EventBridge calls it detail
- Unlike SNS and SQS, the detail field is given as a raw string.
Therefore, we have to manually modify the detail string using
StringBuilder.
- The agent has no reliable way of getting the start time of the
EventBridge span, so the tracer has to put the current time into
`detail[_datadog]` under the header `x-datadog-start-time`
- The EventBridge API has no way of getting the EventBridge bus name, so
the tracer has to put the bus name (which is used to create the span
resource name) into `detail[_datadog]` under the header
`x-datadog-resource-name`
## Test coverage
I added system tests for SNS/SQS:
DataDog/system-tests#3204
I added [unit
tests](d05eb4c)
and [integration
tests](5ccd8b7).
Unit tests can be ran with:
```
cd tracer
dotnet test ./test/Datadog.Trace.ClrProfiler.Managed.Tests
```
Integration tests can be ran with these commands:
```
cd tracer
# Start docker localstock
docker run --rm -it -p 4566:4566 -p 4571:4571 -e SERVICES=events localstack/localstack
# Run integation tests
./build.sh BuildAndRunOSxIntegrationTests -buildConfiguration Debug -framework net6.0 -Filter AwsEventBridgeTests -SampleName Samples.AWS.EventBridge
```
I also did manual testing:
<img width="505" alt="Screenshot 2024-09-30 at 11 00 47 AM"
src="https://github.com/user-attachments/assets/bdf5d516-8b46-4138-ac25-c45d1822dc56">
## Other details
There are lots of diffs and files changed. I recommend reviewers to
review the PR commit by commit. All the autogenerated files were added
in a single commit, which should make the review process less
overwhelming.
<!-- ⚠️ Note: where possible, please obtain 2 approvals prior to
merging. Unless CODEOWNERS specifies otherwise, for external teams it is
typically best to have one review from a team member, and one review
from apm-dotnet. Trivial changes do not require 2 reviews. -->
---------
Co-authored-by: Steven Bouwkamp <[email protected]>
0 commit comments