apm-agent-rum-js icon indicating copy to clipboard operation
apm-agent-rum-js copied to clipboard

apm.setCustomContext() shallow merging behavior

Open swseverance opened this issue 3 years ago • 3 comments

Hi. Per your documentation the behavior when calling apm.setCustomContext(...) is:

For each call, the properties of the context argument are shallow merged with the context previously given.

For my project this behavior is problematic. Is there any way to replace the existing context each time setCustomContext(...) is called?

swseverance avatar Dec 08 '21 17:12 swseverance

You can workaround with this solution proposed here - https://github.com/elastic/apm-agent-rum-js/issues/1085#issuecomment-933945338

vigneshshanmugam avatar Dec 08 '21 18:12 vigneshshanmugam

Thanks @vigneshshanmugam However, it looks like apm.config(...) accepts an object of type AgentConfigOptions and there is no config property on that object. I have instead opted to do the following workaround:

apm.setCustomContext({ context: customContext });

This way the context property of the object is being completely overwritten during each invocation of apm.setCustomContext(...)

Thank you!

swseverance avatar Dec 08 '21 18:12 swseverance

Glad you found a workaround, Will update the docs to make it easier for other users. Thanks!

vigneshshanmugam avatar Dec 08 '21 19:12 vigneshshanmugam