-
Notifications
You must be signed in to change notification settings - Fork 40
feat: opentelemetry sdk LoggerProvider #207
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
Open
yuzurihaaa
wants to merge
43
commits into
Workiva:master
Choose a base branch
from
yuzurihaaa:feat/logger-provider
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
dbda356
feat: LogRecord limits
yuzurihaaa 630f2cf
feat: LogRecord
yuzurihaaa 7119f8e
chore: fix comment
yuzurihaaa 6fb8422
chore: log record limit test
yuzurihaaa 69e4e18
feat: LogRecordProcessor
yuzurihaaa 79640fb
feat: NoopLogRecordProcessor
yuzurihaaa 8ff6c71
feat: LoggerConfig
yuzurihaaa d3d98e6
feat: Logger
yuzurihaaa f4b05aa
feat: LoggerProvider
yuzurihaaa ff5d1e3
feat: exports
yuzurihaaa 1e050b4
wip: change processors initialization from `const`
yuzurihaaa 5eed62e
wip: fix test
yuzurihaaa 99e374f
wip: fix import arrange
yuzurihaaa 38b2137
wip: attach copyright
yuzurihaaa 88eb916
wip: change from `api.SpanContext?` and `api.Context?` to non-null pr…
yuzurihaaa 014f087
wip: remove unused `includeTraceContext`
yuzurihaaa 96938b8
wip: opentelemetry as defaultLoggerName
yuzurihaaa 2a9a80a
wip: make log processors immutable
yuzurihaaa f0206c6
wip: make all variables private
yuzurihaaa 01636f9
wip: update limit to only create if value changes.
yuzurihaaa aae1c3e
wip: change from sdk.Attributes to List<api.Attribute>
yuzurihaaa 464a636
wip: change to `DateTime`
yuzurihaaa 2ea0fcf
wip: remove DateTime initialization
yuzurihaaa 078bd4a
wip: fix test
yuzurihaaa 90ecfdc
wip: remove `processors`
yuzurihaaa 4ab30a2
wip: remove `async` `await`
yuzurihaaa b3f744e
wip: changed to `FutureOr`
yuzurihaaa 9978329
wip: change forceFlush and shutdown to `void`
yuzurihaaa 849e0b0
wip: fix test
yuzurihaaa bebc35e
wip: change LogRecordLimits from abstract class to class
yuzurihaaa 032fd65
wip: avoid nullable values
yuzurihaaa 442b466
wip: mark protected
yuzurihaaa 3fc382e
wip: remove nullable and pass processors instead of callback.
yuzurihaaa f0e65ab
fix: failing unit test
yuzurihaaa b97de95
wip: remove NoopLogRecordProcessor
yuzurihaaa d9c0429
wip: inline
yuzurihaaa 37fae26
wip: limit list
yuzurihaaa b9598de
wip: onEmit ReadableLogRecord -> ReadWriteLogRecord
yuzurihaaa 741ed89
wip: update DateTimeProvider
yuzurihaaa b397a0a
wip: remove getters
yuzurihaaa f4c216b
wip: make fields private
yuzurihaaa 756b063
wip: update TimeProvider to use from review
yuzurihaaa d1d1f77
wip: remove _isReadonly check.
yuzurihaaa 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
There are no files selected for viewing
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
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
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
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,140 @@ | ||
// Copyright 2021-2022 Workiva. | ||
// Licensed under the Apache License, Version 2.0. Please see https://github.com/Workiva/opentelemetry-dart/blob/master/LICENSE for more information | ||
|
||
import 'package:meta/meta.dart'; | ||
import 'package:opentelemetry/api.dart' as api; | ||
import 'package:opentelemetry/sdk.dart' as sdk; | ||
import 'package:opentelemetry/src/experimental_api.dart' as api; | ||
import 'package:opentelemetry/src/experimental_sdk.dart' as sdk; | ||
import 'package:opentelemetry/src/sdk/common/limits.dart'; | ||
|
||
/// https://opentelemetry.io/docs/specs/otel/logs/sdk/#readwritelogrecord | ||
abstract class ReadableLogRecord { | ||
DateTime get timeStamp; | ||
|
||
DateTime get observedTimestamp; | ||
|
||
String get severityText; | ||
|
||
api.Severity get severityNumber; | ||
|
||
dynamic get body; | ||
|
||
sdk.Attributes get attributes; | ||
|
||
api.SpanContext get spanContext; | ||
|
||
sdk.Resource get resource; | ||
|
||
sdk.InstrumentationScope get instrumentationScope; | ||
|
||
int get droppedAttributesCount; | ||
} | ||
|
||
abstract class ReadWriteLogRecord extends ReadableLogRecord { | ||
set body(dynamic severity); | ||
|
||
set severityText(String severity); | ||
|
||
set severityNumber(api.Severity severity); | ||
} | ||
|
||
class LogRecord implements ReadWriteLogRecord { | ||
@override | ||
final sdk.InstrumentationScope instrumentationScope; | ||
|
||
final sdk.Resource _resource; | ||
|
||
final sdk.TimeProvider _timeProvider; | ||
final api.Context _context; | ||
final sdk.LogRecordLimits logRecordLimits; | ||
final DateTime? _timeStamp; | ||
final DateTime? _observedTimestamp; | ||
|
||
String _severityText; | ||
api.Severity _severityNumber; | ||
dynamic _body; | ||
int _totalAttributesCount = 0; | ||
|
||
final sdk.Attributes _attributes; | ||
|
||
@protected | ||
LogRecord({ | ||
blakeroberts-wk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
required this.instrumentationScope, | ||
required this.logRecordLimits, | ||
api.Severity? severityNumber, | ||
String? severityText, | ||
List<api.Attribute> attributes = const <api.Attribute>[], | ||
DateTime? timeStamp, | ||
DateTime? observedTimestamp, | ||
api.Context? context, | ||
dynamic body, | ||
sdk.Resource? resource, | ||
sdk.TimeProvider? timeProvider, | ||
}) : _severityText = severityText ?? api.Severity.unspecified.name, | ||
_resource = resource ?? sdk.Resource([]), | ||
_context = context ?? api.Context.current, | ||
_body = body, | ||
_attributes = sdk.Attributes.empty(), | ||
_severityNumber = severityNumber ?? api.Severity.unspecified, | ||
_timeStamp = timeStamp, | ||
_observedTimestamp = observedTimestamp, | ||
_timeProvider = timeProvider ?? sdk.DateTimeTimeProvider() { | ||
if (attributes.isNotEmpty) setAttributes(attributes); | ||
} | ||
|
||
|
||
@override | ||
sdk.Resource get resource => _resource; | ||
|
||
@override | ||
sdk.Attributes get attributes => _attributes; | ||
|
||
@override | ||
dynamic get body => _body; | ||
|
||
@override | ||
set body(dynamic body) { | ||
_body = body; | ||
} | ||
|
||
@override | ||
api.SpanContext get spanContext => api.spanContextFromContext(_context); | ||
|
||
@override | ||
int get droppedAttributesCount => _totalAttributesCount - attributes.length; | ||
|
||
@override | ||
DateTime get timeStamp => _timeStamp ?? DateTime.fromMicrosecondsSinceEpoch((_timeProvider.now ~/ 1000).toInt()); | ||
|
||
@override | ||
DateTime get observedTimestamp => | ||
_observedTimestamp ?? DateTime.fromMicrosecondsSinceEpoch((_timeProvider.now ~/ 1000).toInt()); | ||
|
||
@override | ||
api.Severity get severityNumber => _severityNumber; | ||
|
||
@override | ||
set severityNumber(api.Severity severity) { | ||
_severityNumber = severity; | ||
} | ||
|
||
@override | ||
String get severityText => _severityText; | ||
|
||
@override | ||
set severityText(String severity) { | ||
_severityText = severity; | ||
} | ||
|
||
void setAttributes(List<api.Attribute> attributes) { | ||
attributes.forEach(setAttribute); | ||
} | ||
|
||
void setAttribute(api.Attribute attribute) { | ||
if (attribute.key.isEmpty) return; | ||
if (logRecordLimits.attributeCountLimit == 0) return; | ||
_totalAttributesCount += 1; | ||
_attributes.add(applyAttributeLimitsForLog(attribute, logRecordLimits)); | ||
} | ||
} |
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,12 @@ | ||
// Copyright 2021-2022 Workiva. | ||
// Licensed under the Apache License, Version 2.0. Please see https://github.com/Workiva/opentelemetry-dart/blob/master/LICENSE for more information | ||
|
||
class LogRecordLimits { | ||
final int attributeCountLimit; | ||
final int attributeValueLengthLimit; | ||
|
||
const LogRecordLimits({ | ||
this.attributeCountLimit = 128, | ||
this.attributeValueLengthLimit = -1, | ||
}); | ||
} |
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,52 @@ | ||
// Copyright 2021-2022 Workiva. | ||
// Licensed under the Apache License, Version 2.0. Please see https://github.com/Workiva/opentelemetry-dart/blob/master/LICENSE for more information | ||
|
||
import 'package:meta/meta.dart'; | ||
import 'package:opentelemetry/api.dart' as api; | ||
import 'package:opentelemetry/sdk.dart' as sdk; | ||
import 'package:opentelemetry/src/api/context/context.dart'; | ||
import 'package:opentelemetry/src/experimental_api.dart' as api; | ||
import 'package:opentelemetry/src/experimental_sdk.dart' as sdk; | ||
|
||
class Logger extends api.Logger { | ||
final sdk.InstrumentationScope _instrumentationScope; | ||
final sdk.Resource _resource; | ||
final sdk.LogRecordLimits _logRecordLimits; | ||
final sdk.TimeProvider _timeProvider; | ||
final List<sdk.LogRecordProcessor> _processors; | ||
|
||
@protected | ||
Logger( | ||
this._instrumentationScope, | ||
this._logRecordLimits, | ||
this._timeProvider, | ||
this._processors, | ||
this._resource, | ||
); | ||
|
||
@override | ||
void emit({ | ||
List<api.Attribute> attributes = const [], | ||
Context? context, | ||
dynamic body, | ||
DateTime? observedTimestamp, | ||
api.Severity? severityNumber, | ||
String? severityText, | ||
DateTime? timeStamp, | ||
}) { | ||
final log = sdk.LogRecord( | ||
logRecordLimits: _logRecordLimits, | ||
resource: _resource, | ||
instrumentationScope: _instrumentationScope, | ||
context: context, | ||
severityText: severityText, | ||
severityNumber: severityNumber, | ||
attributes: attributes, | ||
body: body, | ||
timeProvider: _timeProvider, | ||
); | ||
for (final processor in _processors) { | ||
processor.onEmit(log); | ||
} | ||
} | ||
} |
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,14 @@ | ||
// Copyright 2021-2022 Workiva. | ||
// Licensed under the Apache License, Version 2.0. Please see https://github.com/Workiva/opentelemetry-dart/blob/master/LICENSE for more information | ||
|
||
// https://opentelemetry.io/docs/specs/otel/logs/sdk/#loggerconfig | ||
class LoggerConfig { | ||
/// If not explicitly set, | ||
/// the disabled parameter SHOULD default to false ( i.e. Loggers are enabled by default). | ||
/// If a Logger is disabled, it MUST behave equivalently to No-op Logger. | ||
final bool disabled; | ||
|
||
const LoggerConfig({ | ||
this.disabled = false, | ||
}); | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.