From 56edf5aea00731579399a75ebe14ec5de30ecd3e Mon Sep 17 00:00:00 2001 From: fugao Date: Wed, 21 Dec 2022 12:11:38 +0800 Subject: [PATCH 1/3] feat(api-logs): add the SeverityNumber enumeration --- experimental/packages/api-logs/README.md | 2 +- .../packages/api-logs/src/types/LogRecord.ts | 30 ++++++++++++++++++- .../noop-implementations/noop-logger.test.ts | 3 +- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/experimental/packages/api-logs/README.md b/experimental/packages/api-logs/README.md index 57d40a3211..1d5a17fa76 100644 --- a/experimental/packages/api-logs/README.md +++ b/experimental/packages/api-logs/README.md @@ -42,7 +42,7 @@ const logger = api.logs.getLogger(name, version); logger.emitEvent({ name: 'event-name', domain: 'event-domain' }); // logging an event in a log appender -logger.emitLogRecord({ severityNumber: 1, body: 'log data' }); +logger.emitLogRecord({ severityNumber: SeverityNumber.TRACE, body: 'log data' }); ``` ## Useful links diff --git a/experimental/packages/api-logs/src/types/LogRecord.ts b/experimental/packages/api-logs/src/types/LogRecord.ts index dab3302911..d64d404752 100644 --- a/experimental/packages/api-logs/src/types/LogRecord.ts +++ b/experimental/packages/api-logs/src/types/LogRecord.ts @@ -16,6 +16,34 @@ import { Attributes } from '@opentelemetry/api'; +export enum SeverityNumber { + UNSPECIFIED = 0, + TRACE = 1, + TRACE2 = 2, + TRACE3 = 3, + TRACE4 = 4, + DEBUG = 5, + DEBUG2 = 6, + DEBUG3 = 7, + DEBUG4 = 8, + INFO = 9, + INFO2 = 10, + INFO3 = 11, + INFO4 = 12, + WARN = 13, + WARN2 = 14, + WARN3 = 15, + WARN4 = 16, + ERROR = 17, + ERROR2 = 18, + ERROR3 = 19, + ERROR4 = 20, + FATAL = 21, + FATAL2 = 22, + FATAL3 = 23, + FATAL4 = 24, +} + export interface LogRecord { /** * The time when the log record occurred as UNIX Epoch time in nanoseconds. @@ -25,7 +53,7 @@ export interface LogRecord { /** * Numerical value of the severity. */ - severityNumber?: number; + severityNumber?: SeverityNumber; /** * The severity text. diff --git a/experimental/packages/api-logs/test/noop-implementations/noop-logger.test.ts b/experimental/packages/api-logs/test/noop-implementations/noop-logger.test.ts index 6360e7b7dd..cd3e10fc4e 100644 --- a/experimental/packages/api-logs/test/noop-implementations/noop-logger.test.ts +++ b/experimental/packages/api-logs/test/noop-implementations/noop-logger.test.ts @@ -15,6 +15,7 @@ */ import * as assert from 'assert'; +import { SeverityNumber } from '../../src'; import { NoopLogger } from '../../src/NoopLogger'; import { NoopLoggerProvider } from '../../src/NoopLoggerProvider'; @@ -31,6 +32,6 @@ describe('NoopLogger', () => { it('calling emitLogRecord should not crash', () => { const logger = new NoopLoggerProvider().getLogger('test-noop'); - logger.emitLogRecord({ severityNumber: 1, body: 'log body' }); + logger.emitLogRecord({ severityNumber: SeverityNumber.TRACE, body: 'log body' }); }); }); From 122b9c057eeb943f78803d36abc928e26dcdf8f2 Mon Sep 17 00:00:00 2001 From: fugao Date: Wed, 21 Dec 2022 15:15:25 +0800 Subject: [PATCH 2/3] feat(api-logs): add the SeverityNumber enumeration --- experimental/CHANGELOG.md | 2 +- .../api-logs/test/noop-implementations/noop-logger.test.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 95d3407dd5..6d27b23060 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -11,7 +11,7 @@ All notable changes to experimental packages in this project will be documented * feat(instrumentation-http): monitor error events with events.errorMonitor [#3402](https://github.com/open-telemetry/opentelemetry-js/pull/3402) @legendecas * feat(instrumentation-grpc): added grpc metadata client side attributes in instrumentation [#3386](https://github.com/open-telemetry/opentelemetry-js/pull/3386) * feat(instrumentation): add new `_setMeterInstruments` protected method that update the meter instruments every meter provider update. - +* feat(api-logs): add the `SeverityNumber` enumeration. [#3443](https://github.com/open-telemetry/opentelemetry-js/pull/3443/) @fuaiyi ### :bug: (Bug Fix) * fix(instrumentation-xhr): http.url attribute should be absolute [#3200](https://github.com/open-telemetry/opentelemetry-js/pull/3200) @t2t2 diff --git a/experimental/packages/api-logs/test/noop-implementations/noop-logger.test.ts b/experimental/packages/api-logs/test/noop-implementations/noop-logger.test.ts index cd3e10fc4e..85537d59f0 100644 --- a/experimental/packages/api-logs/test/noop-implementations/noop-logger.test.ts +++ b/experimental/packages/api-logs/test/noop-implementations/noop-logger.test.ts @@ -32,6 +32,9 @@ describe('NoopLogger', () => { it('calling emitLogRecord should not crash', () => { const logger = new NoopLoggerProvider().getLogger('test-noop'); - logger.emitLogRecord({ severityNumber: SeverityNumber.TRACE, body: 'log body' }); + logger.emitLogRecord({ + severityNumber: SeverityNumber.TRACE, + body: 'log body', + }); }); }); From 64bc7700f4c3ef0821cf49ba44b565a14b1d828d Mon Sep 17 00:00:00 2001 From: fugao Date: Wed, 21 Dec 2022 21:22:13 +0800 Subject: [PATCH 3/3] feat(api-logs): add the SeverityNumber enumeration --- experimental/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 6d27b23060..d25839061b 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to experimental packages in this project will be documented * feat(instrumentation-grpc): added grpc metadata client side attributes in instrumentation [#3386](https://github.com/open-telemetry/opentelemetry-js/pull/3386) * feat(instrumentation): add new `_setMeterInstruments` protected method that update the meter instruments every meter provider update. * feat(api-logs): add the `SeverityNumber` enumeration. [#3443](https://github.com/open-telemetry/opentelemetry-js/pull/3443/) @fuaiyi + ### :bug: (Bug Fix) * fix(instrumentation-xhr): http.url attribute should be absolute [#3200](https://github.com/open-telemetry/opentelemetry-js/pull/3200) @t2t2