You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+175Lines changed: 175 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -244,6 +244,181 @@ To request automatic tracing support for a module not on this list, please [file
244
244
245
245
## Upgrade guidelines
246
246
247
+
### 0.17.0 to ???
248
+
249
+
[PR-1880](https://github.com/open-telemetry/opentelemetry-js/pull/1880) feat(diag-logger): introduce a new global level api.diag for internal diagnostic logging
- These PR's remove the previous ```Logger``` and ```LogLevel``` implementations and change the way you should use the replacement ```DiagLogger``` and ```DiagLogLevel```, below are simple examples of how to change your existing usages.
254
+
255
+
#### New Usage patterns
256
+
257
+
-**Global Diagnostic Logging with no passed logger**
258
+
259
+
The new global [```api.diag```](https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-api/src/api/diag.ts#L32) not only provides the ability to set a global diagnostic logger ```setLogger()``` and logging level ```setLogLevel()```, it is also a ```DiagLogger``` implementation and can be used directly to log diagnostic messages.
260
+
261
+
And the helper functions will fallback to this global DiagLogger when no logger is provided or configured.
262
+
263
+
```javascript
264
+
// Previously (Not supported)
265
+
266
+
// Now
267
+
import { diag } from"@opentelemetry/api";
268
+
269
+
diag.debug("...");
270
+
271
+
// Setting the default Global logger to use the Console
let logger =getDiagLoggerFromConfig(config, () =>diag.getLogger());
325
+
}
326
+
```
327
+
328
+
#### Direct update path for existing code
329
+
330
+
Without refactoring your existing code to use ```api.diag``` or ```getDiagLoggerFromConfig``` (recommended path), below is how you would directly upgrade to the newer version so you can get compiling and running.
331
+
332
+
-**api.Logger**
333
+
334
+
The api.Logger has been renamed for clarity to highlight that this is for internal(OpenTelemetry and supporting components) diagnostic level logging and not for usage by a consuming application to send telemetry out of the executing environment.
335
+
336
+
The new ```DiagLogger``` provides the same set of functions as the previous Logger interface plus a few more, so direct replacement of the Logger is a simple case of changing to the new (renamed) type which is also exported by api.
337
+
338
+
```typescript
339
+
// Previously
340
+
import { Logger } from"@opentelemetry/api";
341
+
exportfunction(myLogger:Logger) {
342
+
myLogger.debug("...");
343
+
myLogger.info("...");
344
+
myLogger.warn("...");
345
+
myLogger.error("...");
346
+
}
347
+
348
+
// Now
349
+
import { DiagLogger } from"@opentelemetry/api";
350
+
exportfunction(myLogger:DiagLogger) {
351
+
myLogger.debug("...");
352
+
myLogger.info("...");
353
+
myLogger.warn("...");
354
+
myLogger.error("...");
355
+
356
+
// New levels
357
+
myLogger.verbose("..");
358
+
myLogger.startup("..");
359
+
myLogger.critical("..");
360
+
myLogger.terminal("..");
361
+
}
362
+
```
363
+
364
+
-**api.NoopLogger**
365
+
366
+
To support minification the NoopLogger class has been removed in favor of a factory method and generally direct usage should no longer be required as components should use the new ```api.diag``` or ```getDiagLoggerFromConfig```.
The core.LogLevel enumeration has been moved to the api package and renamed for clarity as with the ```api.DiagLogger``` to highlight its usage for diagnostic logging.
381
+
382
+
Note: Numeric compatibility of each enum value (DEBUG, INFO, WARN, ERROR) has NOT preserved.
383
+
384
+
```javascript
385
+
// Previously
386
+
import { LogLevel } from"@opentelemetry/core";
387
+
388
+
let logLevel =LogLevel.DEBUG;
389
+
LogLevel.ERROR===0// true
390
+
LogLevel.WARN===1// true
391
+
LogLevel.INFO===2// true
392
+
LogLevel.DEBUG===3// true
393
+
394
+
// Now
395
+
import { DiagLogLevel } from"@opentelemetry/api";
396
+
397
+
let logLevel =DiagLogLevel.DEBUG;
398
+
DiagLogLevel.ERROR!==0// true
399
+
DiagLogLevel.WARN!==1// true
400
+
DiagLogLevel.INFO!==2// true
401
+
DiagLogLevel.DEBUG!==3// true
402
+
```
403
+
404
+
Usage of the ```getEnv().OTEL_LOG_LEVEL``` now returns a ```api.DiagLogLevel``` and not the removed ```core.LogLevel```, the environment setting continues to support conversion from ```string``` case-insensitive values of the new Enum equivalent and but explicitly does not support initializing via a numeric value (or string version i.e. "0").
405
+
406
+
-**core.ConsoleLogger**
407
+
408
+
As with the ```core.LogLevel``` this has been moved to the ```api``` package and renamed to ```DiagConsoleLogger```.
409
+
410
+
Note: The previous version of the ```ConsoleLogger``` supported a LogLevel "limit", this functionality has been extracted into a helper wrapper sink ```createLogLevelDiagLogger()``` so it can be applied to any DiagLogger implementation.
0 commit comments