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/mocktracer: fix SetUser & WithUserMetadata #2787

Merged
merged 2 commits into from
Jul 15, 2024

Conversation

eliottness
Copy link
Contributor

@eliottness eliottness commented Jul 12, 2024

What does this PR do?

This PR fixes a panic happening when using tracer.SetUser with the option WithUserMetadata on a instance of a mocktracer.

Stacktrace:

panic: assignment to entry in nil map [recovered]
	panic: assignment to entry in nil map

goroutine 5 [running]:
testing.tRunner.func1.2({0x10487e640, 0x104965140})
	/opt/homebrew/Cellar/go/1.22.3/libexec/src/testing/testing.go:1631 +0x1c4
testing.tRunner.func1()
	/opt/homebrew/Cellar/go/1.22.3/libexec/src/testing/testing.go:1634 +0x33c
panic({0x10487e640?, 0x104965140?})
	/opt/homebrew/Cellar/go/1.22.3/libexec/src/runtime/panic.go:770 +0x124
github.com/DataDog/dd-source/domains/aaa/shared/libs/go/authctxhttp.Authenticate.func1.1.WithUserMetadata.4(0x1400008db18?)
	/Users/kaitlyn.paglia/go/pkg/mod/gopkg.in/!data!dog/dd-trace-go.v1@v1.66.0-rc.1/ddtrace/tracer/option.go:1326 +0x40
gopkg.in/DataDog/dd-trace-go.v1/ddtrace/mocktracer.(*mockspan).SetUser(0x104de8fb0?, {0x14000354154, 0x4}, {0x1400007c2e0, 0x3, 0x14000358000?})
	/Users/kaitlyn.paglia/go/pkg/mod/gopkg.in/!data!dog/dd-trace-go.v1@v1.66.0-rc.1/ddtrace/mocktracer/mockspan.go:251 +0x70
gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer.SetUser({0x104971c98?, 0x14000358000?}, {0x14000354154?, 0x4?}, {0x1400007c2e0?, 0x3?, 0x4?})
	/Users/kaitlyn.paglia/go/pkg/mod/gopkg.in/!data!dog/dd-trace-go.v1@v1.66.0-rc.1/ddtrace/tracer/tracer.go:224 +0x7c
gopkg.in/DataDog/dd-trace-go.v1/appsec.SetUser({0x10496f0c8, 0x1400035d050}, {0x14000354154, 0x4}, {0x1400007c2e0, 0x3, 0x4})
	/Users/kaitlyn.paglia/go/pkg/mod/gopkg.in/!data!dog/dd-trace-go.v1@v1.66.0-rc.1/appsec/appsec.go:58 +0x54
github.com/DataDog/dd-source/domains/aaa/shared/libs/go/authctxhttp.Authenticate.func1.1({0x10496d6c8, 0x14000346040}, 0x14000422120)
	/Users/kaitlyn.paglia/go/src/github.com/DataDog/dd-source/domains/aaa/shared/libs/go/authctxhttp/authctxhttp.go:337 +0xc18
net/http.HandlerFunc.ServeHTTP(0x104967bd8?, {0x10496d6c8?, 0x14000346040?}, 0x1046c8f17?)
	/opt/homebrew/Cellar/go/1.22.3/libexec/src/net/http/server.go:2166 +0x38
github.com/DataDog/dd-source/domains/aaa/shared/libs/go/authctxhttp.TestAppSecBlocking(0x14000111ba0)
	/Users/kaitlyn.paglia/go/src/github.com/DataDog/dd-source/domains/aaa/shared/libs/go/authctxhttp/authctxhttp_test.go:290 +0x3a4
testing.tRunner(0x14000111ba0, 0x104961ec0)
	/opt/homebrew/Cellar/go/1.22.3/libexec/src/testing/testing.go:1689 +0xec
created by testing.(*T).Run in goroutine 1
	/opt/homebrew/Cellar/go/1.22.3/libexec/src/testing/testing.go:1742 +0x318
FAIL	github.com/DataDog/dd-source/domains/aaa/shared/libs/go/authctxhttp	0.642s
FAIL

Motivation

Happened in dd-source on a rapid service testing appsec.SetUser

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!

Signed-off-by: Eliott Bouhana <eliott.bouhana@datadoghq.com>
@eliottness eliottness requested a review from a team as a code owner July 12, 2024 20:41
@pr-commenter
Copy link

pr-commenter bot commented Jul 12, 2024

Benchmarks

Benchmark execution time: 2024-07-15 08:16:42

Comparing candidate commit 75c34ed in PR branch eliott.bouhana/mockspan-set-user with baseline commit a87c895 in branch main.

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

@eliottness eliottness added bug unintended behavior that has to be fixed apm:core labels Jul 13, 2024
@eliottness eliottness merged commit a6b9cd6 into main Jul 15, 2024
164 checks passed
@eliottness eliottness deleted the eliott.bouhana/mockspan-set-user branch July 15, 2024 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:core bug unintended behavior that has to be fixed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants