diff --git a/packages/logs/README.md b/packages/logs/README.md index a8b96199e6..46275da9f0 100644 --- a/packages/logs/README.md +++ b/packages/logs/README.md @@ -479,9 +479,18 @@ if (window.DD_LOGS) { After the Datadog browser logs SDK is initialized, it is possible to: -- Set the entire context for all your loggers with the `setLoggerGlobalContext (context: Context)` API. -- Add a context to all your loggers with `addLoggerGlobalContext (key: string, value: any)` API. -- Get the entire global context with `getLoggerGlobalContext ()` API. +- Set the entire context for all your loggers with the `setGlobalContext (context: object)` API. +- Add a context to all your loggers with the `setGlobalContextProperty (key: string, value: any)` API. +- Get the entire global context with the `getGlobalContext ()` API. +- Remove context property with the `removeGlobalContextProperty (key: string)` API. +- Clear all existing context properties with the `clearGlobalContext ()` API. + +> The Log Browser SDK v4.17.0 has updated the names of several APIs: +> +> - `getGlobalContext` instead of `getLoggerGlobalContext` +> - `setGlobalContext` instead of `setLoggerGlobalContext` +> - `setGlobalContextProperty` instead of `addLoggerGlobalContext` +> - `removeGlobalContextProperty` instead of `removeLoggerGlobalContext` ##### NPM @@ -490,11 +499,19 @@ For NPM, use: ```javascript import { datadogLogs } from '@datadog/browser-logs' -datadogLogs.setLoggerGlobalContext({ env: 'staging' }) +datadogLogs.setGlobalContext({ env: 'staging' }) -datadogLogs.addLoggerGlobalContext('referrer', document.referrer) +datadogLogs.setGlobalContextProperty('referrer', document.referrer) -const context = datadogLogs.getLoggerGlobalContext() // => {env: 'staging', referrer: ...} +datadogLogs.getGlobalContext() // => {env: 'staging', referrer: ...} + +datadogLogs.removeGlobalContextProperty('referrer') + +datadogLogs.getGlobalContext() // => {env: 'staging'} + +datadogLogs.clearGlobalContext() + +datadogLogs.getGlobalContext() // => {} ``` #### CDN async @@ -503,15 +520,31 @@ For CDN async, use: ```javascript DD_LOGS.onReady(function () { - DD_LOGS.setLoggerGlobalContext({ env: 'staging' }) + DD_LOGS.setGlobalContext({ env: 'staging' }) +}) + +DD_LOGS.onReady(function () { + DD_LOGS.setGlobalContextProperty('referrer', document.referrer) +}) + +DD_LOGS.onReady(function () { + DD_LOGS.getGlobalContext() // => {env: 'staging', referrer: ...} }) DD_LOGS.onReady(function () { - DD_LOGS.addLoggerGlobalContext('referrer', document.referrer) + DD_LOGS.removeGlobalContextProperty('referrer') }) DD_LOGS.onReady(function () { - var context = DD_LOGS.getLoggerGlobalContext() // => {env: 'staging', referrer: ...} + DD_LOGS.getGlobalContext() // => {env: 'staging'} +}) + +DD_LOGS.onReady(function () { + DD_LOGS.clearGlobalContext() +}) + +DD_LOGS.onReady(function () { + DD_LOGS.getGlobalContext() // => {} }) ``` @@ -522,11 +555,19 @@ DD_LOGS.onReady(function () { For CDN sync, use: ```javascript -window.DD_LOGS && DD_LOGS.setLoggerGlobalContext({ env: 'staging' }) +window.DD_LOGS && DD_LOGS.setGlobalContext({ env: 'staging' }) + +window.DD_LOGS && DD_LOGS.setGlobalContextProperty('referrer', document.referrer) + +window.DD_LOGS && DD_LOGS.getGlobalContext() // => {env: 'staging', referrer: ...} + +window.DD_LOGS && DD_LOGS.removeGlobalContextProperty('referrer') + +window.DD_LOGS && DD_LOGS.getGlobalContext() // => {env: 'staging'} -window.DD_LOGS && DD_LOGS.addLoggerGlobalContext('referrer', document.referrer) +window.DD_LOGS && DD_LOGS.clearGlobalContext() -var context = window.DD_LOGS && DD_LOGS.getLoggerGlobalContext() // => {env: 'staging', referrer: ...} +window.DD_LOGS && DD_LOGS.getGlobalContext() // => {} ``` **Note**: The `window.DD_LOGS` check is used to prevent issues if a loading failure occurs with the SDK. @@ -535,7 +576,7 @@ var context = window.DD_LOGS && DD_LOGS.getLoggerGlobalContext() // => {env: 'st After a logger is created, it is possible to: -- Set the entire context for your logger with the `setContext (context: Context)` API. +- Set the entire context for your logger with the `setContext (context: object)` API. - Add a context to your logger with `addContext (key: string, value: any)` API: ##### NPM