Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logs SDK #3549

Merged
merged 50 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
0a00912
feat(sdk-logs): sdk-logs init
fuaiyi Jan 17, 2023
0a8910d
feat(sdk-logs): sdk-logs init
fuaiyi Jan 17, 2023
f25e7cf
feat(sdk-logs): sdk-logs init
fuaiyi Jan 17, 2023
b50422e
feat(sdk-logs): sdk-logs init
fuaiyi Jan 18, 2023
5fb3f64
feat(sdk-logs): sdk-logs init
fuaiyi Jan 18, 2023
76e66c1
feat(sdk-logs): sdk-logs init
fuaiyi Jan 18, 2023
2214a51
feat(sdk-logs): sdk-logs init
fuaiyi Jan 18, 2023
b5a51b4
fix compile errors
martinkuba Feb 18, 2023
f1f34a8
Merge remote-tracking branch 'upstream/main' into logs-sdk
fuaiyi Feb 18, 2023
8f8d25e
feat(sdk-logs): sdk-logs init
fuaiyi Feb 18, 2023
999f971
feat(sdk-logs): sdk-logs init
fuaiyi Feb 18, 2023
097d15d
feat(sdk-logs): sdk-logs init
fuaiyi Feb 18, 2023
1e1263b
feat(sdk-logs): sdk-logs init
fuaiyi Feb 18, 2023
66090b0
feat(sdk-logs): sdk-logs init
fuaiyi Feb 18, 2023
f045cf6
feat(sdk-logs): sdk-logs init
fuaiyi Feb 26, 2023
8196379
feat(sdk-logs): sdk-logs init
fuaiyi Feb 26, 2023
af2ae70
feat(sdk-logs): sdk-logs init
fuaiyi Feb 27, 2023
4a54b6f
Merge remote-tracking branch 'upstream/main' into logs-sdk
fuaiyi Feb 28, 2023
681d937
feat(sdk-logs): sdk-logs init
fuaiyi Feb 28, 2023
b06e7f3
feat(sdk-logs): sdk-logs init
fuaiyi Feb 28, 2023
6448b43
feat(sdk-logs): sdk-logs init
fuaiyi Feb 28, 2023
03ff511
feat(sdk-logs): add browser test config
fuaiyi Mar 1, 2023
a29f149
feat: add test-utils compatible assert.rejects
fuaiyi Mar 1, 2023
7803d66
feat(sdk-logs): fix writing errors in README
fuaiyi Mar 21, 2023
1a9a89e
Merge remote-tracking branch 'upstream/main' into logs-sdk
fuaiyi Mar 21, 2023
bb051ee
feat(sdk-logs): update version to 0.36.1
fuaiyi Mar 21, 2023
8bcb18d
feat(sdk-logs): add examples
fuaiyi Mar 21, 2023
413025f
feat(sdk-logs): fix LogRecord default timestamp to Date.now()
fuaiyi Mar 21, 2023
314ff95
feat(sdk-logs): logRecord support rewrite time/body/severityNumber/ne…
fuaiyi Mar 21, 2023
8d476d2
feat(sdk-logs): add logs processor environments
fuaiyi Mar 21, 2023
e579b13
feat(sdk-logs): modify export style
fuaiyi Mar 21, 2023
ab3b861
feat(sdk-logs): update version to 0.36.1
fuaiyi Mar 21, 2023
2501941
feat(sdk-logs): remove exporter factory
fuaiyi Mar 21, 2023
c0c1320
feat(sdk-logs): update CHANGELOG
fuaiyi Mar 21, 2023
14b1a55
feat(sdk-logs): change the processing of schemeUrl
fuaiyi Mar 21, 2023
e8ced53
feat(sdk-logs): split LoggerProviderConfig and LoggerConfig
fuaiyi Mar 28, 2023
8363356
feat(sdk-logs): getLogger with default name when name is invalid
fuaiyi Mar 28, 2023
b7e399e
feat(sdk-logs): improve the shutdown logic of LoggerProvider
fuaiyi Mar 28, 2023
b43efff
feat(sdk-logs): improve the shutdown logic of LoggerProvider
fuaiyi Mar 29, 2023
74fc360
Merge remote-tracking branch 'upstream/main' into logs-sdk
fuaiyi Apr 8, 2023
f423693
feat(sdk-logs): make log record read-only after it has been emitted
fuaiyi Apr 9, 2023
4cca19f
feat(sdk-logs): logger option support includeTraceContext & LogRecord…
fuaiyi Apr 12, 2023
4cb0337
feat(sdk-logs): update version
fuaiyi Apr 12, 2023
dcc1c6a
feat(sdk-logs): update version
fuaiyi Apr 12, 2023
0c3e7b3
feat(sdk-logs): update logs example with typescript
fuaiyi Apr 12, 2023
6d0cc64
feat(sdk-logs): update peerDependencies
fuaiyi Apr 12, 2023
e01b734
feat(sdk-logs): peer-api-check support @opentelemetry/api-logs
fuaiyi Apr 12, 2023
d8d8a95
feat(sdk-logs): update peerDependencies
fuaiyi Apr 12, 2023
fc2e666
Merge branch 'main' into logs-sdk
dyladan Apr 12, 2023
0c1c95a
Merge branch 'main' into logs-sdk
dyladan Apr 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the example is made to be typescript, it can be added to the lerna project and built with other examples to ensure it stays up to date.

Copy link
Contributor Author

@fuaiyi fuaiyi Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, I referred to other example codes that were implemented in JavaScript. I agree with your opinion, and I have modified them to be implemented in TypeScript. 0c3e7b3

"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