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 #3048

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

Conversation

darccio
Copy link
Member

@darccio darccio commented Dec 18, 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

We decided to strategically modify all logging statements, after trying 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 caused 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 review from a team as code owners December 18, 2024 11:42
@datadog-datadog-prod-us1
Copy link

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

Datadog Report

Branch report: dario.castane/go-124-nonconstant-log
Commit report: 02e2646
Test service: dd-trace-go

✅ 0 Failed, 5113 Passed, 70 Skipped, 2m 34.55s Total Time

internal/log/log.go Outdated Show resolved Hide resolved
@pr-commenter
Copy link

pr-commenter bot commented Dec 18, 2024

Benchmarks

Benchmark execution time: 2024-12-19 20:22:44

Comparing candidate commit 17f9128 in PR branch dario.castane/go-124-nonconstant-log with baseline commit 144d592 in branch main.

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

scenario:BenchmarkOTelApiWithCustomTags/datadog_otel_api-24

  • 🟥 execution_time [+148.119ns; +180.681ns] or [+3.131%; +3.819%]

scenario:BenchmarkOTelApiWithCustomTags/otel_api-24

  • 🟥 execution_time [+293.215ns; +341.585ns] or [+4.146%; +4.830%]

@juan-fernandez juan-fernandez requested review from tonyredondo and removed request for juan-fernandez December 19, 2024 13:20
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.

2 participants