1- import type { Account , Context , TrackingConsent , User , PublicApi } from '@datadog/browser-core'
1+ import type { Account , Context , TrackingConsent , User , PublicApi , ContextManager } from '@datadog/browser-core'
22import {
3+ ContextManagerMethod ,
4+ CustomerContextKey ,
35 addTelemetryUsage ,
46 CustomerDataType ,
57 createContextManager ,
@@ -10,6 +12,7 @@ import {
1012 displayAlreadyInitializedError ,
1113 deepClone ,
1214 createTrackingConsentState ,
15+ defineContextMethod ,
1316} from '@datadog/browser-core'
1417import type { LogsInitConfiguration } from '../domain/configuration'
1518import type { HandlerType } from '../domain/logger'
@@ -197,6 +200,7 @@ const LOGS_STORAGE_KEY = 'logs'
197200export interface Strategy {
198201 init : ( initConfiguration : LogsInitConfiguration ) => void
199202 initConfiguration : LogsInitConfiguration | undefined
203+ accountContext : ContextManager
200204 getInternalContext : StartLogsResult [ 'getInternalContext' ]
201205 handleLog : StartLogsResult [ 'handleLog' ]
202206}
@@ -210,23 +214,16 @@ export function makeLogsPublicApi(startLogsImpl: StartLogs): LogsPublicApi {
210214 email : { type : 'string' } ,
211215 } ,
212216 } )
213- const accountContextManager = createContextManager ( 'account' , {
214- propertiesConfig : {
215- id : { type : 'string' , required : true } ,
216- name : { type : 'string' } ,
217- } ,
218- } )
219217 const trackingConsentState = createTrackingConsentState ( )
220218
221219 function getCommonContext ( ) {
222- return buildCommonContext ( globalContextManager , userContextManager , accountContextManager )
220+ return buildCommonContext ( globalContextManager , userContextManager )
223221 }
224222
225223 let strategy = createPreStartStrategy ( getCommonContext , trackingConsentState , ( initConfiguration , configuration ) => {
226224 if ( initConfiguration . storeContextsAcrossPages ) {
227225 storeContextManager ( configuration , globalContextManager , LOGS_STORAGE_KEY , CustomerDataType . GlobalContext )
228226 storeContextManager ( configuration , userContextManager , LOGS_STORAGE_KEY , CustomerDataType . User )
229- storeContextManager ( configuration , accountContextManager , LOGS_STORAGE_KEY , CustomerDataType . Account )
230227 }
231228
232229 const startLogsResult = startLogsImpl ( initConfiguration , configuration , getCommonContext , trackingConsentState )
@@ -235,6 +232,8 @@ export function makeLogsPublicApi(startLogsImpl: StartLogs): LogsPublicApi {
235232 return startLogsResult
236233 } )
237234
235+ const getStrategy = ( ) => strategy
236+
238237 const customLoggers : { [ name : string ] : Logger | undefined } = { }
239238
240239 const mainLogger = new Logger ( ( ...params ) => strategy . handleLog ( ...params ) )
@@ -287,15 +286,27 @@ export function makeLogsPublicApi(startLogsImpl: StartLogs): LogsPublicApi {
287286
288287 clearUser : monitor ( userContextManager . clearContext ) ,
289288
290- setAccount : monitor ( accountContextManager . setContext ) ,
289+ setAccount : defineContextMethod ( getStrategy , CustomerContextKey . accountContext , ContextManagerMethod . setContext ) ,
291290
292- getAccount : monitor ( accountContextManager . getContext ) ,
291+ getAccount : defineContextMethod ( getStrategy , CustomerContextKey . accountContext , ContextManagerMethod . getContext ) ,
293292
294- setAccountProperty : monitor ( accountContextManager . setContextProperty ) ,
293+ setAccountProperty : defineContextMethod (
294+ getStrategy ,
295+ CustomerContextKey . accountContext ,
296+ ContextManagerMethod . setContextProperty
297+ ) ,
295298
296- removeAccountProperty : monitor ( accountContextManager . removeContextProperty ) ,
299+ removeAccountProperty : defineContextMethod (
300+ getStrategy ,
301+ CustomerContextKey . accountContext ,
302+ ContextManagerMethod . removeContextProperty
303+ ) ,
297304
298- clearAccount : monitor ( accountContextManager . clearContext ) ,
305+ clearAccount : defineContextMethod (
306+ getStrategy ,
307+ CustomerContextKey . accountContext ,
308+ ContextManagerMethod . clearContext
309+ ) ,
299310 } )
300311}
301312
0 commit comments