{"action":"created","issue":{"url":"https://api.github.com/repos/getsentry/raven-node/issues/228","repository_url":"https://api.github.com/repos/getsentry/raven-node","labels_url":"https://api.github.com/repos/getsentry/raven-node/issues/228/labels{/name}","comments_url":"https://api.github.com/repos/getsentry/raven-node/issues/228/comments","events_url":"https://api.github.com/repos/getsentry/raven-node/issues/228/events","html_url":"https://github.com/getsentry/raven-node/issues/228","id":187451915,"number":228,"title":"mergeContext is shallow and could be better if it went deeper","user":{"login":"LewisJEllis","id":1445984,"avatar_url":"https://avatars.githubusercontent.com/u/1445984?v=3","gravatar_id":"","url":"https://api.github.com/users/LewisJEllis","html_url":"https://github.com/LewisJEllis","followers_url":"https://api.github.com/users/LewisJEllis/followers","following_url":"https://api.github.com/users/LewisJEllis/following{/other_user}","gists_url":"https://api.github.com/users/LewisJEllis/gists{/gist_id}","starred_url":"https://api.github.com/users/LewisJEllis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LewisJEllis/subscriptions","organizations_url":"https://api.github.com/users/LewisJEllis/orgs","repos_url":"https://api.github.com/users/LewisJEllis/repos","events_url":"https://api.github.com/users/LewisJEllis/events{/privacy}","received_events_url":"https://api.github.com/users/LewisJEllis/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-04T22:28:25Z","updated_at":"2016-11-06T03:47:58Z","closed_at":null,"body":"Right now it just throws our `extend` helper at the context object, which is a shallow non-recursive merge, so:\r\n```javascript\r\nRaven.setContext({\r\n  user: {\r\n    username: 'lewis',\r\n  }\r\n});\r\nRaven.mergeContext({\r\n  user: {\r\n    email: 'lewis@...'\r\n  }\r\n});\r\nconsole.log(Raven.getContext().user);\r\n```\r\ncurrently gives us:\r\n```\r\n{\r\n  email: 'lewis@...'\r\n}\r\n```\r\nbut we might prefer/expect to get:\r\n```\r\n{\r\n  username: 'lewis',\r\n  email: 'lewis@...'\r\n}\r\n```\r\nIt only does mergey stuff in not clobbering any keys on the ctx other than `user`, but it's just replacing the old value of user with the new one.\r\n\r\nRight now to accomplish this, we need to do something like:\r\n```javascript\r\nvar currUserCtx = Raven.getContext().user;\r\nvar newUser = goDoOurOwnMerge(currUserCtx, { email: 'lewis@...' });\r\nRaven.mergeContext({ user: newUser });\r\n```\r\n\r\nThe context data needs to be json-serializable anyway and we use json-stringify-safe, but we should also be careful not to let merging trip on recursion/circular reference problems. I think just going one level deeper should keep this simple and still make `mergeContext` significantly more helpful, but I haven't really ruled out other options.\r\n\r\n/cc @benvinegar @MaxBittker for thoughts"},"comment":{"url":"https://api.github.com/repos/getsentry/raven-node/issues/comments/258658648","html_url":"https://github.com/getsentry/raven-node/issues/228#issuecomment-258658648","issue_url":"https://api.github.com/repos/getsentry/raven-node/issues/228","id":258658648,"user":{"login":"MaxBittker","id":5915546,"avatar_url":"https://avatars.githubusercontent.com/u/5915546?v=3","gravatar_id":"","url":"https://api.github.com/users/MaxBittker","html_url":"https://github.com/MaxBittker","followers_url":"https://api.github.com/users/MaxBittker/followers","following_url":"https://api.github.com/users/MaxBittker/following{/other_user}","gists_url":"https://api.github.com/users/MaxBittker/gists{/gist_id}","starred_url":"https://api.github.com/users/MaxBittker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaxBittker/subscriptions","organizations_url":"https://api.github.com/users/MaxBittker/orgs","repos_url":"https://api.github.com/users/MaxBittker/repos","events_url":"https://api.github.com/users/MaxBittker/events{/privacy}","received_events_url":"https://api.github.com/users/MaxBittker/received_events","type":"User","site_admin":false},"created_at":"2016-11-06T03:47:58Z","updated_at":"2016-11-06T03:47:58Z","body":"+1 on just merging 1 (or even 2) levels deep, sounds like it's a solid improvement with few downsides. "}}
{"actor":{"display_login":"MaxBittker"}}