[serverless] Add EventBridge Inferred Spans
What does this PR do?
- This PR fixes/adds EventBridge inferred spans for Lambda.
- Now, users will see an EventBride span on any Lambda function that was directly invoked by EventBridge.
- In the example architecture
Lambda -> EventBridge -> Lambda, the traces look like this:
Two different traces. Second trace is missing an EventBridge span
- Now, the trace looks like this:
Motivation
SNS and SQS are already supported. There was some code in place for EventBridge, but it didn't work properly and didn't show spans on Datadog. This PR aims to fix this.
Additional Notes
-
I have a PR here to inject trace context into the Java tracer. At the time of writing this, the tracers for .NET and Go do not inject trace context into SQS/SNS/EventBridge yet, but that's my next project.
-
The AWS API has no reliable way of getting the start time of the EventBridge span. It only gives time with precision to the second, which is not precise enough to create spans. Therefore, we try to get the start time from the tracer in the field
x-datadog-sent-timestamp. If this field does not exist, we fall back to AWS API's start time. -
Also, the AWS API has no way of getting the EventBridge bus name, so we attempt to get this from the tracer in the field
x-datadog-bus-namefor the span resource name. If this doesn't exist, we set the resource name to "EventBridge". -
This should not be a breaking change, but this is an area for reviewers to focus on and double check. If the user is using an outdated tracer or .NET/Go that doesn't yet support inferred spans for EB/SQS/SNS, these changes shouldn't break anything, but it still shows an "EventBridge" span on any Lambda function invoked by the EventBridge event:
Possible Drawbacks / Trade-offs
Increased overhead
Describe how to test/QA your changes
Run local tests with invoke test --targets=./pkg/serverless from the root of the project
It's more complicated to test manually. Contact me if you want a live demo of these changes. Here's how I tested:
- Create a serverless architecture that's supported, such as a Java Lambda function that publishes an event to EventBridge, an EventBridge event bus that has a target SQS queue or SNS notifier, and another Java Lambda function that subscribes to the queue/notifier.
- Instrument the lambda functions using
datadog-ci - Build the extension:
./scripts/publish_sandbox.sh - Build the new Java tracer from this PR:
./gradlew publishToMavenLocal && cd ~/.m2/repository/com/datadoghq/dd-java-agent/1.40.0-SNAPSHOT && zip layer.zip dd-java-agent-1.40.0-SNAPSHOT.jar - Create new layers on AWS by uploading those zip files, and replace your Lambda layers with your custom layers.
- Set the environment variable
JAVA_TOOL_OPTIONS: -javaagent:"/opt/dd-java-agent-1.40.0-SNAPSHOT.jar"on your lambda functions to use the new Java tracer - Invoke your first lambda function, and check Datadog for results. The spans should be combined into a single trace.
Test changes on VM
Use this command from test-infra-definitions to manually test this PR changes on a VM:
inv create-vm --pipeline-id=44948452 --os-family=ubuntu
Note: This applies to commit 1484a329
Regression Detector
Regression Detector Results
Run ID: 513bc628-5fbb-4a00-b618-b8d27490b12b Metrics dashboard Target profiles
Baseline: bb344575821d101433bfb3f146cb716da994f2b8 Comparison: 1484a329ed9480f8e98c1f0d48e6ec02bff2f57f
Performance changes are noted in the perf column of each table:
- ✅ = significantly better comparison variant performance
- ❌ = significantly worse comparison variant performance
- ➖ = no significant change in performance
No significant changes in experiment optimization goals
Confidence level: 90.00% Effect size tolerance: |Δ mean %| ≥ 5.00%
There were no significant changes in experiment optimization goals at this confidence level and effect size tolerance.
Fine details of change detection per experiment
| perf | experiment | goal | Δ mean % | Δ mean % CI | trials | links |
|---|---|---|---|---|---|---|
| ➖ | pycheck_lots_of_tags | % cpu utilization | +1.48 | [-1.04, +4.00] | 1 | Logs |
| ➖ | otel_to_otel_logs | ingress throughput | +1.22 | [+0.40, +2.03] | 1 | Logs |
| ➖ | file_tree | memory utilization | +1.19 | [+1.09, +1.28] | 1 | Logs |
| ➖ | basic_py_check | % cpu utilization | +0.06 | [-2.58, +2.70] | 1 | Logs |
| ➖ | tcp_dd_logs_filter_exclude | ingress throughput | +0.00 | [-0.01, +0.01] | 1 | Logs |
| ➖ | idle | memory utilization | -0.00 | [-0.05, +0.05] | 1 | Logs |
| ➖ | uds_dogstatsd_to_api | ingress throughput | -0.00 | [-0.09, +0.09] | 1 | Logs |
| ➖ | tcp_syslog_to_blackhole | ingress throughput | -0.68 | [-0.72, -0.63] | 1 | Logs |
| ➖ | uds_dogstatsd_to_api_cpu | % cpu utilization | -0.84 | [-1.59, -0.09] | 1 | Logs |
Bounds Checks
| perf | experiment | bounds_check_name | replicates_passed |
|---|---|---|---|
| ✅ | idle | memory_usage | 10/10 |
Explanation
A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".
For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:
-
Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.
-
Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.
-
Its configuration does not mark it "erratic".
/merge
:steam_locomotive: MergeQueue: waiting for PR to be ready
This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.
Use /merge -c to cancel this operation!
Serverless Benchmark Results
BenchmarkStartEndInvocation comparison between bb344575821d101433bfb3f146cb716da994f2b8 and 5e9a8137141f2ef58d5665a82598cfa691efc218.
tl;dr
Use these benchmarks as an insight tool during development.
-
Skim down the
vs basecolumn in each chart. If there is a~, then there was no statistically significant change to the benchmark. Otherwise, ensure the estimated percent change is either negative or very small. -
The last row of each chart is the
geomean. Ensure this percentage is either negative or very small.
What is this benchmarking?
The BenchmarkStartEndInvocation compares the amount of time it takes to call the start-invocation and end-invocation endpoints. For universal instrumentation languages (Dotnet, Golang, Java, Ruby), this represents the majority of the duration overhead added by our tracing layer.
The benchmark is run using a large variety of lambda request payloads. In the charts below, there is one row for each event payload type.
How do I interpret these charts?
The charts below comes from benchstat. They represent the statistical change in duration (sec/op), memory overhead (B/op), and allocations (allocs/op).
The benchstat docs explain how to interpret these charts.
Before the comparison table, we see common file-level configuration. If there are benchmarks with different configuration (for example, from different packages), benchstat will print separate tables for each configuration.
The table then compares the two input files for each benchmark. It shows the median and 95% confidence interval summaries for each benchmark before and after the change, and an A/B comparison under "vs base". ... The p-value measures how likely it is that any differences were due to random chance (i.e., noise). The "~" means benchstat did not detect a statistically significant difference between the two inputs. ...
Note that "statistically significant" is not the same as "large": with enough low-noise data, even very small changes can be distinguished from noise and considered statistically significant. It is, of course, generally easier to distinguish large changes from noise.
Finally, the last row of the table shows the geometric mean of each column, giving an overall picture of how the benchmarks changed. Proportional changes in the geomean reflect proportional changes in the benchmarks. For example, given n benchmarks, if sec/op for one of them increases by a factor of 2, then the sec/op geomean will increase by a factor of ⁿ√2.
I need more help
First off, do not worry if the benchmarks are failing. They are not tests. The intention is for them to be a tool for you to use during development.
If you would like a hand interpreting the results come chat with us in #serverless-agent in the internal DataDog slack or in #serverless in the public DataDog slack. We're happy to help!
Benchmark stats
goos: linux
goarch: amd64
pkg: github.com/DataDog/datadog-agent/pkg/serverless/daemon
cpu: AMD EPYC 7763 64-Core Processor
│ baseline/benchmark.log │ current/benchmark.log │
│ sec/op │ sec/op vs base │
api-gateway-appsec.json 87.62µ ± 3% 90.50µ ± 12% +3.29% (p=0.015 n=10)
api-gateway-kong-appsec.json 68.94µ ± 1% 70.30µ ± 1% +1.98% (p=0.004 n=10)
api-gateway-kong.json 68.27µ ± 2% 69.43µ ± 3% +1.70% (p=0.002 n=10)
api-gateway-non-proxy-async.json 108.9µ ± 1% 110.7µ ± 2% +1.64% (p=0.035 n=10)
api-gateway-non-proxy.json 108.3µ ± 1% 111.0µ ± 1% +2.51% (p=0.002 n=10)
api-gateway-websocket-connect.json 71.48µ ± 2% 73.58µ ± 1% +2.93% (p=0.000 n=10)
api-gateway-websocket-default.json 62.73µ ± 1% 66.33µ ± 2% +5.75% (p=0.000 n=10)
api-gateway-websocket-disconnect.json 63.16µ ± 1% 66.40µ ± 1% +5.14% (p=0.000 n=10)
api-gateway.json 115.5µ ± 1% 121.5µ ± 2% +5.17% (p=0.000 n=10)
application-load-balancer.json 64.88µ ± 2% 67.52µ ± 1% +4.08% (p=0.000 n=10)
cloudfront.json 47.64µ ± 1% 51.10µ ± 1% +7.28% (p=0.000 n=10)
cloudwatch-events.json 39.86µ ± 2% 40.87µ ± 2% +2.54% (p=0.005 n=10)
cloudwatch-logs.json 67.43µ ± 1% 70.01µ ± 2% +3.82% (p=0.002 n=10)
custom.json 32.66µ ± 2% 33.17µ ± 2% ~ (p=0.052 n=10)
dynamodb.json 95.16µ ± 1% 99.26µ ± 3% +4.31% (p=0.000 n=10)
empty.json 30.81µ ± 2% 31.27µ ± 2% +1.47% (p=0.009 n=10)
eventbridge-custom.json 43.34µ ± 2% 51.19µ ± 2% +18.09% (p=0.000 n=10)
http-api.json 75.27µ ± 1% 76.25µ ± 1% +1.31% (p=0.043 n=10)
kinesis-batch.json 73.44µ ± 2% 74.15µ ± 1% ~ (p=0.123 n=10)
kinesis.json 55.99µ ± 1% 57.49µ ± 3% +2.68% (p=0.002 n=10)
s3.json 61.53µ ± 2% 62.52µ ± 2% ~ (p=0.075 n=10)
sns-batch.json 92.28µ ± 1% 94.34µ ± 2% +2.23% (p=0.000 n=10)
sns.json 66.36µ ± 2% 68.02µ ± 2% +2.49% (p=0.004 n=10)
snssqs.json 112.7µ ± 1% 115.8µ ± 1% +2.77% (p=0.000 n=10)
snssqs_no_dd_context.json 101.4µ ± 1% 103.5µ ± 2% +2.01% (p=0.002 n=10)
sqs-aws-header.json 56.89µ ± 1% 58.38µ ± 1% +2.63% (p=0.000 n=10)
sqs-batch.json 97.70µ ± 2% 99.66µ ± 2% +2.00% (p=0.007 n=10)
sqs.json 70.81µ ± 4% 73.36µ ± 3% +3.60% (p=0.003 n=10)
sqs_no_dd_context.json 63.34µ ± 2% 66.41µ ± 1% +4.84% (p=0.000 n=10)
stepfunction.json 48.48µ ± 2% 50.90µ ± 1% +5.00% (p=0.000 n=10)
eventbridge-no-bus.json 50.03µ ± 3%
eventbridge-no-timestamp.json 48.41µ ± 4%
geomean 67.85µ 68.70µ +3.54%
│ baseline/benchmark.log │ current/benchmark.log │
│ B/op │ B/op vs base │
api-gateway-appsec.json 37.34Ki ± 0% 37.28Ki ± 0% -0.16% (p=0.000 n=10)
api-gateway-kong-appsec.json 26.94Ki ± 0% 26.94Ki ± 0% ~ (p=0.839 n=10)
api-gateway-kong.json 24.43Ki ± 0% 24.44Ki ± 0% ~ (p=0.725 n=10)
api-gateway-non-proxy-async.json 48.14Ki ± 0% 48.10Ki ± 0% -0.09% (p=0.000 n=10)
api-gateway-non-proxy.json 47.37Ki ± 0% 47.31Ki ± 0% -0.14% (p=0.000 n=10)
api-gateway-websocket-connect.json 25.54Ki ± 0% 25.52Ki ± 0% -0.09% (p=0.000 n=10)
api-gateway-websocket-default.json 21.44Ki ± 0% 21.42Ki ± 0% -0.09% (p=0.000 n=10)
api-gateway-websocket-disconnect.json 21.23Ki ± 0% 21.20Ki ± 0% -0.11% (p=0.000 n=10)
api-gateway.json 49.60Ki ± 0% 49.61Ki ± 0% ~ (p=0.305 n=10)
application-load-balancer.json 23.32Ki ± 0% 22.39Ki ± 0% -3.97% (p=0.000 n=10)
cloudfront.json 17.68Ki ± 0% 17.68Ki ± 0% ~ (p=0.469 n=10)
cloudwatch-events.json 11.74Ki ± 0% 11.72Ki ± 0% -0.20% (p=0.003 n=10)
cloudwatch-logs.json 53.40Ki ± 0% 53.39Ki ± 0% ~ (p=0.516 n=10)
custom.json 9.781Ki ± 0% 9.763Ki ± 0% -0.19% (p=0.002 n=10)
dynamodb.json 40.83Ki ± 0% 40.81Ki ± 0% -0.06% (p=0.017 n=10)
empty.json 9.340Ki ± 0% 9.345Ki ± 0% ~ (p=0.670 n=10)
eventbridge-custom.json 13.48Ki ± 0% 15.07Ki ± 0% +11.74% (p=0.000 n=10)
http-api.json 23.85Ki ± 0% 23.85Ki ± 0% ~ (p=0.926 n=10)
kinesis-batch.json 27.07Ki ± 0% 27.10Ki ± 0% ~ (p=0.280 n=10)
kinesis.json 17.87Ki ± 0% 17.92Ki ± 0% +0.28% (p=0.001 n=10)
s3.json 20.46Ki ± 0% 20.43Ki ± 0% ~ (p=0.190 n=10)
sns-batch.json 38.72Ki ± 0% 38.80Ki ± 0% +0.21% (p=0.000 n=10)
sns.json 24.06Ki ± 0% 24.10Ki ± 0% +0.13% (p=0.045 n=10)
snssqs.json 50.69Ki ± 0% 50.74Ki ± 0% ~ (p=0.190 n=10)
snssqs_no_dd_context.json 44.90Ki ± 0% 44.93Ki ± 0% ~ (p=0.631 n=10)
sqs-aws-header.json 18.91Ki ± 1% 18.90Ki ± 0% ~ (p=0.739 n=10)
sqs-batch.json 41.71Ki ± 0% 41.82Ki ± 0% +0.26% (p=0.000 n=10)
sqs.json 25.66Ki ± 1% 25.80Ki ± 1% ~ (p=0.075 n=10)
sqs_no_dd_context.json 20.68Ki ± 1% 20.78Ki ± 1% ~ (p=0.078 n=10)
stepfunction.json 14.24Ki ± 1% 14.37Ki ± 0% ~ (p=0.093 n=10)
eventbridge-no-bus.json 14.01Ki ± 0%
eventbridge-no-timestamp.json 14.05Ki ± 0%
geomean 25.31Ki 24.46Ki +0.30%
│ baseline/benchmark.log │ current/benchmark.log │
│ allocs/op │ allocs/op vs base │
api-gateway-appsec.json 630.0 ± 0% 629.5 ± 0% ~ (p=1.000 n=10)
api-gateway-kong-appsec.json 488.0 ± 0% 488.0 ± 0% ~ (p=1.000 n=10) ¹
api-gateway-kong.json 466.0 ± 0% 466.0 ± 0% ~ (p=1.000 n=10)
api-gateway-non-proxy-async.json 726.0 ± 0% 726.0 ± 0% ~ (p=1.000 n=10)
api-gateway-non-proxy.json 716.5 ± 0% 716.0 ± 0% ~ (p=0.350 n=10)
api-gateway-websocket-connect.json 453.0 ± 0% 453.5 ± 0% ~ (p=0.650 n=10)
api-gateway-websocket-default.json 379.0 ± 0% 379.5 ± 0% ~ (p=1.000 n=10)
api-gateway-websocket-disconnect.json 370.0 ± 0% 370.0 ± 0% ~ (p=1.000 n=10)
api-gateway.json 791.0 ± 0% 791.0 ± 0% ~ (p=0.211 n=10)
application-load-balancer.json 353.0 ± 0% 352.0 ± 0% -0.28% (p=0.000 n=10)
cloudfront.json 284.0 ± 0% 284.0 ± 0% ~ (p=1.000 n=10) ¹
cloudwatch-events.json 220.0 ± 0% 221.0 ± 0% ~ (p=0.370 n=10)
cloudwatch-logs.json 216.0 ± 0% 216.0 ± 0% ~ (p=1.000 n=10)
custom.json 169.0 ± 0% 169.0 ± 1% ~ (p=0.211 n=10)
dynamodb.json 589.0 ± 0% 589.5 ± 0% ~ (p=0.650 n=10)
empty.json 160.0 ± 0% 160.0 ± 1% ~ (p=0.087 n=10)
eventbridge-custom.json 254.0 ± 0% 267.0 ± 0% +5.12% (p=0.000 n=10)
http-api.json 433.0 ± 0% 434.0 ± 0% +0.23% (p=0.002 n=10)
kinesis-batch.json 391.0 ± 0% 392.0 ± 0% ~ (p=0.066 n=10)
kinesis.json 285.0 ± 0% 287.0 ± 0% +0.70% (p=0.000 n=10)
s3.json 359.0 ± 0% 359.0 ± 0% ~ (p=0.973 n=10)
sns-batch.json 455.0 ± 0% 456.0 ± 0% +0.22% (p=0.000 n=10)
sns.json 324.0 ± 0% 324.0 ± 1% ~ (p=0.135 n=10)
snssqs.json 439.0 ± 0% 440.5 ± 0% +0.34% (p=0.012 n=10)
snssqs_no_dd_context.json 400.0 ± 0% 401.0 ± 0% ~ (p=0.133 n=10)
sqs-aws-header.json 275.0 ± 0% 274.5 ± 1% ~ (p=0.705 n=10)
sqs-batch.json 504.0 ± 0% 506.0 ± 0% +0.40% (p=0.000 n=10)
sqs.json 352.0 ± 1% 354.0 ± 1% ~ (p=0.140 n=10)
sqs_no_dd_context.json 324.0 ± 1% 326.0 ± 1% +0.62% (p=0.025 n=10)
stepfunction.json 237.0 ± 1% 239.0 ± 0% +0.84% (p=0.016 n=10)
eventbridge-no-bus.json 258.0 ± 0%
eventbridge-no-timestamp.json 258.0 ± 0%
geomean 371.1 363.8 +0.32%
¹ all samples are equal
:steam_locomotive: MergeQueue: pull request added to the queue
The median merge time in main is 23m.
Use /merge -c to cancel this operation!