Skip to content

fix: Prevent the C API from swapping track data and metric values - #639

Merged
kinyoklion merged 1 commit into
mainfrom
rlamb/c-api-track-metric-order
Nov 4, 2026
Merged

kinyoklion merged 1 commit into
mainfrom
rlamb/c-api-track-metric-order

Conversation

@kinyoklion

@kinyoklion kinyoklion commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Summary

LDServerSDK_TrackMetric and LDClientSDK_TrackMetric passed the metric value and the data to Track in the wrong order. The implicit conversions between Value and double let the call compile, so the event carried the metric value as its data, and the data converted to a number (usually 0) as its metric value. This affects every caller of these two C functions, including the Lua server-side SDK. The C++ API and LDServerSDK_TrackMetric_WithHookContext already pass the values in the right order.

Tested with new server and client C binding tests, which fail before this change and pass after it. The full server and client unit test suites pass.

Opened from termag


Note

Overview
LDClientSDK_TrackMetric and LDServerSDK_TrackMetric were forwarding arguments to the underlying Track call in the wrong order, so the numeric metric was stored as event data and the LDValue payload was treated as the metric (often becoming 0 via implicit conversion). The C bindings now match the C++ API and the existing LDServerSDK_TrackMetric_WithHookContext path: data first, then metric_value.

Regression coverage adds a client test that subclasses Client to assert the received data and metric, and a server hook test that reads LDTrackSeriesContext_Data and LDTrackSeriesContext_MetricValue after LDServerSDK_TrackMetric.

Reviewed by Cursor Bugbot for commit f9f68b6. Bugbot is set up for automated code reviews on this repo. Configure here.

@kinyoklion
kinyoklion marked this pull request as ready for review November 4, 2026 22:09
@kinyoklion
kinyoklion requested a review from a team as a code owner November 4, 2026 22:09
@kinyoklion
kinyoklion merged commit b363019 into main Nov 4, 2026
55 checks passed
@kinyoklion
kinyoklion deleted the rlamb/c-api-track-metric-order branch November 4, 2026 22:27
@github-actions github-actions Bot mentioned this pull request Nov 3, 2026
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