-
Notifications
You must be signed in to change notification settings - Fork 793
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
refactor: move traceId generation in Tracer instead of Span #154
Conversation
Codecov Report
@@ Coverage Diff @@
## master #154 +/- ##
=========================================
+ Coverage 93.84% 95.5% +1.66%
=========================================
Files 41 41
Lines 3282 3317 +35
Branches 385 383 -2
=========================================
+ Hits 3080 3168 +88
+ Misses 202 149 -53
|
Codecov Report
@@ Coverage Diff @@
## master #154 +/- ##
=========================================
+ Coverage 93.84% 95.94% +2.1%
=========================================
Files 41 39 -2
Lines 3282 3083 -199
Branches 385 342 -43
=========================================
- Hits 3080 2958 -122
+ Misses 202 125 -77
|
/cc @draffensperger |
this._startTime = options.startTime || performance.now(); | ||
this._spanContext = { | ||
traceId, | ||
spanId: randomSpanId(), |
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 realize we need to wait for the spec, but here's to wishing there were a way to optionally specify this line! (Needed for browser initial load tracing)
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.
What is the behavior you would like to see? (Just confused to what this comment is referring to in the code.)
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.
In reference to this comment: open-telemetry/oteps#8 (comment)
this, | ||
name, | ||
traceId, | ||
options.kind || types.SpanKind.INTERNAL, |
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.
rather than deconstructing the context, can we create and pass in the context the span will use? e.g.
let context = new SpanContext()
if (!parentContext) {
context.traceId = randomTraceID();
} else {
context.traceId = parentContext.traceId
context.parentSpanId = parentContext.spanId;
// tracestate
}
and in the span constructor
if (context.spanId == null) {
context.spanId = randomSpanID()
}
this._spanContext = context
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.
@bg451 What do you think about this?
let parentSpanContext = this._getParentSpanContext(options.parent);
if (!parentSpanContext || !isValid(parentSpanContext)) {
// New root span.
parentSpanContext = { traceId: randomTraceId(), spanId: '' };
}
const span = new Span(this, name, parentSpanContext,
options.kind || types.SpanKind.INTERNAL,options.startTime);
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.
Sweet yeah that looks great, thanks!
I saw question in an email about what problem this solves, the answer is that I mostly want to reduce argument bloat. Additionally if any new fields get added to the span context object, it's another place that needs to be updated.
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.
@bg451 - yes that was me, thank you. It became obvious Mayurs solution so I deleted my remark.
@@ -42,21 +42,19 @@ export class Span implements types.Span { | |||
constructor( | |||
parentTracer: types.Tracer, | |||
spanName: string, | |||
traceId: string, | |||
parentSpanContext: SpanContext, |
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.
Why not simply pass the actual SpanContext
that will be used at that point? Meaning it's not the parent that is passed, but you are basically passing the context that the span will itself use directly. If you don't have a parent span ID, I feel it's incorrect to pass it as being a parent.
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.
Hmm, which means spanId
should be created by the tracer and we need to pass parentSpanId seperately (as a optional param) right?
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.
After thinking it over it makes sense to me to pass actual SpanContext
. ptal again.
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 new implementation is not actually what I had in mind, but in any case this is an implementation detail that can be changed, so let's go forward with this for now.
Closes #151