-
Notifications
You must be signed in to change notification settings - Fork 624
feat(instrumentation-winston): add log sending to Logs API #1837
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
Merged
hectorhdzg
merged 62 commits into
open-telemetry:main
from
hectorhdzg:hectorhdzg/winstonlogs
Mar 14, 2024
Merged
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
638c36d
Add recordLog emit
hectorhdzg d461556
Merge branch 'main' into hectorhdzg/winstonlogs
hectorhdzg 4ec2196
Readme lint
hectorhdzg 20f58ab
Merge branch 'hectorhdzg/winstonlogs' of https://github.com/hectorhdz…
hectorhdzg 01286b5
Update
hectorhdzg adc8f7a
Lint
hectorhdzg 7d24291
Merge branch 'main' into hectorhdzg/winstonlogs
hectorhdzg fe2bdbb
Update
hectorhdzg 1d4b91a
Merge branch 'main' into hectorhdzg/winstonlogs
hectorhdzg e76321b
Update
hectorhdzg d80c76a
Merge branch 'main' into hectorhdzg/winstonlogs
hectorhdzg 683c578
Lint
hectorhdzg ffa9f9b
Tests
hectorhdzg 441f72a
Added transports
hectorhdzg 6731e97
Add log appenders(Winston transports)
hectorhdzg 1c7ac82
Merge remote-tracking branch 'upstream/main' into hectorhdzg/winstonlogs
hectorhdzg c662cd0
Merge branch 'main' into hectorhdzg/winstonlogs
hectorhdzg 47db601
npm i
hectorhdzg 9d92764
Lint
hectorhdzg 6595727
Merge branch 'main' into hectorhdzg/winstonlogs
hectorhdzg 4c6e813
Merge branch 'main' into hectorhdzg/winstonlogs
hectorhdzg 4dc6dca
Updating dependencies and readme
hectorhdzg ff81990
Merge branch 'main' into hectorhdzg/winstonlogs
hectorhdzg 3800b1c
Update
hectorhdzg 54b7156
Merge remote-tracking branch 'upstream/main' into hectorhdzg/winstonlogs
hectorhdzg 8c730a5
npm i
hectorhdzg 13fce4d
Update dependencies
hectorhdzg 175a020
Update
hectorhdzg ca07f95
Update readme
hectorhdzg d4a84c4
Readme lint
hectorhdzg 7399017
Merge branch 'main' into hectorhdzg/winstonlogs
hectorhdzg 03b8ce7
Update
hectorhdzg 2d7704c
lint
hectorhdzg 091bddf
Update release manifest
hectorhdzg c447a6e
Addressing comments
hectorhdzg b57803c
npm i
hectorhdzg 574ac19
remove inspect break
hectorhdzg e74650c
Addressing comments
hectorhdzg 6247337
Update
hectorhdzg 3fa81c0
Update packages/winston-transport/README.md
hectorhdzg 3b43b31
Update plugins/node/opentelemetry-instrumentation-winston/README.md
hectorhdzg 5089079
Update packages/winston-transport/test/openTelemetryTransport.test.ts
hectorhdzg 69ae0ea
Update packages/winston-transport/README.md
hectorhdzg a2bb13e
Addressing comments
hectorhdzg fc39c78
Update component owners
hectorhdzg 51564b8
Update tav
hectorhdzg 2405492
Addressing comments
hectorhdzg c2dc4eb
Merge remote-tracking branch 'upstream/main' into hectorhdzg/winstonlogs
hectorhdzg 95d8a6a
Update logger name
hectorhdzg fb41f93
Merge remote-tracking branch 'upstream/main' into hectorhdzg/winstonlogs
hectorhdzg ec9da89
Merge branch 'hectorhdzg/winstonlogs' of https://github.com/hectorhdz…
hectorhdzg 1fe760d
Update
hectorhdzg 615c702
Merge branch 'main' into hectorhdzg/winstonlogs
hectorhdzg 8cf9b57
Merge remote-tracking branch 'upstream/main' into hectorhdzg/winstonlogs
hectorhdzg 064cba7
Update logs api dependency
hectorhdzg 9e9e7d1
Merge remote-tracking branch 'upstream/main' into hectorhdzg/winstonlogs
hectorhdzg fae82c9
Update
hectorhdzg 1750b3e
Merge branch 'main' into hectorhdzg/winstonlogs
hectorhdzg a36d4e8
Merge branch 'main' into hectorhdzg/winstonlogs
hectorhdzg a5e1ad6
Addressing comments
hectorhdzg 32fc1a2
Merge branch 'main' into hectorhdzg/winstonlogs
hectorhdzg 5e0291e
Lint
hectorhdzg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added transports
- Loading branch information
commit 441f72aacbaf0ab7027bf53fe80b75b22e80d47b
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,14 +59,14 @@ | |
| "sinon": "15.2.0", | ||
| "test-all-versions": "5.0.1", | ||
| "ts-mocha": "10.0.0", | ||
| "typescript": "4.4.4", | ||
| "winston": "3.3.3", | ||
| "winston2": "npm:[email protected]" | ||
| "typescript": "4.4.4" | ||
| }, | ||
| "dependencies": { | ||
| "@opentelemetry/api-logs": "^0.45.1", | ||
| "@opentelemetry/core": "1.18.1", | ||
| "@opentelemetry/instrumentation": "^0.45.1" | ||
| "@opentelemetry/instrumentation": "^0.45.1", | ||
| "winston": "3.3.3", | ||
| "winston2": "npm:[email protected]" | ||
trentm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-winston#readme" | ||
| } | ||
49 changes: 49 additions & 0 deletions
49
plugins/node/opentelemetry-instrumentation-winston/src/OpenTelemetryTransportv2.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * 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 { Logger, logs } from '@opentelemetry/api-logs'; | ||
| import * as winston from 'winston2'; | ||
| import { VERSION } from './version'; | ||
| import { emitLogRecord } from './utils'; | ||
|
|
||
| export class OpenTelemetryTransportv2 extends winston.Transport { | ||
| private _logger: Logger; | ||
|
|
||
| constructor(options: winston.TransportOptions) { | ||
| super(options); | ||
| this._logger = logs.getLogger( | ||
| '@opentelemetry/instrumentation-winston', | ||
| VERSION | ||
| ); | ||
| } | ||
|
|
||
| log(level: string, msg: string, meta: any, callback: Function) { | ||
| try { | ||
| const logRecord: Record<string, any> = { | ||
| level: level, | ||
| msg: msg, | ||
| meta: meta, | ||
| }; | ||
| emitLogRecord(logRecord, this._logger); | ||
| this.emit('logged'); | ||
| } catch (error) { | ||
| this.emit('warn', error); | ||
| } | ||
| if (callback) { | ||
| callback(null, true); | ||
| } | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
plugins/node/opentelemetry-instrumentation-winston/src/OpenTelemetryTransportv3.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * 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 { Logger, logs } from '@opentelemetry/api-logs'; | ||
| import * as Transport from 'winston-transport'; | ||
| import { VERSION } from './version'; | ||
| import { emitLogRecord } from './utils'; | ||
|
|
||
| export class OpenTelemetryTransportv3 extends Transport { | ||
| private _logger: Logger; | ||
|
|
||
| constructor(options: Transport.TransportStreamOptions) { | ||
| super(options); | ||
| this._logger = logs.getLogger( | ||
| '@opentelemetry/instrumentation-winston', | ||
| VERSION | ||
| ); | ||
| } | ||
|
|
||
| public override log(info: any, next: () => void) { | ||
| try { | ||
| emitLogRecord(info, this._logger); | ||
| this.emit('logged', info); | ||
hectorhdzg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } catch (error) { | ||
| this.emit('warn', error); | ||
| } | ||
| if (next) { | ||
| setImmediate(next); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most (all?) the winston@3 transports I see have a dependency just on
winston-transport. Could this be changed to only depend on it, and not take a runtime dependency onwinstonitself?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The guild here explains why instrumentations should not depend on the instrumented library.
I think the instrumentation has to find the winston-transport instances (there might be several of different versions) via the hooking mechanism used for patching. If this isn't possible some other mechanism should be used to avoid depending on the instrumented library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Flarna If this PR changes to dep on
winston-transportwould that satisfy the guidelines? This is instrumentingwinston, notwinston-transport.One possible use-case of this package -- as described at https://github.com/open-telemetry/opentelemetry-js-contrib/blob/4c6e81347bb1dbc0c87a0de484a48354cef46cb2/plugins/node/opentelemetry-instrumentation-winston/README.md#using-opentelemetrywinstontransport-without-instrumentation -- will be for a user to directly use the
OpenTelemetryTransportv3class to configure their Winston logger. In that case there isn't necessary an active Winston instrumentation. In other words, I don't think it is possible to rely on being able to getwinston-transportvia the hooking mechanism.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as
@opentelemetry/instrumentation-winstonis part of@opentelemetry/auto-instrumentations-nodeI would avoid such dependencies becauseMaybe we should remove winston instrumentation from
@opentelemetry/auto-instrumentations-node. OptIn will be likely done by winston users only.Or split packages into the "classic" instrumentation (part of auto package) and a V2 and a V3 transport extension (opt-in).