datadog-agent
datadog-agent copied to clipboard
Add EventBridge Inferred Spans
What does this PR do?
- This PR fixes/adds EventBridge inferred spans for Lambda.
- Specifically, this PR supports inferred spans for
Lambda -> EventBridge -> Lambda,Lambda -> EventBridge -> SQS -> Lambda, andLambda -> EventBridge -> SNS -> Lambda. These are the most common use cases that customers want supported.
Motivation
SNS and SQS are already supported. There was some code in place for EventBridge, but it didn't work properly. Even the simplest case, Lambda -> EventBridge -> Lambda, didn't show a span for EventBridge. This PR aims to fix this, and handle other common cases like EventBridge -> SQS and EventBridge -> SNS.
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, 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
SentTimestamp. 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
BusNamefor the span resource name. If this doesn't exist, we set the resource name to "EventBridge". -
This should not be a breaking change, but reviewers should double check my changes and keep this in mind. 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 should show an "EventBridge" span on any Lambda function invoked by the EventBridge event:
Traces before these changes
Lambda --> EventBridge --> Lambda
Two different traces. Second trace is missing an EventBridge span
Lambda --> EventBridge --> SQS --> Lambda
Missing EventBridge span
Lambda --> EventBridge --> SNS --> Lambda
Missing EventBridge span
Traces after these changes
Lambda --> EventBridge --> Lambda
Lambda --> EventBridge --> SQS --> Lambda
Lambda --> EventBridge --> SNS --> Lambda
Possible Drawbacks / Trade-offs
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:
- 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=44525616 --os-family=ubuntu
Note: This applies to commit 1d7799ef
Serverless Benchmark Results
BenchmarkStartEndInvocation comparison between c7eb6e5fd9102291c697a89e7ae4150ae93ae56a and c23d241dbaaa05747cbe1477917d67406e089f70.
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 84.74µ ± 6% 87.03µ ± 4% ~ (p=0.165 n=10)
api-gateway-kong-appsec.json 65.47µ ± 1% 68.28µ ± 1% +4.28% (p=0.000 n=10)
api-gateway-kong.json 64.24µ ± 1% 67.65µ ± 1% +5.32% (p=0.000 n=10)
api-gateway-non-proxy-async.json 102.2µ ± 1% 106.8µ ± 1% +4.55% (p=0.000 n=10)
api-gateway-non-proxy.json 102.2µ ± 3% 107.2µ ± 1% +4.81% (p=0.001 n=10)
api-gateway-websocket-connect.json 67.49µ ± 1% 71.99µ ± 2% +6.66% (p=0.000 n=10)
api-gateway-websocket-default.json 60.98µ ± 1% 64.97µ ± 1% +6.55% (p=0.000 n=10)
api-gateway-websocket-disconnect.json 61.15µ ± 1% 65.05µ ± 1% +6.39% (p=0.000 n=10)
api-gateway.json 112.8µ ± 0% 119.3µ ± 3% +5.75% (p=0.000 n=10)
application-load-balancer.json 61.83µ ± 1% 66.94µ ± 2% +8.26% (p=0.000 n=10)
cloudfront.json 46.60µ ± 2% 50.23µ ± 2% +7.81% (p=0.000 n=10)
cloudwatch-events.json 37.80µ ± 2% 39.76µ ± 2% +5.17% (p=0.000 n=10)
cloudwatch-logs.json 63.15µ ± 3% 66.54µ ± 1% +5.36% (p=0.000 n=10)
custom.json 30.55µ ± 1% 32.16µ ± 2% +5.25% (p=0.000 n=10)
dynamodb.json 92.81µ ± 0% 96.36µ ± 2% +3.83% (p=0.000 n=10)
empty.json 28.93µ ± 1% 30.35µ ± 2% +4.90% (p=0.000 n=10)
eventbridge-custom.json 42.06µ ± 2% 49.04µ ± 3% +16.61% (p=0.000 n=10)
http-api.json 72.48µ ± 1% 75.17µ ± 1% +3.71% (p=0.000 n=10)
kinesis-batch.json 69.61µ ± 1% 74.12µ ± 2% +6.49% (p=0.000 n=10)
kinesis.json 53.62µ ± 1% 56.82µ ± 1% +5.96% (p=0.000 n=10)
s3.json 59.38µ ± 1% 62.89µ ± 2% +5.90% (p=0.000 n=10)
sns-batch.json 89.68µ ± 4% 93.85µ ± 2% +4.65% (p=0.000 n=10)
sns.json 64.23µ ± 1% 69.99µ ± 1% +8.96% (p=0.000 n=10)
snssqs.json 108.6µ ± 1% 113.1µ ± 2% +4.15% (p=0.000 n=10)
snssqs_no_dd_context.json 97.95µ ± 1% 104.58µ ± 2% +6.77% (p=0.000 n=10)
sqs-aws-header.json 55.08µ ± 2% 63.04µ ± 3% +14.46% (p=0.000 n=10)
sqs-batch.json 93.94µ ± 2% 100.08µ ± 1% +6.54% (p=0.000 n=10)
sqs.json 68.94µ ± 2% 75.93µ ± 2% +10.14% (p=0.000 n=10)
sqs_no_dd_context.json 63.18µ ± 5% 69.51µ ± 3% +10.03% (p=0.000 n=10)
eventbridge-no-bus.json 48.54µ ± 3%
eventbridge-no-sent-timestamp.json 48.16µ ± 2%
eventbridgesns.json 70.00µ ± 1%
eventbridgesqs.json 81.89µ ± 61%
geomean 65.89µ 68.97µ +6.58%
│ baseline/benchmark.log │ current/benchmark.log │
│ B/op │ B/op vs base │
api-gateway-appsec.json 37.25Ki ± 0% 37.33Ki ± 0% +0.19% (p=0.000 n=10)
api-gateway-kong-appsec.json 26.92Ki ± 0% 26.92Ki ± 0% ~ (p=0.239 n=10)
api-gateway-kong.json 24.41Ki ± 0% 24.42Ki ± 0% ~ (p=0.306 n=10)
api-gateway-non-proxy-async.json 48.03Ki ± 0% 48.10Ki ± 0% +0.14% (p=0.000 n=10)
api-gateway-non-proxy.json 47.26Ki ± 0% 47.32Ki ± 0% +0.12% (p=0.000 n=10)
api-gateway-websocket-connect.json 25.45Ki ± 0% 25.50Ki ± 0% +0.20% (p=0.000 n=10)
api-gateway-websocket-default.json 21.36Ki ± 0% 21.41Ki ± 0% +0.25% (p=0.000 n=10)
api-gateway-websocket-disconnect.json 21.14Ki ± 0% 21.19Ki ± 0% +0.23% (p=0.000 n=10)
api-gateway.json 49.54Ki ± 0% 49.58Ki ± 0% +0.08% (p=0.000 n=10)
application-load-balancer.json 22.33Ki ± 0% 23.29Ki ± 0% +4.31% (p=0.000 n=10)
cloudfront.json 17.63Ki ± 0% 17.68Ki ± 0% +0.27% (p=0.000 n=10)
cloudwatch-events.json 11.67Ki ± 0% 11.73Ki ± 0% +0.49% (p=0.000 n=10)
cloudwatch-logs.json 53.35Ki ± 0% 53.37Ki ± 0% +0.04% (p=0.005 n=10)
custom.json 9.720Ki ± 0% 9.763Ki ± 0% +0.44% (p=0.000 n=10)
dynamodb.json 40.75Ki ± 0% 40.82Ki ± 0% +0.15% (p=0.000 n=10)
empty.json 9.275Ki ± 0% 9.313Ki ± 0% +0.42% (p=0.001 n=10)
eventbridge-custom.json 13.40Ki ± 0% 15.68Ki ± 0% +16.98% (p=0.000 n=10)
http-api.json 23.72Ki ± 0% 23.95Ki ± 0% +0.96% (p=0.000 n=10)
kinesis-batch.json 27.00Ki ± 0% 27.17Ki ± 0% +0.64% (p=0.000 n=10)
kinesis.json 17.79Ki ± 1% 18.00Ki ± 0% +1.21% (p=0.000 n=10)
s3.json 20.33Ki ± 0% 20.52Ki ± 0% +0.92% (p=0.000 n=10)
sns-batch.json 38.65Ki ± 0% 39.42Ki ± 0% +2.00% (p=0.000 n=10)
sns.json 23.96Ki ± 0% 24.62Ki ± 0% +2.76% (p=0.000 n=10)
snssqs.json 50.52Ki ± 0% 50.84Ki ± 0% +0.62% (p=0.000 n=10)
snssqs_no_dd_context.json 44.77Ki ± 0% 45.28Ki ± 0% +1.14% (p=0.000 n=10)
sqs-aws-header.json 18.79Ki ± 0% 19.53Ki ± 1% +3.94% (p=0.000 n=10)
sqs-batch.json 41.59Ki ± 0% 42.39Ki ± 1% +1.93% (p=0.000 n=10)
sqs.json 25.54Ki ± 0% 26.25Ki ± 1% +2.76% (p=0.000 n=10)
sqs_no_dd_context.json 20.52Ki ± 1% 21.40Ki ± 1% +4.27% (p=0.000 n=10)
eventbridge-no-bus.json 14.68Ki ± 0%
eventbridge-no-sent-timestamp.json 14.70Ki ± 0%
eventbridgesns.json 23.41Ki ± 0%
eventbridgesqs.json 26.97Ki ± 2%
geomean 25.68Ki 25.14Ki +1.59%
│ baseline/benchmark.log │ current/benchmark.log │
│ allocs/op │ allocs/op vs base │
api-gateway-appsec.json 629.0 ± 0% 630.0 ± 0% ~ (p=0.370 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 725.0 ± 0% 726.0 ± 0% ~ (p=0.656 n=10)
api-gateway-non-proxy.json 716.0 ± 0% 716.0 ± 0% ~ (p=1.000 n=10)
api-gateway-websocket-connect.json 453.0 ± 0% 453.0 ± 0% ~ (p=0.211 n=10)
api-gateway-websocket-default.json 379.0 ± 0% 379.0 ± 0% ~ (p=0.303 n=10)
api-gateway-websocket-disconnect.json 369.5 ± 0% 370.0 ± 0% ~ (p=0.141 n=10)
api-gateway.json 790.0 ± 0% 791.0 ± 0% +0.13% (p=0.023 n=10)
application-load-balancer.json 352.0 ± 0% 353.0 ± 0% +0.28% (p=0.000 n=10)
cloudfront.json 283.5 ± 0% 284.0 ± 0% +0.18% (p=0.033 n=10)
cloudwatch-events.json 220.0 ± 0% 220.0 ± 0% ~ (p=0.211 n=10)
cloudwatch-logs.json 215.0 ± 0% 215.5 ± 0% ~ (p=0.350 n=10)
custom.json 168.0 ± 0% 169.0 ± 0% +0.60% (p=0.000 n=10)
dynamodb.json 589.0 ± 0% 589.0 ± 0% ~ (p=0.124 n=10)
empty.json 160.0 ± 1% 160.0 ± 1% ~ (p=0.628 n=10)
eventbridge-custom.json 254.0 ± 0% 270.0 ± 0% +6.30% (p=0.000 n=10)
http-api.json 432.0 ± 0% 435.0 ± 0% +0.69% (p=0.000 n=10)
kinesis-batch.json 390.0 ± 0% 392.5 ± 0% +0.64% (p=0.000 n=10)
kinesis.json 285.0 ± 1% 288.0 ± 0% +1.05% (p=0.000 n=10)
s3.json 358.0 ± 0% 360.0 ± 0% +0.56% (p=0.000 n=10)
sns-batch.json 454.5 ± 0% 468.0 ± 0% +2.97% (p=0.000 n=10)
sns.json 323.0 ± 0% 335.0 ± 1% +3.72% (p=0.000 n=10)
snssqs.json 437.5 ± 0% 440.5 ± 0% +0.69% (p=0.000 n=10)
snssqs_no_dd_context.json 399.0 ± 0% 409.0 ± 0% +2.51% (p=0.000 n=10)
sqs-aws-header.json 273.5 ± 1% 288.5 ± 1% +5.48% (p=0.000 n=10)
sqs-batch.json 503.0 ± 0% 518.5 ± 1% +3.08% (p=0.000 n=10)
sqs.json 350.5 ± 0% 365.0 ± 1% +4.14% (p=0.000 n=10)
sqs_no_dd_context.json 322.5 ± 1% 338.5 ± 1% +4.96% (p=0.000 n=10)
eventbridge-no-bus.json 261.0 ± 0%
eventbridge-no-sent-timestamp.json 261.0 ± 0%
eventbridgesns.json 369.0 ± 0%
eventbridgesqs.json 387.5 ± 2%
geomean 376.1 372.3 +1.32%
¹ all samples are equal
Regression Detector
Regression Detector Results
Run ID: b2ddef8d-7fac-4d4e-b9f7-9315f527e4ec Metrics dashboard Target profiles
Baseline: c7eb6e5fd9102291c697a89e7ae4150ae93ae56a Comparison: 1d7799ef0e67b80715f5c09580063d09cc267a0f
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.52 | [-1.24, +4.28] | 1 | Logs |
| ➖ | basic_py_check | % cpu utilization | +1.32 | [-1.61, +4.25] | 1 | Logs |
| ➖ | idle | memory utilization | +0.04 | [-0.00, +0.09] | 1 | Logs |
| ➖ | uds_dogstatsd_to_api | ingress throughput | -0.00 | [-0.00, +0.00] | 1 | Logs |
| ➖ | tcp_dd_logs_filter_exclude | ingress throughput | -0.00 | [-0.01, +0.01] | 1 | Logs |
| ➖ | uds_dogstatsd_to_api_cpu | % cpu utilization | -0.03 | [-0.78, +0.73] | 1 | Logs |
| ➖ | file_tree | memory utilization | -0.13 | [-0.25, -0.01] | 1 | Logs |
| ➖ | otel_to_otel_logs | ingress throughput | -0.21 | [-1.04, +0.61] | 1 | Logs |
| ➖ | tcp_syslog_to_blackhole | ingress throughput | -0.44 | [-0.49, -0.39] | 1 | Logs |
Bounds Checks
| perf | experiment | bounds_check_name | replicates_passed |
|---|---|---|---|
| ❌ | idle | memory_usage | 7/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".