Skip to content

Commit

Permalink
Merge 0c1c95a into 26dfc70
Browse files Browse the repository at this point in the history
  • Loading branch information
fuaiyi authored Apr 13, 2023
2 parents 26dfc70 + 0c1c95a commit 28874c7
Show file tree
Hide file tree
Showing 61 changed files with 3,972 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Filter Logs singal files
!experimental/examples/logs

# Runtime data
pids
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/
### :rocket: (Enhancement)

* feat(tracing): log span name and IDs when span end is called multiple times [#3716](https://github.com/open-telemetry/opentelemetry-js/pull/3716)
* feat(core): add logs environment variables; add timeout utils method. [#3549](https://github.com/open-telemetry/opentelemetry-js/pull/3549/) @fuaiyi

### :bug: (Bug Fix)

Expand Down
3 changes: 3 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ All notable changes to experimental packages in this project will be documented

### :rocket: (Enhancement)

* feat(api-logs): 1.`LogRecord` fields update: `traceFlags`/`traceId`/`spanId` -> `context`; 2.`Logger` supports configuring `includeTraceContext`; 3.The `onEmit` method of `LogRecordProcessor` supports the `context` field. [#3549](https://github.com/open-telemetry/opentelemetry-js/pull/3549/) @fuaiyi
* feat(sdk-logs): logs sdk implementation. [#3549](https://github.com/open-telemetry/opentelemetry-js/pull/3549/) @fuaiyi

### :bug: (Bug Fix)

* fix(sdk-node): only set DiagConsoleLogger when OTEL_LOG_LEVEL is set [#3693](https://github.com/open-telemetry/opentelemetry-js/pull/3672) @pichlermarc
Expand Down
23 changes: 23 additions & 0 deletions experimental/examples/logs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Installation

```sh
# from this directory
npm install
```

## Run the Application

LogRecord

```sh
npm start
```

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more information on OpenTelemetry logs, visit: <https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/sdk-logs>

## LICENSE

Apache License 2.0
43 changes: 43 additions & 0 deletions experimental/examples/logs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { DiagConsoleLogger, DiagLogLevel, diag } from '@opentelemetry/api';
import { logs, SeverityNumber } from '@opentelemetry/api-logs';
import {
LoggerProvider,
ConsoleLogRecordExporter,
SimpleLogRecordProcessor,
} from '@opentelemetry/sdk-logs';

// Optional and only needed to see the internal diagnostic logging (during development)
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);

const loggerProvider = new LoggerProvider();
loggerProvider.addLogRecordProcessor(
new SimpleLogRecordProcessor(new ConsoleLogRecordExporter())
);

logs.setGlobalLoggerProvider(loggerProvider);

const logger = logs.getLogger('example', '1.0.0');

// emit a log record
logger.emit({
severityNumber: SeverityNumber.INFO,
severityText: 'INFO',
body: 'this is a log record body',
attributes: { 'log.type': 'custom' },
});
17 changes: 17 additions & 0 deletions experimental/examples/logs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "logs-example",
"version": "0.1.0",
"private": true,
"scripts": {
"start": "ts-node index.ts"
},
"dependencies": {
"@opentelemetry/api": "^1.4.1",
"@opentelemetry/api-logs": "^0.37.0",
"@opentelemetry/sdk-logs": "^0.37.0"
},
"devDependencies": {
"ts-node": "^10.9.1",
"@types/node": "18.6.5"
}
}
19 changes: 19 additions & 0 deletions experimental/examples/logs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "build",
"rootDir": "."
},
"include": ["./index.ts"],
"references": [
{
"path": "../../../api"
},
{
"path": "../../../experimental/packages/api-logs"
},
{
"path": "../../../experimental/packages/sdk-logs"
}
]
}
2 changes: 2 additions & 0 deletions experimental/packages/api-logs/src/NoopLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ import { LogRecord } from './types/LogRecord';
export class NoopLogger implements Logger {
emit(_logRecord: LogRecord): void {}
}

export const NOOP_LOGGER = new NoopLogger();
2 changes: 2 additions & 0 deletions experimental/packages/api-logs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export * from './types/Logger';
export * from './types/LoggerProvider';
export * from './types/LogRecord';
export * from './types/LoggerOptions';
export * from './NoopLogger';
export * from './NoopLoggerProvider';

import { LogsAPI } from './api/logs';
export const logs = LogsAPI.getInstance();
16 changes: 3 additions & 13 deletions experimental/packages/api-logs/src/types/LogRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { Attributes } from '@opentelemetry/api';
import { Attributes, Context } from '@opentelemetry/api';

export enum SeverityNumber {
UNSPECIFIED = 0,
Expand Down Expand Up @@ -71,17 +71,7 @@ export interface LogRecord {
attributes?: Attributes;

/**
* 8 least significant bits are the trace flags as defined in W3C Trace Context specification.
* The Context associated with the LogRecord.
*/
traceFlags?: number;

/**
* A unique identifier for a trace.
*/
traceId?: string;

/**
* A unique identifier for a span within a trace.
*/
spanId?: string;
context?: Context;
}
6 changes: 6 additions & 0 deletions experimental/packages/api-logs/src/types/LoggerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ export interface LoggerOptions {
* The instrumentation scope attributes to associate with emitted telemetry
*/
scopeAttributes?: Attributes;

/**
* Specifies whether the Trace Context should automatically be passed on to the LogRecords emitted by the Logger.
* @default true
*/
includeTraceContext?: boolean;
}
1 change: 1 addition & 0 deletions experimental/packages/sdk-logs/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
7 changes: 7 additions & 0 deletions experimental/packages/sdk-logs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
env: {
mocha: true,
node: true,
},
...require('../../../eslint.config.js'),
};
4 changes: 4 additions & 0 deletions experimental/packages/sdk-logs/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/bin
/coverage
/doc
/test
Loading

0 comments on commit 28874c7

Please sign in to comment.