Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/mixpanel-ruby/flags/flags_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ def track_exposure_event(flag_key, selected_variant, context, latency_ms = nil)
distinct_id = context['distinct_id'] || context[:distinct_id]

unless distinct_id
# Local eval succeeds when the flag's Variant Assignment Key is
# something other than distinct_id (e.g., device_id), but the
# exposure event still needs distinct_id to attribute the user.
# Surface the drop instead of silently returning so callers can
# see they need to include distinct_id in the context.
@error_handler&.handle(MixpanelError.new(
"Cannot track exposure event for flag '#{flag_key}' without a distinct_id in the context"
))
return
end

Expand Down
23 changes: 23 additions & 0 deletions spec/mixpanel-ruby/flags/local_flags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,29 @@ def user_context_with_properties(properties)

provider.send(:track_exposure_event, 'test_flag', variant, test_context)
end

# SDK-84: when local eval succeeds via a non-distinct_id Variant Assignment
# Key but the context lacks distinct_id, the exposure can't fire. Surface
# via error_handler instead of silently returning.
it 'reports through error_handler when distinct_id is missing' do
variant = Mixpanel::Flags::SelectedVariant.new(
variant_key: 'treatment', variant_value: 'treatment'
)

expect(mock_tracker).not_to receive(:call)
expect(mock_error_handler).to receive(:handle) do |err|
expect(err).to be_a(Mixpanel::MixpanelError)
expect(err.message).to include('test_flag')
expect(err.message).to include('distinct_id')
end

provider.send(
:track_exposure_event,
'test_flag',
variant,
{ 'device_id' => 'abc-123' }
)
end
end

describe 'polling' do
Expand Down
Loading