From 6e7fed505002b1143b679c813d590e5e700f5730 Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Tue, 16 Aug 2022 15:11:22 +0100 Subject: [PATCH 1/7] Update logger Global Context APIs --- packages/logs/README.md | 62 +++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/packages/logs/README.md b/packages/logs/README.md index a8b96199e6..55b6759133 100644 --- a/packages/logs/README.md +++ b/packages/logs/README.md @@ -479,9 +479,15 @@ 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: Context)` API. +- Add a context to all your loggers with `setGlobalContextProperty (key: string, value: any)` API. +- Get the entire global context with `getGlobalContext ()` 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 +496,19 @@ For NPM, use: ```javascript import { datadogLogs } from '@datadog/browser-logs' -datadogLogs.setLoggerGlobalContext({ env: 'staging' }) +datadogLogs.setGlobalContext({ env: 'staging' }) + +datadogLogs.setGlobalContextProperty('referrer', document.referrer) + +datadogLogs.getGlobalContext() // => {env: 'staging', referrer: ...} -datadogLogs.addLoggerGlobalContext('referrer', document.referrer) +datadogLogs.removeGlobalContextProperty('referrer') -const context = datadogLogs.getLoggerGlobalContext() // => {env: 'staging', referrer: ...} +datadogLogs.getGlobalContext() // => {env: 'staging'} + +datadogLogs.clearGlobalContext() + +datadogLogs.getGlobalContext() // => {} ``` #### CDN async @@ -503,15 +517,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) + datadogLogs.removeGlobalContextProperty('referrer') }) DD_LOGS.onReady(function () { - var context = DD_LOGS.getLoggerGlobalContext() // => {env: 'staging', referrer: ...} + datadogLogs.getGlobalContext() // => {env: 'staging'} +}) + +DD_LOGS.onReady(function () { + datadogLogs.clearGlobalContext() +}) + +DD_LOGS.onReady(function () { + datadogLogs.getGlobalContext() // => {} }) ``` @@ -522,11 +552,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. From 54454c7047ccd5ac653c389585c398d3b1fbe0cb Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Tue, 16 Aug 2022 15:19:24 +0100 Subject: [PATCH 2/7] fix README format --- packages/logs/README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/logs/README.md b/packages/logs/README.md index 55b6759133..710d9e3892 100644 --- a/packages/logs/README.md +++ b/packages/logs/README.md @@ -484,10 +484,11 @@ After the Datadog browser logs SDK is initialized, it is possible to: - Get the entire global context with `getGlobalContext ()` 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` +> +> - `getGlobalContext` instead of `getLoggerGlobalContext` +> - `setGlobalContext` instead of `setLoggerGlobalContext` +> - `setGlobalContextProperty` instead of `addLoggerGlobalContext` +> - `removeGlobalContextProperty` instead of `removeLoggerGlobalContext` ##### NPM From c8bf1a0fcdb5dfb02b916d71b1ba08839c3d56a6 Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Wed, 17 Aug 2022 09:17:31 +0100 Subject: [PATCH 3/7] Update packages/logs/README.md Co-authored-by: Heston Hoffman --- packages/logs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/logs/README.md b/packages/logs/README.md index 710d9e3892..dcde78bb49 100644 --- a/packages/logs/README.md +++ b/packages/logs/README.md @@ -480,7 +480,7 @@ 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 `setGlobalContext (context: Context)` API. -- Add a context to all your loggers with `setGlobalContextProperty (key: string, value: any)` API. +- Add a context to all your loggers with the `setGlobalContextProperty (key: string, value: any)` API. - Get the entire global context with `getGlobalContext ()` API. > The Log Browser SDK v4.17.0 has updated the names of several APIs: From 24646815a0acbd4da2d1dca522d97e5bf90e8413 Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Wed, 17 Aug 2022 09:17:37 +0100 Subject: [PATCH 4/7] Update packages/logs/README.md Co-authored-by: Heston Hoffman --- packages/logs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/logs/README.md b/packages/logs/README.md index dcde78bb49..cace647625 100644 --- a/packages/logs/README.md +++ b/packages/logs/README.md @@ -481,7 +481,7 @@ After the Datadog browser logs SDK is initialized, it is possible to: - Set the entire context for all your loggers with the `setGlobalContext (context: Context)` API. - Add a context to all your loggers with the `setGlobalContextProperty (key: string, value: any)` API. -- Get the entire global context with `getGlobalContext ()` API. +- Get the entire global context with the `getGlobalContext ()` API. > The Log Browser SDK v4.17.0 has updated the names of several APIs: > From fc0ca9932d87a21cc6de7fda49f6f278f458dcfd Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Wed, 17 Aug 2022 09:22:33 +0100 Subject: [PATCH 5/7] Document `removeGlobalContextProperty` and `clearGlobalContext` --- packages/logs/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/logs/README.md b/packages/logs/README.md index cace647625..9d1e59b5b9 100644 --- a/packages/logs/README.md +++ b/packages/logs/README.md @@ -482,6 +482,8 @@ After the Datadog browser logs SDK is initialized, it is possible to: - Set the entire context for all your loggers with the `setGlobalContext (context: Context)` 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: > From 569309a5c27b706b2408fe956f40f7a4d781d5cb Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Wed, 17 Aug 2022 14:08:44 +0100 Subject: [PATCH 6/7] change type Context to object --- packages/logs/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/logs/README.md b/packages/logs/README.md index 9d1e59b5b9..3809b7038e 100644 --- a/packages/logs/README.md +++ b/packages/logs/README.md @@ -479,7 +479,7 @@ 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 `setGlobalContext (context: Context)` 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. @@ -576,7 +576,7 @@ window.DD_LOGS && DD_LOGS.getGlobalContext() // => {} 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 From 522fc0bbe7dd1d9274bedb9a47d1c9e0599c63ff Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Wed, 17 Aug 2022 14:09:25 +0100 Subject: [PATCH 7/7] use DD_LOGS instead of datadogLogs --- packages/logs/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/logs/README.md b/packages/logs/README.md index 3809b7038e..46275da9f0 100644 --- a/packages/logs/README.md +++ b/packages/logs/README.md @@ -532,19 +532,19 @@ DD_LOGS.onReady(function () { }) DD_LOGS.onReady(function () { - datadogLogs.removeGlobalContextProperty('referrer') + DD_LOGS.removeGlobalContextProperty('referrer') }) DD_LOGS.onReady(function () { - datadogLogs.getGlobalContext() // => {env: 'staging'} + DD_LOGS.getGlobalContext() // => {env: 'staging'} }) DD_LOGS.onReady(function () { - datadogLogs.clearGlobalContext() + DD_LOGS.clearGlobalContext() }) DD_LOGS.onReady(function () { - datadogLogs.getGlobalContext() // => {} + DD_LOGS.getGlobalContext() // => {} }) ```