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

ddtrace/tracer: add NewStartSpanConfig & WithStartSpanConfig API #2341

Merged
merged 14 commits into from Nov 20, 2023

Conversation

darccio
Copy link
Contributor

@darccio darccio commented Nov 10, 2023

What does this PR do?

Adds NewStartSpanConfig and WithStartSpanConfig functions to allow to use config structs.

Motivation

This API reduces the number of calls (in functional option form) in hot paths by giving the freedom to prepare a common span configuration in hot paths.

Microbenchmarks show that there are significant improvements:

Just running the functional options

❯ benchstat -col /scenario /tmp/with_config.txt
goos: darwin
goarch: arm64
pkg: github.com/DataDog/dd-trace-go/v2/ddtrace/tracer
          │     none     │         WithStartSpanConfig         │
          │    sec/op    │   sec/op     vs base                │
Config-10   169.65n ± 1%   70.17n ± 5%  -58.64% (p=0.000 n=10)

          │    none    │        WithStartSpanConfig         │
          │    B/op    │    B/op     vs base                │
Config-10   448.0 ± 0%   160.0 ± 0%  -64.29% (p=0.000 n=10)

          │    none    │        WithStartSpanConfig         │
          │ allocs/op  │ allocs/op   vs base                │
Config-10   5.000 ± 0%   2.000 ± 0%  -60.00% (p=0.000 n=10)

Creating spans (more realistic)

❯ benchstat -col /scenario /tmp/start_span.txt
goos: darwin
goarch: arm64
pkg: github.com/DataDog/dd-trace-go/v2/ddtrace/tracer
                   │    none     │        WithStartSpanConfig         │
                   │   sec/op    │   sec/op     vs base               │
StartSpanConfig-10   1.387µ ± 1%   1.327µ ± 2%  -4.36% (p=0.000 n=10)

                   │     none     │         WithStartSpanConfig          │
                   │     B/op     │     B/op      vs base                │
StartSpanConfig-10   2.390Ki ± 0%   2.108Ki ± 0%  -11.77% (p=0.000 n=10)

                   │    none    │        WithStartSpanConfig         │
                   │ allocs/op  │ allocs/op   vs base                │
StartSpanConfig-10   25.00 ± 0%   22.00 ± 0%  -12.00% (p=0.000 n=10)

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.

For Datadog employees:

  • If this PR touches code that handles credentials of any kind, such as Datadog API keys, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

@pr-commenter
Copy link

pr-commenter bot commented Nov 10, 2023

Benchmarks

Benchmark execution time: 2023-11-20 14:12:31

Comparing candidate commit bbbe437 in PR branch dario.castane/AIT-8738/new-span-config with baseline commit 54feb34 in branch v2-dev.

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

@darccio darccio marked this pull request as ready for review November 10, 2023 16:18
@darccio darccio requested a review from a team November 10, 2023 16:18
@darccio darccio requested review from a team as code owners November 13, 2023 10:16
Copy link
Contributor

@ahmed-mez ahmed-mez 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! Just added a few non-blocking comments.

ddtrace/tracer/option.go Outdated Show resolved Hide resolved
ddtrace/tracer/option.go Outdated Show resolved Hide resolved
ddtrace/ddtrace.go Outdated Show resolved Hide resolved
ddtrace/ddtrace.go Show resolved Hide resolved
ddtrace/tracer/option.go Show resolved Hide resolved
darccio and others added 2 commits November 20, 2023 14:54
Co-authored-by: Ahmed Mezghani <38987709+ahmed-mez@users.noreply.github.com>
Co-authored-by: Ahmed Mezghani <38987709+ahmed-mez@users.noreply.github.com>
@darccio darccio changed the title ddtrace/tracer: add NewStartSpanConfig & WithConfig API ddtrace/tracer: add NewStartSpanConfig & WithStartSpanConfig API Nov 20, 2023
@darccio darccio merged commit 0fa8d63 into v2-dev Nov 20, 2023
49 checks passed
@darccio darccio deleted the dario.castane/AIT-8738/new-span-config branch November 20, 2023 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants