launchdarkly / ruby-server-sdk

LaunchDarkly Server-side SDK for Ruby
https://docs.launchdarkly.com/sdk/server-side/ruby
Other
34 stars 52 forks source link

Custom attributes ignored in create_legacy_context #212

Closed Hugo-Hache closed 1 year ago

Hugo-Hache commented 1 year ago

I was having issues pushing custom attributes with legacy format of context. By browsing the source code I found this line that ignores attributes other than :ip, :email, :avatar, :firstName, :lastName, :country.

I'm not sure to understand what "dedicated instance variables" mentions this comment, and so how would the custom attributes would make it to the context sent to the server.

In case other people are facing the same issue, migrating to the new format and putting custom attributes at the root fixed it for me:

client.identify({key: 'key', custom: { customAttribute: 'value' }}) # didn't work

client.identify(LaunchDarkly::LDContext.create({kind: 'user', key: 'key', customAttribute: 'value' })) # works
keelerm84 commented 1 year ago

Hi :wave:!

How are you determining that the custom attributes don't work? Are you evaluating a flag that isn't giving you the expected results? Are the custom attributes not showing up in the LaunchDarkly UI?

I'm not sure to understand what "dedicated instance variables" mentions this comment, and so how would the custom attributes would make it to the context sent to the server.

key, kind, name, and anonymous are stored as instance variables in the built context. Every other property is stored in the attributes hash.

In the block of code you linked to, you can see that we first define the attributes as the custom attributes you provided. Then, if you provided any of the originally pre-defined keys (ip, email, etc), then we override those specific custom attributes.

In case other people are facing the same issue, migrating to the new format and putting custom attributes at the root fixed it for me:

The two examples you provided aren't actually equivalent. In the original, legacy format, you could target the customAttribute directly. In the new version, you would have to access it by /custom/customAttribute.

The below 2 would be equivalent.

// Legacy user format
{key: 'key', custom: { customAttribute: 'value' }}

// New kind format
{kind: 'user', key: 'key', customAttribute: 'value'}
Hugo-Hache commented 1 year ago

Hi @keelerm84,

Thanks for the reactivity, you're right about the syntax (I mistakenly let the custom key in LDContext, edited my original to remove it).

To check the customAttributes change I'm using the contexts detail page of my user https://app.launchdarkly.com/default//contexts/user/

Since last Friday I've noticed the new Live Events page, here's what I did and observed:

(I first wrote a more detailed transcript where custom attribute never changed ... because I copied the key from context page title and one letter was uppercased 🙈)

As this issue was about syntax to update custom attributes I'm closing it, thanks for your help.