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

fix(ddtrace/tracer): avoid tests to fail with error "non-constant format string" from upcoming Go 1.24 release #3002

Closed
wants to merge 0 commits into from

Conversation

darccio
Copy link
Member

@darccio darccio commented Dec 2, 2024

What does this PR do?

Upcoming Go 1.24 release introduces a new go vet check (golang/go#60529) for printf calls with non-const format and no args. This causes go test to fail to run in gotip:

❯ gotip test gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer
# gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer
# [gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer]
ddtrace/tracer/abandonedspans.go:276:11: non-constant format string in call to gopkg.in/DataDog/dd-trace-go.v1/internal/log.Warn
ddtrace/tracer/otel_dd_mappings.go:101:14: non-constant format string in call to gopkg.in/DataDog/dd-trace-go.v1/internal/log.Warn
ddtrace/tracer/slog.go:44:13: non-constant format string in call to gopkg.in/DataDog/dd-trace-go.v1/internal/log.Debug
ddtrace/tracer/slog.go:46:12: non-constant format string in call to gopkg.in/DataDog/dd-trace-go.v1/internal/log.Info
ddtrace/tracer/slog.go:48:12: non-constant format string in call to gopkg.in/DataDog/dd-trace-go.v1/internal/log.Warn
ddtrace/tracer/slog.go:50:13: non-constant format string in call to gopkg.in/DataDog/dd-trace-go.v1/internal/log.Error
ddtrace/tracer/option_test.go:341:13: non-constant format string in call to (*testing.common).Fatalf
FAIL    gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer [build failed]
FAIL

The adopted approach was refactoring internal/log API to offer:

  • Debug, Info, Warn, Error functions for logging a string without arguments
  • Debugf, Infof, Warnf, Errorf function for logging formatted messages with arguments

This causes a significant amount of changes across the repository, but we want to keep the API as coherent as possible. It mirrors stdlib's log API.

Motivation

Avoid unintended consequences from upcoming Go 1.24 release.

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.
  • For internal contributors, a matching PR should be created to the v2-dev branch and reviewed by @DataDog/apm-go.

Unsure? Have a question? Request a review!

@darccio darccio requested a review from a team as a code owner December 2, 2024 16:31
@darccio darccio requested a review from mtoffl01 December 2, 2024 16:32
@pr-commenter
Copy link

pr-commenter bot commented Dec 2, 2024

Benchmarks

Benchmark execution time: 2024-12-17 13:53:50

Comparing candidate commit 52af2e8 in PR branch dario.castane/go-124-errors with baseline commit cd21985 in branch main.

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

Copy link
Contributor

@hannahkm hannahkm left a comment

Choose a reason for hiding this comment

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

Could we check for the same issues in other directories (other than ddtrace/tracer)? Running gotip locally gives similar failures in our ddtrace/opentelemetry and internal/appsec, for example.

@darccio
Copy link
Member Author

darccio commented Dec 9, 2024

@hannahkm I think we'll have to apply a different approach, because our Error function kind of expects that the first string argument is usually constant:

image

@darccio darccio requested a review from a team as a code owner December 9, 2024 13:30
@darccio darccio marked this pull request as draft December 16, 2024 09:38
@github-actions github-actions bot added the apm:ecosystem contrib/* related feature requests or bugs label Dec 17, 2024
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Dec 17, 2024

Datadog Report

Branch report: dario.castane/go-124-errors
Commit report: e95f6c7
Test service: dd-trace-go

✅ 0 Failed, 5112 Passed, 70 Skipped, 2m 55.25s Total Time

@darccio darccio marked this pull request as ready for review December 17, 2024 13:11
@darccio darccio requested review from a team as code owners December 17, 2024 13:11
@darccio darccio requested a review from anmarchenko December 17, 2024 13:11
@darccio darccio closed this Dec 18, 2024
@darccio darccio force-pushed the dario.castane/go-124-errors branch from 52af2e8 to d15e61a Compare December 18, 2024 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:ecosystem contrib/* related feature requests or bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants