From 57aad0a31cf14fd0e97f606630a2ac8d056d9fe4 Mon Sep 17 00:00:00 2001 From: "andreas.karlsson" Date: Thu, 29 Aug 2024 13:24:32 +0200 Subject: [PATCH] docs: clarify importance of withContext in server usage (#197) --- packages/sdk/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/sdk/README.md b/packages/sdk/README.md index 5d8b0073..863a2d97 100644 --- a/packages/sdk/README.md +++ b/packages/sdk/README.md @@ -61,6 +61,9 @@ const childInstance = confidence.withContext({ 'pants-color': 'blue', 'pants-fit At this point, the context of `childInstance` is `'pants-color': 'blue', 'pants-fit': 'slim'` while the context of `confidence` remains `{'pants-color': 'yellow'}`. +[!IMPORTANT] +When using the SDK in a server environment, you should call `withContext` rather than `setContext`. This will give you a new instance scoped to the request and prevent context from leaking between requests. + ## Event tracking Use `confidence.track()` from any Confidence instance to track an event in Confidence. Any context data set on the instance will be appended to the tracking event.