Skip to content

feat(ddtrace): implement version detection for dd-trace-go v1 non-transitional#3381

Merged
darccio merged 2 commits into
mainfrom
dario.castane/v1-mix-warning
Apr 10, 2025
Merged

feat(ddtrace): implement version detection for dd-trace-go v1 non-transitional#3381
darccio merged 2 commits into
mainfrom
dario.castane/v1-mix-warning

Conversation

@darccio

@darccio darccio commented Apr 4, 2025

Copy link
Copy Markdown
Member

What does this PR do?

Adds v1 non-transitional versions of dd-trace-go present in the compiled binary.

It also sets the v1 transitional version as the tag version so logging for services instrumented with v1.74.0 and higher show a v1 version, following the principle of least surprise.

Motivation

v1.73.0 and below are not compatible with v2. They can't coexist.

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 April 4, 2025 15:26
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Apr 4, 2025

Copy link
Copy Markdown

Datadog Report

Branch report: dario.castane/v1-mix-warning
Commit report: e0e5caf
Test service: dd-trace-go

✅ 0 Failed, 4475 Passed, 64 Skipped, 3m 40.55s Total Time

Comment thread ddtrace/v1.go Outdated
Comment thread ddtrace/v1.go Outdated
Comment thread internal/version/version.go Outdated
minor, _ := strconv.Atoi(captures["mi"])
patch, _ := strconv.Atoi(captures["pa"])
rc, _ := strconv.Atoi(captures["rc"])
return major, minor, patch, rc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this an unrelated refactoring? Or was the plan to use parseVersion in v1.go? If yes, why didn't this pan out?

@darccio darccio Apr 6, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@felixge I pushed and left behind a change I wanted to introduce to replace the Tag with the v1 transitional version, so logs show the version that users can see in their go.mod as direct dependency (to avoid confusions).

You can see the change at 31564a3.

I'm also wondering if it's the right time to replace this ad hoc code with semver instead. WDYT?

Update: I woke up with an idea about how to refactor it so we check debuginfo once, and also warn on tracer's start: 59b5ceb

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@felixge I rebased this against main. Please, can you review it again? Thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 for using semver

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@kakkoyun PR is going to have lots of changed go.mod files due to adding a new dependency 😁 But worth it, it looks cleaner.

@pr-commenter

pr-commenter Bot commented Apr 4, 2025

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2025-04-10 08:47:54

Comparing candidate commit ef705e9 in PR branch dario.castane/v1-mix-warning with baseline commit 3d0fb01 in branch main.

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

Comment thread internal/version/version_test.go
@darccio darccio changed the base branch from v2-dev to main April 7, 2025 09:54
@darccio darccio requested review from a team as code owners April 7, 2025 09:54
@darccio darccio requested a review from juan-fernandez April 7, 2025 09:54
@darccio darccio changed the base branch from main to v2-dev April 7, 2025 09:55
@darccio darccio force-pushed the dario.castane/v1-mix-warning branch from 5b36869 to 63b79ab Compare April 8, 2025 13:08
@darccio darccio changed the base branch from v2-dev to main April 8, 2025 13:09
Comment thread internal/version/version.go Outdated
Comment thread internal/version/version.go Outdated
minor, _ := strconv.Atoi(captures["mi"])
patch, _ := strconv.Atoi(captures["pa"])
rc, _ := strconv.Atoi(captures["rc"])
return major, minor, patch, rc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 for using semver

Comment thread internal/version/version.go Outdated

func parseVersion(version string) (int, int, int, int) {
var (
v = semver.MustParse(version)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I decided to go with MustParse because this shouldn't fail ever. I consider this a canary.

@rarguelloF rarguelloF left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm, left a refactor suggestion

Comment thread internal/version/version.go Outdated

@tonyredondo tonyredondo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@darccio

darccio commented Apr 9, 2025

Copy link
Copy Markdown
Member Author

Nice:

image

The go.mod:

module go-http-puppy

go 1.23.0

require (
	github.com/DataDog/dd-trace-go/v2 v2.0.0-20250409103927-ac517a28737c
	gopkg.in/DataDog/dd-trace-go.v1 v1.72.2
)

require (
	// [...] snip
)

@darccio darccio force-pushed the dario.castane/v1-mix-warning branch 5 times, most recently from a1c8934 to 757ae2d Compare April 10, 2025 08:14
…nsitional

Co-authored-by: Kemal Akkoyun <kakkoyun@users.noreply.github.com>
@darccio darccio force-pushed the dario.castane/v1-mix-warning branch from 757ae2d to ef705e9 Compare April 10, 2025 08:19
@darccio darccio enabled auto-merge (squash) April 10, 2025 16:36
@darccio darccio merged commit e137aa6 into main Apr 10, 2025
@darccio darccio deleted the dario.castane/v1-mix-warning branch April 10, 2025 16:53
@darccio darccio added the v2.0 label Jun 2, 2025
sameerank added a commit to DataDog/dd-trace-dotnet that referenced this pull request May 8, 2026
## Summary of changes

Adds flag evaluation metrics support to the Datadog OpenFeature
provider. When a feature flag is evaluated, a counter metric is emitted
with relevant attributes.

## Reason for change

Part of the Feature Flags Evaluation (FFE) initiative to provide
visibility into flag evaluations across all Datadog server SDKs. This
brings parity with implementations in dd-trace-py and dd-trace-go.

## Implementation details

- **FlagEvalMetrics.cs**: Core metrics recording class using
`System.Diagnostics.Metrics`
  - Meter name: `Datadog.FeatureFlags.OpenFeature`
  - Metric: `feature_flag.evaluations` (Counter<long>)
  - Unit: `{evaluation}`
- Tags: `feature_flag.key`, `feature_flag.result.variant`,
`feature_flag.result.reason`, `error.type` (optional),
`feature_flag.result.allocation_key` (optional)

- **FlagEvalMetricsHook.cs**: OpenFeature hook that implements
`FinallyAsync` to record metrics after each evaluation completes
  - Converts reason to lowercase for consistency
  - Maps `ErrorType` enum to snake_case strings
  - Extracts allocation key from flag metadata when present

- **DatadogProvider.cs**: Registers the metrics hook with the
OpenFeature API

- Updated OpenFeature SDK dependency from 2.0.0 to 2.3.0

- **Package version bumped to 2.3.0** to match OpenFeature SDK
dependency version. This signals the breaking changes from OpenFeature
2.3.0:
  - .NET 6 support dropped (now requires .NET 8+)
  - Hook `finally` signature changed to include evaluation details

**Conditional compilation**: Only enabled for .NET 6+ (`#if
NET6_0_OR_GREATER`) since `System.Diagnostics.Metrics` requires .NET 6+.

## Test coverage

- Feature is validated through system-tests
(`tests/ffe/test_flag_eval_metrics.py`)
- Also checked in DataDog/ffe-dogfooding#56
- Unit tests were explored but deferred due to type conflicts between
shared source files in `Datadog.FeatureFlags.OpenFeature` and
`Datadog.Trace` assemblies

## Other details

Jira: https://datadoghq.atlassian.net/browse/FFL-1946

Related PRs:
- dd-trace-py: DataDog/dd-trace-py#17029
- dd-trace-go: DataDog/dd-trace-go#3381
- system-tests: DataDog/system-tests#6689

---------

Co-authored-by: Andrew Lock <andrew.lock@datadoghq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants