Repository navigation
Conversation
IdentifyUpdate's own doc comment promises the update is "sent immediately, rather than the next time you start up Analytics" - but it only enqueued the Identify call via UpdateServerInformationOnThisUser, same as Track, relying on the client's normal batching (flushAt/ flushInterval) to eventually deliver it. In practice that meant a mid- session IdentifyUpdate call (e.g. after a UI language change) didn't actually show up until the next batch flush or app shutdown (SayMore's Program.cs explicitly flushes at shutdown) - confirmed by manual testing: the companion Track event for the same user action appeared in Mixpanel right away, but the Identify-based profile trait only updated after closing and relaunching the app. Fixed by calling the existing FlushClient() right after enqueueing, so IdentifyUpdate actually honors its own contract. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
IdentifyUpdate is static and can be called before any Analytics object
exists (s_singleton null) or after one has been disposed. Previously
this would NRE on s_singleton.UpdateServerInformationOnThisUser() -
and now, with the FlushClient() call just added, would NRE there too
if it somehow got past that.
- Not yet constructed: throw ApplicationException, matching the exact
precedent already used for the same situation in
TrackWithApplicationProperties ("The application must first
construct a single Analytics object"). This is a caller/wiring
error, not a runtime condition - better to fail loudly so it's
caught during development than to silently drop every analytics
call for an app that never got directly construction right.
- Disposed: no-op. By that point in the app's lifecycle, nothing
can meaningfully be updated, and this can legitimately happen from
a timing race during shutdown rather than a caller mistake -
failing silently is safer than risking a crash there.
The disposed branch isn't covered by a new unit test: constructing a
real Analytics object (even with allowTracking:false, which skips all
other side effects) would permanently set the process-wide static
singleton for the rest of the test run, breaking every other test's
"no Analytics ever constructed" assumption. This is the same boundary
the existing (and also untested) s_singleton==null guard in
TrackWithApplicationProperties already lives with.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
s_disposed was static state standing in for a per-instance property. Since the class is currently a hard singleton, this made no practical difference - but disposed-ness is correctly a property of the specific object being disposed, not the type. Moving it to an instance field (_disposed, checked via s_singleton._disposed) costs nothing now and means the flag would already be on the right object if the "only one instance ever" restriction is ever relaxed. Required reordering IdentifyUpdate's checks: null-userInfo -> singleton- not-constructed (throw) -> singleton-disposed (no-op), since checking disposed-ness now requires an instance to check it on. Not a behavior change - _disposed can only ever be set inside the instance method Dispose(), which requires s_singleton to already be non-null and it's never nulled out afterward, so there's no reachable state where the old ordering and the new one would actually differ. All 32 tests still pass unchanged, confirming it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Devin review on PR #46: if Analytics was constructed with allowTracking:false (or later disabled), SegmentClient's internal _analytics is never initialized (Initialize() never ran). The unconditional FlushClient() added to IdentifyUpdate called SegmentClient.Flush(), which dereferences _analytics without a null check (unlike ShutDown(), which uses ?.) - a real, reachable NRE any time a caller calls IdentifyUpdate while tracking is off, since UpdateServerInformationOnThisUser() itself already no-ops safely in that case but the Flush call right after it did not. Fix: only flush when AllowTracking is true, matching the same gate UpdateServerInformationOnThisUser() already uses for the identical reason. Not independently unit tested, for the same structural reason the other singleton-dependent branches aren't - constructing even a side-effect-free Analytics instance to reach this path would permanently set the static singleton for the rest of the test run. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Other Devin flagged this:
|
Unfortuately, as written (with the use of statics and a session-lifetime singleton), there are some things that are impossible to test in this library. |
imnasnainaec
left a comment
There was a problem hiding this comment.
@imnasnainaec reviewed 2 files and all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on tombogle).
Also, tighten up contract for when it is legal to call
IdentifyUpdate. Previous comments implied it could be called before calling the constructor (to create the singleton), but that never worked. Now the comments make that clear and also define that it is a no-op if the singleton has already been disposed.This change is