Skip to content

Commit

Permalink
feat(api-logs): add the SeverityNumber enumeration (#3443)
Browse files Browse the repository at this point in the history
* feat(api-logs): add the SeverityNumber enumeration

* feat(api-logs): add the SeverityNumber enumeration

* feat(api-logs): add the SeverityNumber enumeration
  • Loading branch information
fuaiyi authored Dec 21, 2022
1 parent faa0a33 commit 1c3af6c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +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)

Expand Down
2 changes: 1 addition & 1 deletion experimental/packages/api-logs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 29 additions & 1 deletion experimental/packages/api-logs/src/types/LogRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -25,7 +53,7 @@ export interface LogRecord {
/**
* Numerical value of the severity.
*/
severityNumber?: number;
severityNumber?: SeverityNumber;

/**
* The severity text.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import * as assert from 'assert';
import { SeverityNumber } from '../../src';
import { NoopLogger } from '../../src/NoopLogger';
import { NoopLoggerProvider } from '../../src/NoopLoggerProvider';

Expand All @@ -31,6 +32,9 @@ 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',
});
});
});

0 comments on commit 1c3af6c

Please sign in to comment.