Skip to content

Improve Instrumenter API to use Context instead of Span #9211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Aug 12, 2025

Conversation

PerfectSlayer
Copy link
Contributor

@PerfectSlayer PerfectSlayer commented Jul 22, 2025

What Does This Do

Improve the instrumenter API to be context-based rather than span-based.
This will allow products other than tracing to create and aggregate information that does no more have to be stored in span. The main benefit is tracing instrumentations won't always have to be enabled so products do no more need pay the tracing overhead when trying to keep track of their data.

  • Improve startSpan API from HttpServerDecorator to be based on Context API. It comes with the following names for clarity:
    • parentContext as the upstream service context, usually contains an Extracted context as tracing context
    • context as the new child context containing tracing, dsm, asm information.
  • startSpan uses the instrumentation name declared from the HttpServerDecorator implementation
  • Improve Jetty AppSec instrumentation
    • Rely on Context rather than AgentSpan and RequestBlockingAction
  • Use CorrelationIdentifier API to get key and values to store for correlation
  • Fix wrong datadog.trace.instrumentation.azurefunctions package name

Motivation

AppSec changes was required as it was instrumenting the HttpServerDecorator API and it would help to move toward the Context API.
It simplifies both the call (less stack changes) and the null checks (less instructions to inject).
It also moves from local variable index lookup to idempotent access to current context (attach few instructions below).
It simplifies the DelayCertainInsMethodVisitor to use Runnable instead of Function as reapplying visitations do not requires parameters nor return values.

Additional Notes

Any minor change to the HttpServerDecorator needs a lot of fixes in multiple files.
I would have a hard time trying to split the PR into smaller working chunks.

Contributor Checklist

Jira ticket: LANGPLAT-680

@PerfectSlayer PerfectSlayer added the tag: do not merge Do not merge changes label Jul 22, 2025
@pr-commenter
Copy link

pr-commenter bot commented Jul 22, 2025

Benchmarks

Startup

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master bbujon/context
git_commit_date 1755006834 1755009211
git_commit_sha ef2e9f0 f7b9cb0
release_version 1.53.0-SNAPSHOT~ef2e9f03e6 1.53.0-SNAPSHOT~f7b9cb0fb1
See matching parameters
Baseline Candidate
application insecure-bank insecure-bank
ci_job_date 1755010924 1755010924
ci_job_id 1076306964 1076306964
ci_pipeline_id 73425764 73425764
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-0-8mnjh0ek 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-0-8mnjh0ek 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
module Agent Agent
parent None None

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 47 metrics, 12 unstable metrics.

Startup time reports for insecure-bank
gantt
    title insecure-bank - global startup overhead: candidate=1.53.0-SNAPSHOT~f7b9cb0fb1, baseline=1.53.0-SNAPSHOT~ef2e9f03e6

    dateFormat X
    axisFormat %s
section tracing
Agent [baseline] (1.042 s) : 0, 1041519
Total [baseline] (8.56 s) : 0, 8560476
Agent [candidate] (1.051 s) : 0, 1050754
Total [candidate] (8.589 s) : 0, 8588917
section iast
Agent [baseline] (1.177 s) : 0, 1176841
Total [baseline] (9.299 s) : 0, 9298659
Agent [candidate] (1.174 s) : 0, 1173505
Total [candidate] (9.295 s) : 0, 9294868
Loading
  • baseline results
Module Variant Duration Δ tracing
Agent tracing 1.042 s -
Agent iast 1.177 s 135.322 ms (13.0%)
Total tracing 8.56 s -
Total iast 9.299 s 738.184 ms (8.6%)
  • candidate results
Module Variant Duration Δ tracing
Agent tracing 1.051 s -
Agent iast 1.174 s 122.752 ms (11.7%)
Total tracing 8.589 s -
Total iast 9.295 s 705.951 ms (8.2%)
gantt
    title insecure-bank - break down per module: candidate=1.53.0-SNAPSHOT~f7b9cb0fb1, baseline=1.53.0-SNAPSHOT~ef2e9f03e6

    dateFormat X
    axisFormat %s
section tracing
crashtracking [baseline] (1.414 ms) : 0, 1414
crashtracking [candidate] (1.449 ms) : 0, 1449
BytebuddyAgent [baseline] (729.993 ms) : 0, 729993
BytebuddyAgent [candidate] (736.095 ms) : 0, 736095
GlobalTracer [baseline] (241.299 ms) : 0, 241299
GlobalTracer [candidate] (243.237 ms) : 0, 243237
AppSec [baseline] (29.915 ms) : 0, 29915
AppSec [candidate] (30.275 ms) : 0, 30275
Debugger [baseline] (5.97 ms) : 0, 5970
Debugger [candidate] (6.081 ms) : 0, 6081
Remote Config [baseline] (652.953 µs) : 0, 653
Remote Config [candidate] (653.125 µs) : 0, 653
Telemetry [baseline] (11.4 ms) : 0, 11400
Telemetry [candidate] (12.041 ms) : 0, 12041
section iast
crashtracking [baseline] (1.422 ms) : 0, 1422
crashtracking [candidate] (1.421 ms) : 0, 1421
BytebuddyAgent [baseline] (849.401 ms) : 0, 849401
BytebuddyAgent [candidate] (847.045 ms) : 0, 847045
GlobalTracer [baseline] (232.543 ms) : 0, 232543
GlobalTracer [candidate] (231.847 ms) : 0, 231847
IAST [baseline] (26.992 ms) : 0, 26992
IAST [candidate] (29.172 ms) : 0, 29172
AppSec [baseline] (29.115 ms) : 0, 29115
AppSec [candidate] (27.657 ms) : 0, 27657
Debugger [baseline] (7.434 ms) : 0, 7434
Debugger [candidate] (6.591 ms) : 0, 6591
Remote Config [baseline] (582.4 µs) : 0, 582
Remote Config [candidate] (582.679 µs) : 0, 583
Telemetry [baseline] (8.333 ms) : 0, 8333
Telemetry [candidate] (8.28 ms) : 0, 8280
Loading
Startup time reports for petclinic
gantt
    title petclinic - global startup overhead: candidate=1.53.0-SNAPSHOT~f7b9cb0fb1, baseline=1.53.0-SNAPSHOT~ef2e9f03e6

    dateFormat X
    axisFormat %s
section tracing
Agent [baseline] (1.045 s) : 0, 1044590
Total [baseline] (10.639 s) : 0, 10638581
Agent [candidate] (1.051 s) : 0, 1051285
Total [candidate] (10.701 s) : 0, 10700600
section appsec
Agent [baseline] (1.221 s) : 0, 1221168
Total [baseline] (10.821 s) : 0, 10820670
Agent [candidate] (1.219 s) : 0, 1218811
Total [candidate] (10.75 s) : 0, 10749961
section iast
Agent [baseline] (1.181 s) : 0, 1180524
Total [baseline] (10.908 s) : 0, 10907553
Agent [candidate] (1.18 s) : 0, 1179649
Total [candidate] (10.876 s) : 0, 10876013
section profiling
Agent [baseline] (1.208 s) : 0, 1207555
Total [baseline] (10.91 s) : 0, 10909854
Agent [candidate] (1.192 s) : 0, 1192431
Total [candidate] (10.844 s) : 0, 10844315
Loading
  • baseline results
Module Variant Duration Δ tracing
Agent tracing 1.045 s -
Agent appsec 1.221 s 176.578 ms (16.9%)
Agent iast 1.181 s 135.934 ms (13.0%)
Agent profiling 1.208 s 162.965 ms (15.6%)
Total tracing 10.639 s -
Total appsec 10.821 s 182.09 ms (1.7%)
Total iast 10.908 s 268.973 ms (2.5%)
Total profiling 10.91 s 271.273 ms (2.5%)
  • candidate results
Module Variant Duration Δ tracing
Agent tracing 1.051 s -
Agent appsec 1.219 s 167.526 ms (15.9%)
Agent iast 1.18 s 128.364 ms (12.2%)
Agent profiling 1.192 s 141.146 ms (13.4%)
Total tracing 10.701 s -
Total appsec 10.75 s 49.361 ms (0.5%)
Total iast 10.876 s 175.413 ms (1.6%)
Total profiling 10.844 s 143.715 ms (1.3%)
gantt
    title petclinic - break down per module: candidate=1.53.0-SNAPSHOT~f7b9cb0fb1, baseline=1.53.0-SNAPSHOT~ef2e9f03e6

    dateFormat X
    axisFormat %s
section tracing
crashtracking [baseline] (1.431 ms) : 0, 1431
crashtracking [candidate] (1.445 ms) : 0, 1445
BytebuddyAgent [baseline] (731.608 ms) : 0, 731608
BytebuddyAgent [candidate] (735.871 ms) : 0, 735871
GlobalTracer [baseline] (241.722 ms) : 0, 241722
GlobalTracer [candidate] (243.161 ms) : 0, 243161
AppSec [baseline] (30.085 ms) : 0, 30085
AppSec [candidate] (30.278 ms) : 0, 30278
Debugger [baseline] (6.005 ms) : 0, 6005
Debugger [candidate] (6.032 ms) : 0, 6032
Remote Config [baseline] (646.688 µs) : 0, 647
Remote Config [candidate] (660.571 µs) : 0, 661
Telemetry [baseline] (12.14 ms) : 0, 12140
Telemetry [candidate] (12.843 ms) : 0, 12843
section appsec
crashtracking [baseline] (1.434 ms) : 0, 1434
crashtracking [candidate] (1.432 ms) : 0, 1432
BytebuddyAgent [baseline] (753.841 ms) : 0, 753841
BytebuddyAgent [candidate] (753.032 ms) : 0, 753032
GlobalTracer [baseline] (235.489 ms) : 0, 235489
GlobalTracer [candidate] (234.324 ms) : 0, 234324
IAST [baseline] (23.744 ms) : 0, 23744
IAST [candidate] (23.39 ms) : 0, 23390
AppSec [baseline] (169.423 ms) : 0, 169423
AppSec [candidate] (168.572 ms) : 0, 168572
Debugger [baseline] (5.73 ms) : 0, 5730
Debugger [candidate] (7.995 ms) : 0, 7995
Remote Config [baseline] (613.468 µs) : 0, 613
Remote Config [candidate] (603.044 µs) : 0, 603
Telemetry [baseline] (9.881 ms) : 0, 9881
Telemetry [candidate] (8.372 ms) : 0, 8372
section iast
crashtracking [baseline] (1.429 ms) : 0, 1429
crashtracking [candidate] (1.434 ms) : 0, 1434
BytebuddyAgent [baseline] (852.202 ms) : 0, 852202
BytebuddyAgent [candidate] (851.188 ms) : 0, 851188
GlobalTracer [baseline] (233.571 ms) : 0, 233571
GlobalTracer [candidate] (233.592 ms) : 0, 233592
IAST [baseline] (30.035 ms) : 0, 30035
IAST [candidate] (26.853 ms) : 0, 26853
AppSec [baseline] (25.26 ms) : 0, 25260
AppSec [candidate] (29.986 ms) : 0, 29986
Debugger [baseline] (8.233 ms) : 0, 8233
Debugger [candidate] (6.584 ms) : 0, 6584
Remote Config [baseline] (588.853 µs) : 0, 589
Remote Config [candidate] (577.839 µs) : 0, 578
Telemetry [baseline] (8.238 ms) : 0, 8238
Telemetry [candidate] (8.291 ms) : 0, 8291
section profiling
crashtracking [baseline] (1.412 ms) : 0, 1412
crashtracking [candidate] (1.399 ms) : 0, 1399
BytebuddyAgent [baseline] (769.221 ms) : 0, 769221
BytebuddyAgent [candidate] (760.526 ms) : 0, 760526
GlobalTracer [baseline] (224.975 ms) : 0, 224975
GlobalTracer [candidate] (221.023 ms) : 0, 221023
AppSec [baseline] (30.611 ms) : 0, 30611
AppSec [candidate] (29.898 ms) : 0, 29898
Debugger [baseline] (6.399 ms) : 0, 6399
Debugger [candidate] (6.3 ms) : 0, 6300
Remote Config [baseline] (683.466 µs) : 0, 683
Remote Config [candidate] (698.006 µs) : 0, 698
Telemetry [baseline] (16.222 ms) : 0, 16222
Telemetry [candidate] (15.068 ms) : 0, 15068
ProfilingAgent [baseline] (108.117 ms) : 0, 108117
ProfilingAgent [candidate] (108.051 ms) : 0, 108051
Profiling [baseline] (108.771 ms) : 0, 108771
Profiling [candidate] (108.702 ms) : 0, 108702
Loading

Load

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master bbujon/context
git_commit_date 1755006834 1755009211
git_commit_sha ef2e9f0 f7b9cb0
release_version 1.53.0-SNAPSHOT~ef2e9f03e6 1.53.0-SNAPSHOT~f7b9cb0fb1
See matching parameters
Baseline Candidate
application insecure-bank insecure-bank
ci_job_date 1755010601 1755010601
ci_job_id 1076306965 1076306965
ci_pipeline_id 73425764 73425764
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-1-v94iprde 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-1-v94iprde 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

Summary

Found 1 performance improvements and 1 performance regressions! Performance is the same for 10 metrics, 12 unstable metrics.

scenario Δ mean http_req_duration Δ mean throughput candidate mean http_req_duration candidate mean throughput baseline mean http_req_duration baseline mean throughput
scenario:load:petclinic:code_origins:high_load worse
[+1.001ms; +1.824ms] or [+2.320%; +4.226%]
unstable
[-11.132op/s; +4.332op/s] or [-10.271%; +3.997%]
44.561ms 104.987op/s 43.149ms 108.388op/s
scenario:load:petclinic:profiling:high_load better
[-3.776ms; -2.776ms] or [-7.256%; -5.334%]
unstable
[-0.621op/s; +12.671op/s] or [-0.690%; +14.087%]
48.765ms 95.975op/s 52.041ms 89.950op/s
Request duration reports for insecure-bank
gantt
    title insecure-bank - request duration [CI 0.99] : candidate=1.53.0-SNAPSHOT~f7b9cb0fb1, baseline=1.53.0-SNAPSHOT~ef2e9f03e6
    dateFormat X
    axisFormat %s
section baseline
no_agent (4.307 ms) : 4256, 4358
.   : milestone, 4307,
iast (9.267 ms) : 9117, 9416
.   : milestone, 9267,
iast_FULL (14.082 ms) : 13798, 14365
.   : milestone, 14082,
iast_GLOBAL (10.455 ms) : 10269, 10641
.   : milestone, 10455,
profiling (8.472 ms) : 8336, 8608
.   : milestone, 8472,
tracing (7.607 ms) : 7500, 7715
.   : milestone, 7607,
section candidate
no_agent (4.365 ms) : 4315, 4414
.   : milestone, 4365,
iast (9.345 ms) : 9187, 9503
.   : milestone, 9345,
iast_FULL (14.452 ms) : 14163, 14742
.   : milestone, 14452,
iast_GLOBAL (10.449 ms) : 10266, 10633
.   : milestone, 10449,
profiling (8.617 ms) : 8482, 8751
.   : milestone, 8617,
tracing (7.838 ms) : 7723, 7953
.   : milestone, 7838,
Loading
  • baseline results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 4.307 ms [4.256 ms, 4.358 ms] -
iast 9.267 ms [9.117 ms, 9.416 ms] 4.96 ms (115.2%)
iast_FULL 14.082 ms [13.798 ms, 14.365 ms] 9.775 ms (227.0%)
iast_GLOBAL 10.455 ms [10.269 ms, 10.641 ms] 6.148 ms (142.8%)
profiling 8.472 ms [8.336 ms, 8.608 ms] 4.165 ms (96.7%)
tracing 7.607 ms [7.5 ms, 7.715 ms] 3.3 ms (76.6%)
  • candidate results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 4.365 ms [4.315 ms, 4.414 ms] -
iast 9.345 ms [9.187 ms, 9.503 ms] 4.98 ms (114.1%)
iast_FULL 14.452 ms [14.163 ms, 14.742 ms] 10.088 ms (231.1%)
iast_GLOBAL 10.449 ms [10.266 ms, 10.633 ms] 6.085 ms (139.4%)
profiling 8.617 ms [8.482 ms, 8.751 ms] 4.252 ms (97.4%)
tracing 7.838 ms [7.723 ms, 7.953 ms] 3.473 ms (79.6%)
Request duration reports for petclinic
gantt
    title petclinic - request duration [CI 0.99] : candidate=1.53.0-SNAPSHOT~f7b9cb0fb1, baseline=1.53.0-SNAPSHOT~ef2e9f03e6
    dateFormat X
    axisFormat %s
section baseline
no_agent (36.993 ms) : 36689, 37297
.   : milestone, 36993,
appsec (48.356 ms) : 47924, 48788
.   : milestone, 48356,
code_origins (43.149 ms) : 42776, 43521
.   : milestone, 43149,
iast (46.016 ms) : 45608, 46425
.   : milestone, 46016,
profiling (52.041 ms) : 51565, 52516
.   : milestone, 52041,
tracing (44.41 ms) : 44025, 44795
.   : milestone, 44410,
section candidate
no_agent (37.48 ms) : 37183, 37778
.   : milestone, 37480,
appsec (48.601 ms) : 48170, 49033
.   : milestone, 48601,
code_origins (44.561 ms) : 44169, 44953
.   : milestone, 44561,
iast (46.133 ms) : 45730, 46536
.   : milestone, 46133,
profiling (48.765 ms) : 48311, 49218
.   : milestone, 48765,
tracing (43.851 ms) : 43494, 44209
.   : milestone, 43851,
Loading
  • baseline results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 36.993 ms [36.689 ms, 37.297 ms] -
appsec 48.356 ms [47.924 ms, 48.788 ms] 11.363 ms (30.7%)
code_origins 43.149 ms [42.776 ms, 43.521 ms] 6.156 ms (16.6%)
iast 46.016 ms [45.608 ms, 46.425 ms] 9.023 ms (24.4%)
profiling 52.041 ms [51.565 ms, 52.516 ms] 15.048 ms (40.7%)
tracing 44.41 ms [44.025 ms, 44.795 ms] 7.417 ms (20.0%)
  • candidate results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 37.48 ms [37.183 ms, 37.778 ms] -
appsec 48.601 ms [48.17 ms, 49.033 ms] 11.121 ms (29.7%)
code_origins 44.561 ms [44.169 ms, 44.953 ms] 7.081 ms (18.9%)
iast 46.133 ms [45.73 ms, 46.536 ms] 8.652 ms (23.1%)
profiling 48.765 ms [48.311 ms, 49.218 ms] 11.284 ms (30.1%)
tracing 43.851 ms [43.494 ms, 44.209 ms] 6.371 ms (17.0%)

Dacapo

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master bbujon/context
git_commit_date 1755006834 1755009211
git_commit_sha ef2e9f0 f7b9cb0
release_version 1.53.0-SNAPSHOT~ef2e9f03e6 1.53.0-SNAPSHOT~f7b9cb0fb1
See matching parameters
Baseline Candidate
application biojava biojava
ci_job_date 1755011202 1755011202
ci_job_id 1076306966 1076306966
ci_pipeline_id 73425764 73425764
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-0-brkm2vbj 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-0-brkm2vbj 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 11 metrics, 1 unstable metrics.

Execution time for tomcat
gantt
    title tomcat - execution time [CI 0.99] : candidate=1.53.0-SNAPSHOT~f7b9cb0fb1, baseline=1.53.0-SNAPSHOT~ef2e9f03e6
    dateFormat X
    axisFormat %s
section baseline
no_agent (1.477 ms) : 1465, 1488
.   : milestone, 1477,
appsec (3.69 ms) : 3471, 3909
.   : milestone, 3690,
iast (2.2 ms) : 2137, 2262
.   : milestone, 2200,
iast_GLOBAL (2.248 ms) : 2185, 2311
.   : milestone, 2248,
profiling (2.07 ms) : 2017, 2122
.   : milestone, 2070,
tracing (2.027 ms) : 1978, 2077
.   : milestone, 2027,
section candidate
no_agent (1.476 ms) : 1464, 1487
.   : milestone, 1476,
appsec (3.615 ms) : 3401, 3829
.   : milestone, 3615,
iast (2.213 ms) : 2150, 2276
.   : milestone, 2213,
iast_GLOBAL (2.257 ms) : 2193, 2320
.   : milestone, 2257,
profiling (2.045 ms) : 1995, 2096
.   : milestone, 2045,
tracing (2.029 ms) : 1980, 2078
.   : milestone, 2029,
Loading
  • baseline results
Variant Execution Time [CI 0.99] Δ no_agent
no_agent 1.477 ms [1.465 ms, 1.488 ms] -
appsec 3.69 ms [3.471 ms, 3.909 ms] 2.214 ms (149.9%)
iast 2.2 ms [2.137 ms, 2.262 ms] 723.074 µs (49.0%)
iast_GLOBAL 2.248 ms [2.185 ms, 2.311 ms] 771.287 µs (52.2%)
profiling 2.07 ms [2.017 ms, 2.122 ms] 593.037 µs (40.2%)
tracing 2.027 ms [1.978 ms, 2.077 ms] 550.842 µs (37.3%)
  • candidate results
Variant Execution Time [CI 0.99] Δ no_agent
no_agent 1.476 ms [1.464 ms, 1.487 ms] -
appsec 3.615 ms [3.401 ms, 3.829 ms] 2.139 ms (144.9%)
iast 2.213 ms [2.15 ms, 2.276 ms] 737.341 µs (50.0%)
iast_GLOBAL 2.257 ms [2.193 ms, 2.32 ms] 780.927 µs (52.9%)
profiling 2.045 ms [1.995 ms, 2.096 ms] 569.717 µs (38.6%)
tracing 2.029 ms [1.98 ms, 2.078 ms] 553.125 µs (37.5%)
Execution time for biojava
gantt
    title biojava - execution time [CI 0.99] : candidate=1.53.0-SNAPSHOT~f7b9cb0fb1, baseline=1.53.0-SNAPSHOT~ef2e9f03e6
    dateFormat X
    axisFormat %s
section baseline
no_agent (14.96 s) : 14960000, 14960000
.   : milestone, 14960000,
appsec (14.75 s) : 14750000, 14750000
.   : milestone, 14750000,
iast (18.402 s) : 18402000, 18402000
.   : milestone, 18402000,
iast_GLOBAL (17.985 s) : 17985000, 17985000
.   : milestone, 17985000,
profiling (15.449 s) : 15449000, 15449000
.   : milestone, 15449000,
tracing (14.846 s) : 14846000, 14846000
.   : milestone, 14846000,
section candidate
no_agent (15.262 s) : 15262000, 15262000
.   : milestone, 15262000,
appsec (14.917 s) : 14917000, 14917000
.   : milestone, 14917000,
iast (18.361 s) : 18361000, 18361000
.   : milestone, 18361000,
iast_GLOBAL (18.192 s) : 18192000, 18192000
.   : milestone, 18192000,
profiling (15.333 s) : 15333000, 15333000
.   : milestone, 15333000,
tracing (15.082 s) : 15082000, 15082000
.   : milestone, 15082000,
Loading
  • baseline results
Variant Execution Time [CI 0.99] Δ no_agent
no_agent 14.96 s [14.96 s, 14.96 s] -
appsec 14.75 s [14.75 s, 14.75 s] -210.0 ms (-1.4%)
iast 18.402 s [18.402 s, 18.402 s] 3.442 s (23.0%)
iast_GLOBAL 17.985 s [17.985 s, 17.985 s] 3.025 s (20.2%)
profiling 15.449 s [15.449 s, 15.449 s] 489.0 ms (3.3%)
tracing 14.846 s [14.846 s, 14.846 s] -114.0 ms (-0.8%)
  • candidate results
Variant Execution Time [CI 0.99] Δ no_agent
no_agent 15.262 s [15.262 s, 15.262 s] -
appsec 14.917 s [14.917 s, 14.917 s] -345.0 ms (-2.3%)
iast 18.361 s [18.361 s, 18.361 s] 3.099 s (20.3%)
iast_GLOBAL 18.192 s [18.192 s, 18.192 s] 2.93 s (19.2%)
profiling 15.333 s [15.333 s, 15.333 s] 71.0 ms (0.5%)
tracing 15.082 s [15.082 s, 15.082 s] -180.0 ms (-1.2%)

@datadog-datadog-prod-us1
Copy link
Contributor

datadog-datadog-prod-us1 bot commented Aug 4, 2025

Code coverage: total 57.31%, patch 76.92% (view details)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: f7b9cb0 | Docs | Was this helpful? Give us feedback!

@PerfectSlayer PerfectSlayer force-pushed the bbujon/context branch 3 times, most recently from 63e0f86 to 050278f Compare August 8, 2025 11:20
public static void blockAndThrowOnFailure(
Request request, Response response, Flow.Action.RequestBlockingAction rba, AgentSpan span) {
if (!block(request, response, rba, span)) {
public static boolean hasRequestBlockingAction(Context context) {
Copy link
Contributor Author

@PerfectSlayer PerfectSlayer Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context parameter could be removed here as always current but I find it more explicit to have it given as parameter as the context retrieval will be located near the context creation / attachement.

Additionally, all other helper methods have a Context instance as parameter so it stays consistent.

@@ -216,4 +216,12 @@ default <T> T get(@Nonnull ContextKey<T> key) {
default <T> Context with(@Nonnull ContextKey<T> key, @Nullable T value) {
return SPAN_KEY == key ? (Context) value : Context.root().with(SPAN_KEY, this, key, value);
}

@Override
default Context with(@Nullable ImplicitContextKeyed value) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This optimization usually happens when creating local root span from remote extracted context.
@mcculls Do you think it worth it as we will end up allocating an array as soon as there is a second context element?

@PerfectSlayer PerfectSlayer added type: enhancement Enhancements and improvements type: refactoring comp: context propagation Trace context propagation and removed tag: do not merge Do not merge changes labels Aug 11, 2025
@PerfectSlayer PerfectSlayer removed the type: enhancement Enhancements and improvements label Aug 11, 2025
@PerfectSlayer PerfectSlayer marked this pull request as ready for review August 11, 2025 16:12
@PerfectSlayer PerfectSlayer requested review from a team as code owners August 11, 2025 16:12
@PerfectSlayer PerfectSlayer requested a review from mcculls August 11, 2025 16:12
Copy link
Contributor

@mhlidd mhlidd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good! Left a few notes

@@ -160,6 +164,11 @@ public AgentSpan onRequest(
return onRequest(span, connection, request, getExtractedSpanContext(context));
}

public AgentSpanContext.Extracted getExtractedSpanContext(Context context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something that we can set as a private method now? It seems like the only two instrumentations that use this still are SprayHttpServerRunSealedRouteAdvice and TomcatServerInstrumentation. (Albeit modifications would have to be made to those functionality)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About TomcatServerInstrumentation, it feels I would be picking your leftover (git blame this line 😬 ):

// TODO: Migrate setting DD_EXTRACTED_CONTEXT_ATTRIBUTE from AgentSpanContext.Extracted to

About Spray, I could try. I'm not that familiar with Scala, but that sounds doable.
What about doing it in a follow up PR? I expect to have even more refactoring coming to make gateway inferred span happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up on #9358

Comment on lines -77 to -80
} else {
span = startSpan(DECORATE.spanName());
span.setMeasured(true);
context = span;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to do a check for context == Context.root() and if so then call startSpan(DECORATE.spanName());?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. spanSpan can be called with a context without tracing span.
Even the IG callback support the fact there is no Extracted context.

The goal of having non-null, immutable, always-valid context instances is to avoid this kind of branching and make the code simpler.

@@ -1,4 +1,4 @@
package datadog.trace.instrumentation.azurefunctions;
package datadog.trace.instrumentation.azure.functions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow good catch 😮

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I need to review the spec to find out how this even work 🤷

@PerfectSlayer PerfectSlayer changed the title Context work draft Improve Instrumenter API to use Context instead of Span Aug 12, 2025
Copy link
Contributor

@amarziali amarziali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok. Thanks for the detailed description

Unclear of the benefits compared to the existing optimization.
@PerfectSlayer PerfectSlayer enabled auto-merge (squash) August 12, 2025 14:59
@PerfectSlayer PerfectSlayer merged commit f9278b6 into master Aug 12, 2025
500 checks passed
@PerfectSlayer PerfectSlayer deleted the bbujon/context branch August 12, 2025 15:38
@github-actions github-actions bot added this to the 1.53.0 milestone Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants