Having a potential problem with what we are seeing...
# support
t
Having a potential problem with what we are seeing with identify calls. We use the Ruby SDK to identify a user like this:
Copy code
irb(main):002:0> pp RudderAttributes::UserProperties.for_account(a)
{:user_id=>"50",
 :traits=>
  {:"Shop Name"=>"Rudderstack Test",
   :"Shop Description"=> "My description",
   :"Created At"=>"2023-03-21T20:28:42Z",
   :Currency=>"USD",
   :email=>"user@user.com",
   :properties=>{:subscribe=>true}},
 :context=>nil,
 :integrations=>{:Intercom=>false}}
However in the live event view, it's showing the traits twice, once as a top level property, but then again as a nested prop of `context`:
Copy code
{
  "channel": "server",
  "context": {
    "library": {
      "name": "rudderanalytics-ruby",
      "version": "2.0.2"
    },
    "traits": {
      "Created At": "2018-04-20T22:27:47Z",
      "Currency": "USD",
      "Shop Description": "My description",
      "Shop Name": "Rudderstack Test",
      "email": "user@user.com",
      "properties": {
        "subscribe": true
      }
    }
  },
  "integrations": {
    "Intercom": false
  },
  "messageId": "f2d7f284-5f7c-41d5-bd82-402d74643251",
  "rudderId": "f093e616-5855-4bbd-8621-4bffe9a663a8",
  "sentAt": "2023-08-01T21:10:39.367Z",
  "timestamp": "2023-08-01T21:10:39.367Z",
  "traits": {
    "Created At": "2018-04-20T22:27:47Z",
    "Currency": "USD",
    "Shop Description": "My description",
    "Shop Name": "Rudderstack Test",
    "email": "user@user.com",
    "properties": {
      "subscribe": true
    }
  },
  "type": "identify",
  "userId": "50"
}
This doesn't occur when do an identify call with the JS SDK -- I only see the traits under
context.traits
I can't find any documentation around this either. This impacts what I am writing for a transformation so trying to get to the bottom of this.
m
Hey There! 👋 Your message has been received by the RudderStack team. We will forward this request to your Technical Account Manager, and they will get back to you shortly. Please use the thread for any additional comments.
t
The JS SDK generates this.. notice
traits
is just within
context
and not at the top level:
Copy code
"anonymousId": "b7996d98-96cb-46da-8162-8dcb27f07d73",
    "channel": "web",
    "context": {
        "app": {
            "name": "RudderLabs JavaScript SDK",
            "namespace": "com.rudderlabs.javascript",
            "version": "2.38.1"
        },
        "campaign": {},
        "library": {
            "name": "RudderLabs JavaScript SDK",
            "version": "2.38.1"
        },
        "locale": "en-US",
        "os": {
            "name": "",
            "version": ""
        },
        "page": {
            "path": "/dashboard",
            "search": "",
            "tab_url": "https://my.bigcartel.biz/dashboard",
            "title": "Big Cartel - Dashboard",
            "url": "https://my.bigcartel.biz/dashboard"
        },
        "screen": {
            "density": 2,
            "height": 1440,
            "innerHeight": 1152,
            "innerWidth": 829,
            "width": 2560
        },
        "sessionId": 1690925648908,
        "traits": {
            "Created At": "2018-04-20T22:27:47Z",
            "Currency": "USD",
            "Shop Description": "My description",
            "Shop Name": "Rudderstack Test",
            "email": "user@user.com",
            "properties": {
                "subscribe": true
            }
        },
        "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
    },
    "integrations": {
        "All": true
    },
    "messageId": "45e448b5-3a7a-4a4a-bdae-23f03ee20a0d",
    "originalTimestamp": "2023-08-01T21:37:31.356Z",
    "receivedAt": "2023-08-01T21:37:31.402Z",
    "request_ip": "174.21.142.42",
    "rudderId": "fdea86f3-24a7-47ac-b0f9-23ed221e28b1",
    "sentAt": "2023-08-01T21:37:31.358Z",
    "timestamp": "2023-08-01T21:37:31.400Z",
    "type": "identify",
    "userId": "50"
}
If the prop level of
traits
is supposed to be a top level property within the event, it means the JS SDK is completely broken, and I find that hard to believe. So my guess is that it's actually meant to be within
context
which means the Ruby SDK has a bug having it in both places (within
context
and at the top level) In the Ruby SDK, this line 36 and 37 of this file shows that it's keeping it at both levels: https://github.com/rudderlabs/rudder-sdk-ruby/blob/74e6a0281286cebaebfd9e16b6e5cbf3ea3a055a/lib/rudder/analytics/field_parser.rb#L36C1-L36C1 In the JS SDK, it clearly sets traits as a child of
context
but does not keep them top level: https://github.com/rudderlabs/rudder-sdk-js/blob/7b5aea1eea91511e4b68ad6fe895b638f4c4413a/src/core/analytics.js#L920C16-L920C16 In the iOS SDK,
traits
is a top level property and nested under `context`: https://github.com/rudderlabs/rudder-sdk-ios/blob/6de1425138a2dcdf36ea43c276a0b572eb836904/Sources/Classes/RSMessage.m#L25 vs https://github.com/rudderlabs/rudder-sdk-ios/blob/6de1425138a2dcdf36ea43c276a0b572eb836904/Sources/Classes/RSMessage.m#L28 So Questions: 1. in the event payload for identify, where am I supposed to find "traits"? Within
context
as a nested property only or both within context and at the top level (peer with
context
)? 2. If it’s supposed to be both places, what’s the rationale for the duplication? It seems unnecessary and bloated to do this 3. Nit pick: If it's meant to be within
context
it is super weird that in the ruby docs, it shows traits as a peer of context. We just get into weird inception mind tricks on how to think about traits vs context when passed in as a params to identify: https://www.rudderstack.com/docs/sources/event-streams/sdks/rudderstack-ruby-sdk/#identify
c
We are looking into it. CC: <!subteam^S04QT1G74Q3|@sdk-team>
m
Also Trevin, are you interested in creating the PR for this? The team can review this PR and merge it.
c
Hey @thankful-gpu-70135 Ideally, traits should not be set at two places for an Identify call. Unfortunately, due to backward compatibility concerns, we are currently unable to implement this change. However, rest assured that we have plans to address this issue in the future. However, to address your concern:
This impacts what I am writing for a transformation so trying to get to the bottom of this.
There are multiple ways you can deal with it: 1. Look for traits in both locations, following this order of priority: [
context.traits
,
traits
]. 2. Alternatively, you can drop the traits that are not required using transformation.
t
Ok that’s helpful! I would mention this in your docs. I was going out of my mind.
I will just choose to drop the top level traits then
@calm-yak-10773 @shy-kite-21035 Actually, I did observe weird behavior.. Ideally I'd like to just rely on the latest implementation which is traits within context.traits and ignore the top level traits. 1. But when I did some transformation on
context.traits
, the destinations got both sets of traits, one set transformed and one not. I'd expect a destination to only get one set of traits, not a merged set. 2.
Look for traits in both locations, following this order of priority: [
context.traits
,
traits
].
This strikes me as odd guidance because it then means I can't rely on it being in one place if I'm using a recent SDK. Is it not safe to always look at
context.traits
? 3. Can i really just delete
traits
every time and leave
context.traits
?
c
I’d expect a destination to only get one set of traits, not a merged set.
Actually, some cloud mode destinations have been configured to fall back to the top-level traits in case
context.traits
is absent. Due to this configuration, you might be receiving a merged set of traits.
3. Can i really just delete
traits
every time and leave
context.traits
?
I can think of two solution for this: 1. Since in your case, both the traits are exactly the same, you can safely delete the top-level traits. a. Suppose you’re making an identify call using the JS SDK and then performing some transformation. In this case, there wouldn’t be any top-level traits, correct? So, I wanted to synchronise the same behaviour for you, as we expect in any other client-side SDKs. 2. If there is still any doubt at your end, then transform both the traits. This way, you can guarantee that the traits will remain the same even after getting merged. Please take note that in the future, we are expecting to synchronise the behaviour between client-side and server-side SDKs.
t
@calm-yak-10773
Actually, some cloud mode destinations have been configured to fall back to the top-level traits in case
context.traits
is absent. Due to this configuration, you might be receiving a merged set of traits.
I'm seeing this with klaviyo but there must be a bug.
context.traits
is present, but I'm also getting a merged set. I think that it should never merge if
context.traits
is present, otherwise you're saying the legacy support (top level traits) always interferes.
Suppose you’re making an identify call using the JS SDK and then performing some transformation. In this case, there wouldn’t be any top-level traits, correct?
I am only using the JS sdk right now for some easy testing and sending of events to rudderstack. our "real" implementation will be done using the Ruby SDK on our service. This is how I even stumbled upon this issue.
1. Since in your case, both the traits are exactly the same, you can safely delete the top-level traits.
Ok i'll do this then, it's better and cleaner if indeed you are saying that
context.traits
is the correct most up to date place to look for traits, and will be so moving forward./
c
I’m trying to. understand this better:
I’m seeing this with klaviyo but there must be a bug.
context.traits
is present, but I’m also getting a merged set. I think that it should never merge if
context.traits
is present, otherwise you’re saying the legacy support (top level traits) always interferes.
Could you please share the code snippet that you’re currently using to make the call to Klaviyo destination using the JS SDK? Additionally, it would be helpful if you could provide more information about which traits are getting merged. This information will assist us in debugging the issue more effectively. Thank you!
t
Simplified example is this
Copy code
{
    context: {
      traits: {
        foo: {
          bar: 1
        }
      }
    },
    traits: {
      foo: {
        bar: 1
      }
    }
}
if my transformations flatters only what’s in context.traits, I have this:
Copy code
{
    context: {
      traits: {
        foo_bar: 1
      }
    },
    traits: {
      foo: {
        bar: 1
      }
    }
}
That user proprieties is sent in an identify call to rudderstack which is connected to klayvio as a destination, klayvio will show in its user properties:
Copy code
{
  foo_bar: 1,
  foo: { bar: 1 }
}
Which means RS is merging the traits into a single prop bag and sending it. If the top level traits is indeed a legacy situation I’d expect context.traits to supersede it and not get merged.
gratitude thank you 1
c
Is this happening when you make the call using the JS SDK or the Ruby SDK?
t
Ruby sdk for sure. I’m actually not sure about JS sdk
👍 1
c
Thanks for the confirmation and sharing the info!
If the top level traits is indeed a legacy situation I’d expect context.traits to supersede it and not get merged.
I agree, but actually Klayvio and other destinations are not designed to handle the same set of traits present in both context.traits and top-level traits simultaneously in an identify call. The root cause of the problem lies in the Ruby SDK, as it is generating the payload in an incorrect format. I would suggest you to proceed with two approaches, I suggested earlier, until we fix this in Ruby SDK:
1. Since in your case, both the traits are exactly the same, you can safely delete the top-level traits.
a. Suppose you’re making an identify call using the JS SDK and then performing some transformation. In this case, there wouldn’t be any top-level traits, correct? So, I wanted to synchronise the same behaviour for you, as we expect in any other client-side SDKs.
2. If there is still any doubt at your end, then transform both the traits. This way, you can guarantee that the traits will remain the same even after getting merged.
Ok i’ll do this then, it’s better and cleaner if indeed you are saying that
context.traits
is the correct most up to date place to look for traits, and will be so moving forward./
For an identify call,
context.traits
is indeed the appropriate place to look for the traits. Please proceed with this.
I’m actually not sure about JS sdk
JS SDK wouldn’t cause this issue, as there will be no top level traits in an identify call.
t
Thank you!
🙂 1
@calm-yak-10773 one thing that may solve this is just removing the top level traits completely? https://github.com/rudderlabs/rudder-sdk-ruby/pull/13
c
I'm not sure if the team would proceed with this or not due to the reason I previously mentioned. But still I'll ask the team to look again into it and respond in the PR itself.
Unfortunately, due to backward compatibility concerns, we are currently unable to implement this change.
I really appreciate your effort to raise the PR. Thanks again.
t
But if the SDK is a new release, it should handle legacy issues I'd expect. Those that need legacy support stay on old version otherwise they upgrade