-
Notifications
You must be signed in to change notification settings - Fork 16
AF-1541 additional timing granularity #116
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
Closed
+730
−17
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3ddcf31
add traces to basic transitions
toddbeckman-wf cabbdf6
track childOf for child modules
toddbeckman-wf 680c8f3
make opentracing a real dep
toddbeckman-wf 4f98ceb
example
toddbeckman-wf 40b58ef
remove todo
toddbeckman-wf e3e9734
make span names more generic and use span tags for module names
toddbeckman-wf c55f58a
AF-1540 allow consumer to specify useful state time
toddbeckman-wf cbab191
AF-1540 make start time the same
toddbeckman-wf b63cb9d
AF-1541 additional timing granularity
toddbeckman-wf 0194c78
actually commit files
toddbeckman-wf cf5b889
testing for tracing for everything but dispose
toddbeckman-wf 9e1920c
dont trace unload
toddbeckman-wf b62baca
Merge branch 'tracing_for_lifecycle_transitions' into AF-1540_consume…
toddbeckman-wf 7fc4d0f
active span can be null
toddbeckman-wf 5b4cf0d
Merge branch 'tracing_for_lifecycle_transitions' into AF-1540_consume…
toddbeckman-wf 1e5169c
enterFirstUsefulState should be protected
toddbeckman-wf 1d92e45
Merge branch 'AF-1540_consumer-specified-timing' into AF-1541_additio…
toddbeckman-wf 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import 'dart:async'; | ||
import 'package:opentracing/opentracing.dart'; | ||
|
||
class SampleSpan implements Span { | ||
static int _nextId = 0; | ||
final int _id = _nextId++; | ||
|
||
@override | ||
final List<Reference> references; | ||
|
||
@override | ||
final Map<String, dynamic> tags; | ||
|
||
@override | ||
final List<LogData> logData = []; | ||
|
||
@override | ||
final String operationName; | ||
|
||
@override | ||
SpanContext context; | ||
|
||
@override | ||
final DateTime startTime; | ||
DateTime _endTime; | ||
|
||
Completer<Span> _whenFinished = new Completer<Span>(); | ||
|
||
SampleSpan( | ||
this.operationName, { | ||
SpanContext childOf, | ||
this.references, | ||
DateTime startTime, | ||
Map<String, dynamic> tags, | ||
}) | ||
: this.startTime = startTime ?? new DateTime.now(), | ||
this.tags = tags ?? {} { | ||
if (childOf != null) { | ||
references.add(new Reference.childOf(childOf)); | ||
} | ||
setTag('span.kind', 'client'); | ||
|
||
final parent = parentContext; | ||
if (parent != null) { | ||
this.context = new SpanContext(spanId: _id, traceId: parent.traceId); | ||
this.context.baggage.addAll(parent.baggage); | ||
} else { | ||
this.context = new SpanContext(spanId: _id, traceId: _id); | ||
} | ||
} | ||
|
||
@override | ||
void addTags(Map<String, dynamic> newTags) => tags.addAll(newTags); | ||
|
||
@override | ||
Duration get duration => _endTime?.difference(startTime); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓Are consumers of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figure it's not important here because it's just in the examples. |
||
|
||
@override | ||
DateTime get endTime => _endTime; | ||
|
||
@override | ||
void finish({DateTime finishTime}) { | ||
if (_whenFinished == null) { | ||
return; | ||
} | ||
|
||
_endTime = finishTime ?? new DateTime.now(); | ||
_whenFinished.complete(this); | ||
_whenFinished = null; | ||
} | ||
|
||
@override | ||
void log(String event, {dynamic payload, DateTime timestamp}) => | ||
logData.add(new LogData(timestamp ?? new DateTime.now(), event, payload)); | ||
|
||
@override | ||
SpanContext get parentContext => | ||
references.isEmpty ? null : references.first.referencedContext; | ||
|
||
@override | ||
void setTag(String tagName, dynamic value) => tags[tagName] = value; | ||
|
||
@override | ||
Future<Span> get whenFinished => _whenFinished.future; | ||
|
||
@override | ||
String toString() { | ||
final sb = new StringBuffer('SampleSpan('); | ||
sb | ||
..writeln('traceId: ${context.traceId}') | ||
..writeln('spanId: ${context.spanId}') | ||
..writeln('operationName: $operationName') | ||
..writeln('tags: ${tags.toString()}') | ||
..writeln('startTime: ${startTime.toString()}'); | ||
|
||
if (_endTime != null) { | ||
sb | ||
..writeln('endTime: ${endTime.toString()}') | ||
..writeln('duration: ${duration.toString()}'); | ||
} | ||
|
||
if (logData.isNotEmpty) { | ||
sb.writeln('logData: ${logData.toString()}'); | ||
} | ||
|
||
if (references.isNotEmpty) { | ||
final reference = references.first; | ||
sb.writeln( | ||
'reference: ${reference.referenceType} ${reference.referencedContext.spanId}'); | ||
} | ||
|
||
sb.writeln(')'); | ||
|
||
return sb.toString(); | ||
} | ||
} | ||
|
||
class SampleTracer implements AbstractTracer { | ||
@override | ||
SampleSpan startSpan( | ||
String operationName, { | ||
SpanContext childOf, | ||
List<Reference> references, | ||
DateTime startTime, | ||
Map<String, dynamic> tags, | ||
}) { | ||
return new SampleSpan( | ||
operationName, | ||
childOf: childOf, | ||
references: references, | ||
startTime: startTime, | ||
tags: tags, | ||
) | ||
..whenFinished.then((span) { | ||
print(span.toString()); | ||
}); | ||
} | ||
|
||
@override | ||
Reference childOf(SpanContext context) => new Reference.childOf(context); | ||
|
||
@override | ||
Reference followsFrom(SpanContext context) => | ||
new Reference.followsFrom(context); | ||
|
||
@override | ||
SpanContext extract(String format, dynamic carrier) { | ||
throw new UnimplementedError( | ||
'Sample tracer for example purposes does not support advanced tracing behavior.'); | ||
} | ||
|
||
@override | ||
void inject(SpanContext spanContext, String format, dynamic carrier) { | ||
throw new UnimplementedError( | ||
'Sample tracer for example purposes does not support advanced tracing behavior.'); | ||
} | ||
|
||
@override | ||
Future<dynamic> flush() { | ||
return null; | ||
} | ||
} |
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.
This could introduce an issue if a consumer treats the returned
Future
directly.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.
I was just toying around with the examples and forgot to put it back. I'll probably do that before pushing for the reviews on this.