Repository navigation
SDK development guide fixes - #169
Merged
Merged
Conversation
Brings the C++ SDK in line with the updated SDK development guide: crash and data-loss fixes, wrong behaviours and small missing features. Crashes and data loss: start() without a device ID no longer throws (a UUID is generated, SQLite builds store it); views() and crash() before start() are safe; a throwing log listener is contained; SBS segmentation filters no longer strip the SDK's own view data; st=false no longer blocks for 15 s and deletes waiting events; only a 2xx JSON answer with "result" counts as delivered; invalid event counts, empty keys, device IDs and app keys are refused; stop() sends waiting events and ends the session; crash reports carry the OS and app version; limits below their minimum are ignored. Behaviour: every request is POST; start() refuses invalid server URLs and app keys; events are sent on the session update timer; session calls work only with manual session control; remote config uses method=rc and enrolls in A/B tests only on request; a stored device ID wins at start() unless enableClearStoredDeviceID() is called; SBS, views, crashes and location follow the guide. Added: getDeviceID, getDeviceIDType, enableClearStoredDeviceID, t/av/rr on every request, OS metrics, event IDs, failed request cool-down, request drop age, backoff, gradual queue trimming, crash filter and crash segmentation, clearBreadcrumbs, stopAllViews, disableLocation, enrollABOnRCDownload. Build: CMAKE_CXX_STANDARD is honoured, with C++14 as the default and the minimum, so the cpp17 and cpp20 CI jobs compile at C++17 and C++20. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Wc7z4S3SpREqhYT28iCtkY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Brings the C++ SDK in line with the updated SDK Development Guide. It fixes the crash and data-loss problems a review against the guide found (each reproduced before the fix), corrects behaviour that differs from the guide, and adds the small missing pieces the guide requires. It also makes the
cpp17andcpp20CI jobs compile at the standard they name.The
XX.XX.XXsection ofCHANGELOG.mdlists every change.Breaking changes (the "Minor breaking change" lines)
usePosttrue for every request and must support POST;alwaysUsePostis deprecated and has no effect.start()refuses a server URL withouthttp://orhttps://or without a host, an empty app key andYOUR_APP_KEY: it logs an error and the SDK stays off.flushEvents()sends them right away.beginSession,updateSessionandendSessionwork only withenableManualSessionControl(). A manualupdateSession()always reports the duration.method=rcand no longer enroll the user in A/B tests (enrollABOnRCDownload()turns it back on). Automatic downloads run at the end ofstart(), after a device ID change and when consent is given.setLocationdrops values that don't fit their form.start(): a different device ID given withsetDeviceIDbeforestart()is ignored with a warning.enableClearStoredDeviceID()beforestart()uses the given one instead.The consent ("cr") breaking line in the same section comes from #168.
Crashes and data loss fixed (each reproduced first)
start()without a device ID threw. The SDK now generates a UUID (type 1), and SQLite builds store it.views()orcrash()beforestart()dereferenced null. They are usable now; calls are ignored with a warning.[CLY]_viewsegmentation, so views were missing from the dashboard. Internal events are no longer filtered.st=false,setUserDetailsand a device ID change blocked for 15 s and then deleted the waiting events, and a running session never ended.result.stop()lostend_sessionand the waiting events. They are now queued before the update thread stops.start()without its fourth argument never updated sessions and held events until 100 were waiting. The update loop always runs now._osand_app_versionwere dropped by the server. They are filled from the metrics; a crash without a stack trace is ignored.Other guide alignment
t,avandrron every request, failed request cool-down (setFailedRequestCooldown, 60 s), drop by age (setRequestDropAgeHours, SBSdort), backoff (disableBackoffMechanism, SBSbom*), gradual queue trimming (disableGradualRequestCleaner).id,cvid,pvid,peid), validation with log codes, filters and limits applied to custom events and unknown[CLY]_keys, timed events recorded at their end, event queue capped at 1000.segment, first view per session, reserved keys protected,closeViewWithNamecloses the last started view,stopAllViews().{v,t,c}or the inner object and are not persisted, no fetch at all when updates are disabled, fetch after a device ID change (with merge: after the merge request is delivered).setCrashFilterCallbackwith_ob,setCustomCrashSegmentation,crash().clearBreadcrumbs(),_cvid.start()applied,disableLocation(), an erase at the end of init when location is off._osand_os_version;setMetricsvalues still win.Device ID at start
Follows the guide's "Device ID State Management During Init": a stored device ID wins; otherwise the given one is used; otherwise a UUID is generated. With
enableClearStoredDeviceID(), events the stored user left in the database are first queued under the stored device ID, then the given or a new device ID is used and stored. Called afterstart(), it is ignored with a warning.CI: C++ standard
Every target pinned
CXX_STANDARD 14, which overrides-DCMAKE_CXX_STANDARD, so thecpp17andcpp20jobs compiled at C++14. NowCMAKE_CXX_STANDARDdefaults to 14 only when it is unset, andtarget_compile_features(... PRIVATE cxx_std_14)keeps C++14 as the minimum: a parent project on C++11 still builds the SDK as C++14, and consumers get no new requirement. Checked flags: unset gives c++14, 11 gives c++14, 17 gives c++17, 20 gives c++20 (CMake 3.16 and 3.29 with GCC; MSVCstdcpp14andstdcpp20). Conan builds now use the profile'scppstd.The first real C++17 and C++20 runs crashed in the test suite:
tests/mutex_exception_safety.cppshared a plain static pointer between the test thread and its log callback, which the always-running update loop calls from its own thread. The pointer is now atomic and read once per call.Decisions for review
updateSession()always sends the duration, also sooner than the update interval.endSession()while SBS turned session tracking off and no session runs returnsfalsewith a debug log, without w760.setSDKBehaviorSettingsaccepts both the full server answer ({v,t,c}) and its innercobject.start(), after a device ID change and when consent is given, not at session start.Tests
init,request_pipeline,event_recording,session_lifecycle,behavior_settings,remote_config,crash_reporting,location. Each fix's test failed on the old code first.tparameter, the cool-down,method=rc, session calls in automatic mode, events queued before a session ends, provided SBS not stored, the viewsegmentkey.Verification (local)
On the PR head:
initandmutex_exception_safetytestsEarlier in the work, before the last test-only change (the race fix above):
Earlier still, before the device ID rule and the CMake change: UBSAN 173/173, static custom-HTTP build 172/172, full ASAN 172/173 (the failing test asserted an asynchronous fetch's position; fixed, then passed 5 times in a row under ASAN).
Not run: a real Countly server, macOS, clang, the system nlohmann_json flavour (WSL has 3.7.3, the SDK needs 3.11 or newer), TSAN, the Qt demo.
clang-formatwas not run (not installed).Left for later
Remote config callbacks, cache and A/B APIs, offline mode, user profile modifiers and
save(), view pause and resume, manual feedback widgets, queue operations, custom headers and certificate pinning. The help-center C++ docs need the breaking changes and the new APIs.🤖 Generated with Claude Code
https://claude.ai/code/session_01Wc7z4S3SpREqhYT28iCtkY