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

refactor: move traceId generation in Tracer instead of Span #154

Merged
merged 4 commits into from
Aug 7, 2019

Conversation

mayurkale22
Copy link
Member

Closes #151

@codecov-io
Copy link

codecov-io commented Aug 2, 2019

Codecov Report

Merging #154 into master will increase coverage by 1.66%.
The diff coverage is 98.96%.

@@            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
Impacted Files Coverage Δ
packages/opentelemetry-basic-tracer/src/Span.ts 88.4% <100%> (+28.27%) ⬆️
...ages/opentelemetry-basic-tracer/src/BasicTracer.ts 97.1% <100%> (+4.91%) ⬆️
...kages/opentelemetry-basic-tracer/test/Span.test.ts 100% <100%> (ø) ⬆️
...pentelemetry-basic-tracer/test/BasicTracer.test.ts 86.2% <97.56%> (+3.49%) ⬆️

@codecov-io
Copy link

Codecov Report

Merging #154 into master will increase coverage by 2.1%.
The diff coverage is 99.08%.

@@            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
Impacted Files Coverage Δ
packages/opentelemetry-basic-tracer/src/Span.ts 90% <100%> (+29.87%) ⬆️
...ages/opentelemetry-basic-tracer/src/BasicTracer.ts 95.27% <100%> (+3.08%) ⬆️
...kages/opentelemetry-basic-tracer/test/Span.test.ts 100% <100%> (ø) ⬆️
...pentelemetry-basic-tracer/test/BasicTracer.test.ts 86.2% <97.56%> (+3.49%) ⬆️
...oks/test/asynchooks/AsyncHooksScopeManager.test.ts
...ry-scope-async-hooks/src/AsyncHooksScopeManager.ts

@mayurkale22
Copy link
Member Author

/cc @draffensperger

this._startTime = options.startTime || performance.now();
this._spanContext = {
traceId,
spanId: randomSpanId(),
Copy link
Contributor

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)

Copy link
Contributor

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.)

Copy link
Member

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,
Copy link
Member

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

Copy link
Member Author

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);

Copy link
Member

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.

Copy link
Contributor

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,
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member Author

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.

Copy link
Member

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.

@mayurkale22 mayurkale22 merged commit 83480b7 into open-telemetry:master Aug 7, 2019
@mayurkale22 mayurkale22 deleted the issue#151 branch August 7, 2019 15:52
dyladan added a commit to dyladan/opentelemetry-js that referenced this pull request Sep 9, 2022
dyladan added a commit to dyladan/opentelemetry-js that referenced this pull request Sep 9, 2022
dyladan added a commit to dyladan/opentelemetry-js that referenced this pull request Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sdk: move traceId generation in Tracer instead of Span
6 participants