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: Ensure SpanLink access is safe from corruption #2975

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mtoffl01
Copy link
Contributor

What does this PR do?

  • Changes the (spanContext).SpanLinks() implementation to return a copy of a slice instead of the slice itself
  • Removes (spanContext).SetLinks() method
  • nit: Clean up a test

Motivation

Ensure users cannot modify spanContext

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • 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.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.

Unsure? Have a question? Request a review!

assert.True(t, ok)
assert.Equal(t, len(ctxLink.SpanLinks()), 1)
assert.Equal(t, ctxLink.SpanLinks()[0], spanLink)
var _ ddtrace.SpanContextWithLinks = ctx
Copy link
Contributor

Choose a reason for hiding this comment

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

Should an assertion be made here to make sure that the casting doesn't fail? Otherwise what is the point of this declaration? 🤔

Copy link
Contributor Author

@mtoffl01 mtoffl01 Nov 11, 2024

Choose a reason for hiding this comment

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

The code won't compile if this fails; this is a common code pattern for "checking that a concrete type fulfills an interface" in Go.
https://dev.to/kittipat1413/checking-if-a-type-satisfies-an-interface-in-go-432n#:~:text=In%20Go%2C%20to%20check%20if,now%2C%20not%20at%20runtime.%E2%80%9D

@pr-commenter
Copy link

pr-commenter bot commented Nov 11, 2024

Benchmarks

Benchmark execution time: 2024-11-11 16:47:59

Comparing candidate commit bf2289d in PR branch mtoff/safeguard-spanlinks with baseline commit 16269d5 in branch main.

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

@mtoffl01 mtoffl01 marked this pull request as ready for review November 11, 2024 20:36
@mtoffl01 mtoffl01 requested a review from a team as a code owner November 11, 2024 20:36
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.

3 participants