Skip to content
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

Allow use of span as a primordial context #8250

Merged
merged 3 commits into from
Jan 22, 2025

Conversation

mcculls
Copy link
Contributor

@mcculls mcculls commented Jan 20, 2025

What Does This Do

Supports using implementations of AgentSpan as Context.

Motivation

Helps migration of tracing towards the context-based approach.

Additional Notes

A convenience method was added to Context that accepts a pair of key-value mappings. This lets custom root context implementations skip creation of the interim context when adding two entries at the same time, for example a span and a baggage holder. We do not expect to require further variants of this method, but this particular case is worth adding to reduce copying when inflating spans into full contexts.

Contributor Checklist

Jira ticket: APMAPI-959

@mcculls mcculls requested a review from PerfectSlayer January 20, 2025 11:20
@mcculls mcculls marked this pull request as ready for review January 20, 2025 11:20
@mcculls mcculls requested a review from a team as a code owner January 20, 2025 11:20
@mcculls mcculls force-pushed the mcculls/span-as-primordial-context branch from d863876 to 332d71c Compare January 20, 2025 11:46
@pr-commenter
Copy link

pr-commenter bot commented Jan 20, 2025

Benchmarks

Startup

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master mcculls/span-as-primordial-context
git_commit_date 1737487402 1737536385
git_commit_sha 1f71dbd ab36886
release_version 1.46.0-SNAPSHOT~1f71dbd1b1 1.46.0-SNAPSHOT~ab3688699d
See matching parameters
Baseline Candidate
application insecure-bank insecure-bank
ci_job_date 1737538972 1737538972
ci_job_id 775343537 775343537
ci_pipeline_id 53649858 53649858
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
module Agent Agent
parent None None
variant iast iast

Summary

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

Startup time reports for insecure-bank
gantt
    title insecure-bank - global startup overhead: candidate=1.46.0-SNAPSHOT~ab3688699d, baseline=1.46.0-SNAPSHOT~1f71dbd1b1

    dateFormat X
    axisFormat %s
section tracing
Agent [baseline] (1.055 s) : 0, 1055336
Total [baseline] (8.658 s) : 0, 8657876
Agent [candidate] (1.056 s) : 0, 1055946
Total [candidate] (8.646 s) : 0, 8646047
section iast
Agent [baseline] (1.182 s) : 0, 1182355
Total [baseline] (9.193 s) : 0, 9192686
Agent [candidate] (1.191 s) : 0, 1191489
Total [candidate] (9.215 s) : 0, 9214651
section iast_HARDCODED_SECRET_DISABLED
Agent [baseline] (1.183 s) : 0, 1182699
Total [baseline] (9.179 s) : 0, 9178866
Agent [candidate] (1.191 s) : 0, 1191370
Total [candidate] (9.248 s) : 0, 9247629
section iast_TELEMETRY_OFF
Agent [baseline] (1.175 s) : 0, 1174705
Total [baseline] (9.168 s) : 0, 9168434
Agent [candidate] (1.177 s) : 0, 1177001
Total [candidate] (9.23 s) : 0, 9229869
Loading
  • baseline results
Module Variant Duration Δ tracing
Agent tracing 1.055 s -
Agent iast 1.182 s 127.019 ms (12.0%)
Agent iast_HARDCODED_SECRET_DISABLED 1.183 s 127.363 ms (12.1%)
Agent iast_TELEMETRY_OFF 1.175 s 119.369 ms (11.3%)
Total tracing 8.658 s -
Total iast 9.193 s 534.81 ms (6.2%)
Total iast_HARDCODED_SECRET_DISABLED 9.179 s 520.991 ms (6.0%)
Total iast_TELEMETRY_OFF 9.168 s 510.558 ms (5.9%)
  • candidate results
Module Variant Duration Δ tracing
Agent tracing 1.056 s -
Agent iast 1.191 s 135.543 ms (12.8%)
Agent iast_HARDCODED_SECRET_DISABLED 1.191 s 135.424 ms (12.8%)
Agent iast_TELEMETRY_OFF 1.177 s 121.055 ms (11.5%)
Total tracing 8.646 s -
Total iast 9.215 s 568.604 ms (6.6%)
Total iast_HARDCODED_SECRET_DISABLED 9.248 s 601.583 ms (7.0%)
Total iast_TELEMETRY_OFF 9.23 s 583.822 ms (6.8%)
gantt
    title insecure-bank - break down per module: candidate=1.46.0-SNAPSHOT~ab3688699d, baseline=1.46.0-SNAPSHOT~1f71dbd1b1

    dateFormat X
    axisFormat %s
section tracing
BytebuddyAgent [baseline] (712.836 ms) : 0, 712836
BytebuddyAgent [candidate] (713.923 ms) : 0, 713923
GlobalTracer [baseline] (255.539 ms) : 0, 255539
GlobalTracer [candidate] (255.789 ms) : 0, 255789
AppSec [baseline] (55.532 ms) : 0, 55532
AppSec [candidate] (55.516 ms) : 0, 55516
Remote Config [baseline] (735.749 µs) : 0, 736
Remote Config [candidate] (752.728 µs) : 0, 753
Telemetry [baseline] (15.786 ms) : 0, 15786
Telemetry [candidate] (14.933 ms) : 0, 14933
section iast
BytebuddyAgent [baseline] (831.706 ms) : 0, 831706
BytebuddyAgent [candidate] (837.854 ms) : 0, 837854
GlobalTracer [baseline] (246.364 ms) : 0, 246364
GlobalTracer [candidate] (247.979 ms) : 0, 247979
AppSec [baseline] (58.172 ms) : 0, 58172
AppSec [candidate] (58.935 ms) : 0, 58935
IAST [baseline] (21.585 ms) : 0, 21585
IAST [candidate] (21.832 ms) : 0, 21832
Remote Config [baseline] (679.167 µs) : 0, 679
Remote Config [candidate] (691.881 µs) : 0, 692
Telemetry [baseline] (8.827 ms) : 0, 8827
Telemetry [candidate] (8.939 ms) : 0, 8939
section iast_HARDCODED_SECRET_DISABLED
BytebuddyAgent [baseline] (831.671 ms) : 0, 831671
BytebuddyAgent [candidate] (837.873 ms) : 0, 837873
GlobalTracer [baseline] (246.896 ms) : 0, 246896
GlobalTracer [candidate] (248.266 ms) : 0, 248266
AppSec [baseline] (58.111 ms) : 0, 58111
AppSec [candidate] (58.644 ms) : 0, 58644
IAST [baseline] (21.443 ms) : 0, 21443
IAST [candidate] (21.783 ms) : 0, 21783
Remote Config [baseline] (679.205 µs) : 0, 679
Remote Config [candidate] (678.714 µs) : 0, 679
Telemetry [baseline] (8.907 ms) : 0, 8907
Telemetry [candidate] (8.925 ms) : 0, 8925
section iast_TELEMETRY_OFF
BytebuddyAgent [baseline] (825.958 ms) : 0, 825958
BytebuddyAgent [candidate] (827.41 ms) : 0, 827410
GlobalTracer [baseline] (245.621 ms) : 0, 245621
GlobalTracer [candidate] (246.434 ms) : 0, 246434
AppSec [baseline] (57.707 ms) : 0, 57707
AppSec [candidate] (57.817 ms) : 0, 57817
IAST [baseline] (21.12 ms) : 0, 21120
IAST [candidate] (21.058 ms) : 0, 21058
Remote Config [baseline] (662.577 µs) : 0, 663
Remote Config [candidate] (680.866 µs) : 0, 681
Telemetry [baseline] (8.655 ms) : 0, 8655
Telemetry [candidate] (8.598 ms) : 0, 8598
Loading
Startup time reports for petclinic
gantt
    title petclinic - global startup overhead: candidate=1.46.0-SNAPSHOT~ab3688699d, baseline=1.46.0-SNAPSHOT~1f71dbd1b1

    dateFormat X
    axisFormat %s
section tracing
Agent [baseline] (1.05 s) : 0, 1050287
Total [baseline] (10.455 s) : 0, 10455316
Agent [candidate] (1.054 s) : 0, 1053794
Total [candidate] (10.557 s) : 0, 10556727
section appsec
Agent [baseline] (1.192 s) : 0, 1191939
Total [baseline] (10.696 s) : 0, 10696114
Agent [candidate] (1.188 s) : 0, 1188449
Total [candidate] (10.762 s) : 0, 10762263
section iast
Agent [baseline] (1.184 s) : 0, 1184044
Total [baseline] (11.131 s) : 0, 11130633
Agent [candidate] (1.183 s) : 0, 1183139
Total [candidate] (10.969 s) : 0, 10969121
section profiling
Agent [baseline] (1.253 s) : 0, 1252595
Total [baseline] (10.807 s) : 0, 10807189
Agent [candidate] (1.255 s) : 0, 1255134
Total [candidate] (10.81 s) : 0, 10809787
Loading
  • baseline results
Module Variant Duration Δ tracing
Agent tracing 1.05 s -
Agent appsec 1.192 s 141.652 ms (13.5%)
Agent iast 1.184 s 133.757 ms (12.7%)
Agent profiling 1.253 s 202.307 ms (19.3%)
Total tracing 10.455 s -
Total appsec 10.696 s 240.798 ms (2.3%)
Total iast 11.131 s 675.317 ms (6.5%)
Total profiling 10.807 s 351.873 ms (3.4%)
  • candidate results
Module Variant Duration Δ tracing
Agent tracing 1.054 s -
Agent appsec 1.188 s 134.655 ms (12.8%)
Agent iast 1.183 s 129.344 ms (12.3%)
Agent profiling 1.255 s 201.339 ms (19.1%)
Total tracing 10.557 s -
Total appsec 10.762 s 205.536 ms (1.9%)
Total iast 10.969 s 412.394 ms (3.9%)
Total profiling 10.81 s 253.06 ms (2.4%)
gantt
    title petclinic - break down per module: candidate=1.46.0-SNAPSHOT~ab3688699d, baseline=1.46.0-SNAPSHOT~1f71dbd1b1

    dateFormat X
    axisFormat %s
section tracing
BytebuddyAgent [baseline] (711.318 ms) : 0, 711318
BytebuddyAgent [candidate] (713.305 ms) : 0, 713305
GlobalTracer [baseline] (254.392 ms) : 0, 254392
GlobalTracer [candidate] (254.95 ms) : 0, 254950
AppSec [baseline] (56.172 ms) : 0, 56172
AppSec [candidate] (56.34 ms) : 0, 56340
Remote Config [baseline] (723.495 µs) : 0, 723
Remote Config [candidate] (739.282 µs) : 0, 739
Telemetry [baseline] (12.778 ms) : 0, 12778
Telemetry [candidate] (13.517 ms) : 0, 13517
section appsec
BytebuddyAgent [baseline] (732.737 ms) : 0, 732737
BytebuddyAgent [candidate] (730.736 ms) : 0, 730736
GlobalTracer [baseline] (254.355 ms) : 0, 254355
GlobalTracer [candidate] (252.856 ms) : 0, 252856
AppSec [baseline] (171.193 ms) : 0, 171193
AppSec [candidate] (171.352 ms) : 0, 171352
IAST [baseline] (19.338 ms) : 0, 19338
IAST [candidate] (19.327 ms) : 0, 19327
Remote Config [baseline] (663.327 µs) : 0, 663
Remote Config [candidate] (666.956 µs) : 0, 667
Telemetry [baseline] (8.235 ms) : 0, 8235
Telemetry [candidate] (8.176 ms) : 0, 8176
section iast
BytebuddyAgent [baseline] (831.478 ms) : 0, 831478
BytebuddyAgent [candidate] (831.734 ms) : 0, 831734
GlobalTracer [baseline] (247.799 ms) : 0, 247799
GlobalTracer [candidate] (246.928 ms) : 0, 246928
AppSec [baseline] (58.613 ms) : 0, 58613
AppSec [candidate] (58.325 ms) : 0, 58325
IAST [baseline] (21.58 ms) : 0, 21580
IAST [candidate] (21.519 ms) : 0, 21519
Remote Config [baseline] (698.995 µs) : 0, 699
Remote Config [candidate] (662.571 µs) : 0, 663
Telemetry [baseline] (8.912 ms) : 0, 8912
Telemetry [candidate] (8.89 ms) : 0, 8890
section profiling
BytebuddyAgent [baseline] (702.431 ms) : 0, 702431
BytebuddyAgent [candidate] (703.616 ms) : 0, 703616
GlobalTracer [baseline] (348.176 ms) : 0, 348176
GlobalTracer [candidate] (350.381 ms) : 0, 350381
AppSec [baseline] (54.889 ms) : 0, 54889
AppSec [candidate] (53.977 ms) : 0, 53977
Remote Config [baseline] (719.302 µs) : 0, 719
Remote Config [candidate] (716.888 µs) : 0, 717
Telemetry [baseline] (8.72 ms) : 0, 8720
Telemetry [candidate] (8.792 ms) : 0, 8792
ProfilingAgent [baseline] (95.764 ms) : 0, 95764
ProfilingAgent [candidate] (95.638 ms) : 0, 95638
Profiling [baseline] (95.788 ms) : 0, 95788
Profiling [candidate] (95.663 ms) : 0, 95663
Loading

Load

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
end_time 2025-01-22T09:12:46 2025-01-22T09:19:51
git_branch master mcculls/span-as-primordial-context
git_commit_date 1737487402 1737536385
git_commit_sha 1f71dbd ab36886
release_version 1.46.0-SNAPSHOT~1f71dbd1b1 1.46.0-SNAPSHOT~ab3688699d
start_time 2025-01-22T09:12:32 2025-01-22T09:19:37
See matching parameters
Baseline Candidate
application insecure-bank insecure-bank
ci_job_date 1737537949 1737537949
ci_job_id 775343538 775343538
ci_pipeline_id 53649858 53649858
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
variant iast iast

Summary

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

Request duration reports for petclinic
gantt
    title petclinic - request duration [CI 0.99] : candidate=1.46.0-SNAPSHOT~ab3688699d, baseline=1.46.0-SNAPSHOT~1f71dbd1b1
    dateFormat X
    axisFormat %s
section baseline
no_agent (1.359 ms) : 1339, 1378
.   : milestone, 1359,
appsec (1.772 ms) : 1748, 1796
.   : milestone, 1772,
appsec_no_iast (1.776 ms) : 1753, 1799
.   : milestone, 1776,
iast (1.527 ms) : 1504, 1551
.   : milestone, 1527,
profiling (1.56 ms) : 1536, 1585
.   : milestone, 1560,
tracing (1.488 ms) : 1462, 1513
.   : milestone, 1488,
section candidate
no_agent (1.355 ms) : 1336, 1374
.   : milestone, 1355,
appsec (1.757 ms) : 1734, 1781
.   : milestone, 1757,
appsec_no_iast (1.751 ms) : 1727, 1774
.   : milestone, 1751,
iast (1.514 ms) : 1490, 1538
.   : milestone, 1514,
profiling (1.518 ms) : 1495, 1541
.   : milestone, 1518,
tracing (1.488 ms) : 1464, 1512
.   : milestone, 1488,
Loading
  • baseline results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 1.359 ms [1.339 ms, 1.378 ms] -
appsec 1.772 ms [1.748 ms, 1.796 ms] 413.269 µs (30.4%)
appsec_no_iast 1.776 ms [1.753 ms, 1.799 ms] 417.364 µs (30.7%)
iast 1.527 ms [1.504 ms, 1.551 ms] 168.594 µs (12.4%)
profiling 1.56 ms [1.536 ms, 1.585 ms] 201.223 µs (14.8%)
tracing 1.488 ms [1.462 ms, 1.513 ms] 128.694 µs (9.5%)
  • candidate results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 1.355 ms [1.336 ms, 1.374 ms] -
appsec 1.757 ms [1.734 ms, 1.781 ms] 402.435 µs (29.7%)
appsec_no_iast 1.751 ms [1.727 ms, 1.774 ms] 395.974 µs (29.2%)
iast 1.514 ms [1.49 ms, 1.538 ms] 159.231 µs (11.8%)
profiling 1.518 ms [1.495 ms, 1.541 ms] 163.548 µs (12.1%)
tracing 1.488 ms [1.464 ms, 1.512 ms] 133.037 µs (9.8%)
Request duration reports for insecure-bank
gantt
    title insecure-bank - request duration [CI 0.99] : candidate=1.46.0-SNAPSHOT~ab3688699d, baseline=1.46.0-SNAPSHOT~1f71dbd1b1
    dateFormat X
    axisFormat %s
section baseline
no_agent (374.806 µs) : 354, 395
.   : milestone, 375,
iast (514.094 µs) : 492, 536
.   : milestone, 514,
iast_FULL (736.859 µs) : 715, 759
.   : milestone, 737,
iast_GLOBAL (565.271 µs) : 542, 589
.   : milestone, 565,
iast_HARDCODED_SECRET_DISABLED (513.997 µs) : 492, 536
.   : milestone, 514,
iast_INACTIVE (457.363 µs) : 436, 478
.   : milestone, 457,
iast_TELEMETRY_OFF (495.005 µs) : 473, 517
.   : milestone, 495,
tracing (453.101 µs) : 432, 474
.   : milestone, 453,
section candidate
no_agent (379.415 µs) : 360, 399
.   : milestone, 379,
iast (508.955 µs) : 487, 531
.   : milestone, 509,
iast_FULL (745.054 µs) : 723, 767
.   : milestone, 745,
iast_GLOBAL (560.85 µs) : 538, 583
.   : milestone, 561,
iast_HARDCODED_SECRET_DISABLED (506.453 µs) : 485, 528
.   : milestone, 506,
iast_INACTIVE (455.94 µs) : 435, 477
.   : milestone, 456,
iast_TELEMETRY_OFF (498.347 µs) : 476, 520
.   : milestone, 498,
tracing (450.964 µs) : 430, 472
.   : milestone, 451,
Loading
  • baseline results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 374.806 µs [354.408 µs, 395.204 µs] -
iast 514.094 µs [492.174 µs, 536.013 µs] 139.288 µs (37.2%)
iast_FULL 736.859 µs [715.045 µs, 758.673 µs] 362.053 µs (96.6%)
iast_GLOBAL 565.271 µs [541.982 µs, 588.56 µs] 190.465 µs (50.8%)
iast_HARDCODED_SECRET_DISABLED 513.997 µs [492.427 µs, 535.567 µs] 139.191 µs (37.1%)
iast_INACTIVE 457.363 µs [436.235 µs, 478.491 µs] 82.557 µs (22.0%)
iast_TELEMETRY_OFF 495.005 µs [473.315 µs, 516.695 µs] 120.199 µs (32.1%)
tracing 453.101 µs [432.019 µs, 474.184 µs] 78.296 µs (20.9%)
  • candidate results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 379.415 µs [359.857 µs, 398.972 µs] -
iast 508.955 µs [487.202 µs, 530.708 µs] 129.54 µs (34.1%)
iast_FULL 745.054 µs [722.821 µs, 767.287 µs] 365.64 µs (96.4%)
iast_GLOBAL 560.85 µs [538.38 µs, 583.321 µs] 181.435 µs (47.8%)
iast_HARDCODED_SECRET_DISABLED 506.453 µs [484.803 µs, 528.103 µs] 127.038 µs (33.5%)
iast_INACTIVE 455.94 µs [434.641 µs, 477.24 µs] 76.526 µs (20.2%)
iast_TELEMETRY_OFF 498.347 µs [476.47 µs, 520.224 µs] 118.932 µs (31.3%)
tracing 450.964 µs [430.239 µs, 471.689 µs] 71.549 µs (18.9%)

Dacapo

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master mcculls/span-as-primordial-context
git_commit_date 1737487402 1737536385
git_commit_sha 1f71dbd ab36886
release_version 1.46.0-SNAPSHOT~1f71dbd1b1 1.46.0-SNAPSHOT~ab3688699d
See matching parameters
Baseline Candidate
application biojava biojava
ci_job_date 1737538447 1737538447
ci_job_id 775343539 775343539
ci_pipeline_id 53649858 53649858
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
variant appsec appsec

Summary

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

Execution time for biojava
gantt
    title biojava - execution time [CI 0.99] : candidate=1.46.0-SNAPSHOT~ab3688699d, baseline=1.46.0-SNAPSHOT~1f71dbd1b1
    dateFormat X
    axisFormat %s
section baseline
no_agent (14.743 s) : 14743000, 14743000
.   : milestone, 14743000,
appsec (14.968 s) : 14968000, 14968000
.   : milestone, 14968000,
iast (18.516 s) : 18516000, 18516000
.   : milestone, 18516000,
iast_GLOBAL (18.068 s) : 18068000, 18068000
.   : milestone, 18068000,
profiling (15.157 s) : 15157000, 15157000
.   : milestone, 15157000,
tracing (14.915 s) : 14915000, 14915000
.   : milestone, 14915000,
section candidate
no_agent (15.275 s) : 15275000, 15275000
.   : milestone, 15275000,
appsec (15.04 s) : 15040000, 15040000
.   : milestone, 15040000,
iast (18.966 s) : 18966000, 18966000
.   : milestone, 18966000,
iast_GLOBAL (18.375 s) : 18375000, 18375000
.   : milestone, 18375000,
profiling (15.748 s) : 15748000, 15748000
.   : milestone, 15748000,
tracing (15.147 s) : 15147000, 15147000
.   : milestone, 15147000,
Loading
  • baseline results
Variant Execution Time [CI 0.99] Δ no_agent
no_agent 14.743 s [14.743 s, 14.743 s] -
appsec 14.968 s [14.968 s, 14.968 s] 225.0 ms (1.5%)
iast 18.516 s [18.516 s, 18.516 s] 3.773 s (25.6%)
iast_GLOBAL 18.068 s [18.068 s, 18.068 s] 3.325 s (22.6%)
profiling 15.157 s [15.157 s, 15.157 s] 414.0 ms (2.8%)
tracing 14.915 s [14.915 s, 14.915 s] 172.0 ms (1.2%)
  • candidate results
Variant Execution Time [CI 0.99] Δ no_agent
no_agent 15.275 s [15.275 s, 15.275 s] -
appsec 15.04 s [15.04 s, 15.04 s] -235.0 ms (-1.5%)
iast 18.966 s [18.966 s, 18.966 s] 3.691 s (24.2%)
iast_GLOBAL 18.375 s [18.375 s, 18.375 s] 3.1 s (20.3%)
profiling 15.748 s [15.748 s, 15.748 s] 473.0 ms (3.1%)
tracing 15.147 s [15.147 s, 15.147 s] -128.0 ms (-0.8%)
Execution time for tomcat
gantt
    title tomcat - execution time [CI 0.99] : candidate=1.46.0-SNAPSHOT~ab3688699d, baseline=1.46.0-SNAPSHOT~1f71dbd1b1
    dateFormat X
    axisFormat %s
section baseline
no_agent (1.469 ms) : 1458, 1481
.   : milestone, 1469,
appsec (2.363 ms) : 2320, 2406
.   : milestone, 2363,
iast (2.104 ms) : 2050, 2158
.   : milestone, 2104,
iast_GLOBAL (2.139 ms) : 2085, 2193
.   : milestone, 2139,
profiling (1.968 ms) : 1925, 2011
.   : milestone, 1968,
tracing (1.936 ms) : 1895, 1978
.   : milestone, 1936,
section candidate
no_agent (1.473 ms) : 1461, 1484
.   : milestone, 1473,
appsec (2.359 ms) : 2316, 2402
.   : milestone, 2359,
iast (2.103 ms) : 2049, 2157
.   : milestone, 2103,
iast_GLOBAL (2.15 ms) : 2095, 2205
.   : milestone, 2150,
profiling (1.984 ms) : 1940, 2028
.   : milestone, 1984,
tracing (1.942 ms) : 1900, 1983
.   : milestone, 1942,
Loading
  • baseline results
Variant Execution Time [CI 0.99] Δ no_agent
no_agent 1.469 ms [1.458 ms, 1.481 ms] -
appsec 2.363 ms [2.32 ms, 2.406 ms] 893.596 µs (60.8%)
iast 2.104 ms [2.05 ms, 2.158 ms] 634.54 µs (43.2%)
iast_GLOBAL 2.139 ms [2.085 ms, 2.193 ms] 669.8 µs (45.6%)
profiling 1.968 ms [1.925 ms, 2.011 ms] 498.748 µs (33.9%)
tracing 1.936 ms [1.895 ms, 1.978 ms] 466.938 µs (31.8%)
  • candidate results
Variant Execution Time [CI 0.99] Δ no_agent
no_agent 1.473 ms [1.461 ms, 1.484 ms] -
appsec 2.359 ms [2.316 ms, 2.402 ms] 886.461 µs (60.2%)
iast 2.103 ms [2.049 ms, 2.157 ms] 630.548 µs (42.8%)
iast_GLOBAL 2.15 ms [2.095 ms, 2.205 ms] 677.131 µs (46.0%)
profiling 1.984 ms [1.94 ms, 2.028 ms] 511.467 µs (34.7%)
tracing 1.942 ms [1.9 ms, 1.983 ms] 469.006 µs (31.8%)

@mcculls mcculls force-pushed the mcculls/span-as-primordial-context branch 3 times, most recently from 732527a to 08762f9 Compare January 20, 2025 13:06
Copy link
Contributor

@PerfectSlayer PerfectSlayer left a comment

Choose a reason for hiding this comment

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

About the Context.with(key1, value1, key2, value2), how is it supposed to be used?
The keys are not supposed to be exposed, and context objects are supposed to be big enough be independent / not related.

For example with span and baggage, I would expect:

  1. to have their keys hidden into the ImplicitContextKeyed implementations
  2. baggage to move out of the span quite soon as part of context improvement / baggage support so there won't be a place with both span and baggage at the same time to create a context in one call.

In general, what would be the benefit of this dedicated method? Avoid the instantiation of a SingletonContext instance from the root context to a two element context? And where should the specific optimized implementation would go?

@mcculls
Copy link
Contributor Author

mcculls commented Jan 20, 2025

About the Context.with(key1, value1, key2, value2), how is it supposed to be used?

It's used by AgentSpan to inflate a simple span to a full context with a span and another key-value.

It lets the tracer supply an optimized route for that code-path which is not possible using with(k1, v1).with(k2, v2) because you can't substitute two methods without having an interim throwaway object.

In general, what would be the benefit of this dedicated method? Avoid the instantiation of a SingletonContext instance from the root context to a two element context? And where should the specific optimized implementation would go?

Yes because that's going to be a heavily used code-path which deserves special attention.

Here's the flow:

  • AgentSpan implementations are now implicit contexts which can have key-values added to them
  • This means they must support the Context.with(key, value) method
  • To keep things loosely-coupled we want to avoid exposing the IndexedContext implementation
  • But we also want to avoid having complete parallel implementations for just scope + context values
  • We also want to try to align contexts created inside a traced service that might start with Context.root() and add spans later - in other words Context.root().with(baggage).with(span) and span.with(baggage) should result in the same content
  • The easiest way to achieve this is with a with(k1, v1, k2, v2) method

This functionality is already covered by with(k1, v1).with(k2, v2) so we're not expanding the functional scope, instead we're providing a way to provide a different implementation for that code path. We default it to the obvious implementation i.e. with(k1, v1).with(k2, v2).

When we write the tracing implementation of ContextManager it will have a special root context and this method means we can avoid an allocation while still keeping things loosely-coupled. It also keeps the basic context implementation consistent.

@mcculls mcculls force-pushed the mcculls/span-as-primordial-context branch 3 times, most recently from edc420a to 2758d2c Compare January 20, 2025 17:27
@mcculls mcculls added the tag: no release notes Changes to exclude from release notes label Jan 20, 2025
Copy link
Contributor

@PerfectSlayer PerfectSlayer left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍 Thanks for the clarification.
It might seems like early optimisations while not all the pieces are present but we can still do benchmark and refine later!

@mcculls mcculls force-pushed the mcculls/span-as-primordial-context branch from 2758d2c to 4dae677 Compare January 21, 2025 18:24
@mcculls mcculls force-pushed the mcculls/span-as-primordial-context branch from 4dae677 to ab36886 Compare January 22, 2025 08:59
@mcculls mcculls added tag: no release notes Changes to exclude from release notes and removed tag: no release notes Changes to exclude from release notes labels Jan 22, 2025
@mcculls mcculls merged commit 3900e56 into master Jan 22, 2025
175 checks passed
@mcculls mcculls deleted the mcculls/span-as-primordial-context branch January 22, 2025 10:27
@github-actions github-actions bot added this to the 1.46.0 milestone Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: core Tracer core tag: no release notes Changes to exclude from release notes type: refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants