This repository was archived by the owner on Nov 17, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +18
-8
lines changed
Expand file tree Collapse file tree 2 files changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -79,11 +79,15 @@ export class DiagAPI implements DiagLogger {
7979 return false ;
8080 }
8181
82- return registerGlobal (
83- 'diag' ,
84- createLogLevelDiagLogger ( logLevel , logger ) ,
85- true
86- ) ;
82+ const oldLogger = getGlobal ( 'diag' ) ;
83+ const newLogger = createLogLevelDiagLogger ( logLevel , logger ) ;
84+ // There already is an logger registered. We'll let it know before overwriting it.
85+ if ( oldLogger ) {
86+ oldLogger . warn ( 'Current logger will be overwritten' ) ;
87+ newLogger . warn ( 'Current logger will overwrite one already registered' ) ;
88+ }
89+
90+ return registerGlobal ( 'diag' , newLogger , true ) ;
8791 } ;
8892
8993 self . disable = ( ) => {
Original file line number Diff line number Diff line change @@ -35,13 +35,16 @@ export function registerGlobal<Type extends keyof OTelGlobalAPI>(
3535 instance : OTelGlobalAPI [ Type ] ,
3636 allowOverride = false
3737) : boolean {
38- _global [ GLOBAL_OPENTELEMETRY_API_KEY ] = _global [
38+ diag . debug (
39+ `@opentelemetry/api: Registering a global for ${ type } v${ VERSION } .`
40+ ) ;
41+
42+ const api = ( _global [ GLOBAL_OPENTELEMETRY_API_KEY ] = _global [
3943 GLOBAL_OPENTELEMETRY_API_KEY
4044 ] ?? {
4145 version : VERSION ,
42- } ;
46+ } ) ;
4347
44- const api = _global [ GLOBAL_OPENTELEMETRY_API_KEY ] ! ;
4548 if ( ! allowOverride && api [ type ] ) {
4649 // already registered an API of this type
4750 const err = new Error (
@@ -75,6 +78,9 @@ export function getGlobal<Type extends keyof OTelGlobalAPI>(
7578}
7679
7780export function unregisterGlobal ( type : keyof OTelGlobalAPI ) {
81+ diag . debug (
82+ `@opentelemetry/api: Unregistering a global for ${ type } v${ VERSION } .`
83+ ) ;
7884 const api = _global [ GLOBAL_OPENTELEMETRY_API_KEY ] ;
7985
8086 if ( api ) {
You can’t perform that action at this time.
0 commit comments