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

Add no-op implementations of Tracer API #98

Merged
merged 4 commits into from
Jul 17, 2019

Conversation

mayurkale22
Copy link
Member

@mayurkale22 mayurkale22 commented Jul 11, 2019

Closes #86

This is still work in progress as some dependencies are not yet merged (especially BinaryFormat (merged now) and HttpTraceContext(merged now) PRs) but it should provide a starting point and avoid blocking other work. Comments are welcome.

/**
* No-op implementations of {@link Tracer}.
*/
export class NoopTracer implements Tracer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that NOOP_SPAN is useful to return for non-sampled cases, but what would be the use case for NoopTracer?

If it's intended to just get some code started, what would you think about calling this TracerBase or similar? Would this be the class that eventually takes a scope storage in the constructor?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason for NoopTracer, at least for us, is when users disable the tracer then the implementation is switched to the noop to avoid unnecessary overhead. The noop tracer then uses only noop classes for the entire API surface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, makes sense!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on @rochdev comment (#98 (comment))

And In OpenTracing there is a concept of Global tracer (which user can set using initGlobalTracer() function). AFAIK Global tracer (global.Tracer()) should return minimal Tracer - NoopTracer if the app chooses to NOT use the SDK like basic-tracer or auto-tracer or vendor specific.

span: Span,
fn: T
): ReturnType<T> {
throw new Error('Method not implemented.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tracer should never throw.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, added @todo for now (dependency on #100).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should discuss it on our next SIG the similar conversation here:
#99 (comment)

packages/opentelemetry-core/test/trace/NoopTracer.test.ts Outdated Show resolved Hide resolved
import { NOOP_BINARY_FORMAT } from '../context/propagation/NoopBinaryFormat';
import { NoopSpan } from './NoopSpan';

export const NOOP_SPAN = new NoopSpan({ traceId: '', spanId: '' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, Done. PTAL

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we accomplish a similar thing by having say exprot const INVALID_TRACE_ID = '' and export const INVALID_SPAN_ID = '' in some authoritative place, maybe in the types package?

Copy link
Member Author

@mayurkale22 mayurkale22 Jul 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing is used in other PR : https://github.com/open-telemetry/opentelemetry-js/pull/102/files#diff-08ac79b280d2466a4fa3ffa58f1caed6R21

Will rebase, which ever is approved later.

@codecov-io
Copy link

codecov-io commented Jul 15, 2019

Codecov Report

Merging #98 into master will decrease coverage by 0.06%.
The diff coverage is 98.19%.

@@            Coverage Diff             @@
##           master      #98      +/-   ##
==========================================
- Coverage   98.67%   98.61%   -0.07%     
==========================================
  Files          21       26       +5     
  Lines        1511     1732     +221     
  Branches      173      193      +20     
==========================================
+ Hits         1491     1708     +217     
- Misses         20       24       +4
Impacted Files Coverage Δ
...core/src/context/propagation/NoopHttpTextFormat.ts 100% <100%> (ø)
...s/opentelemetry-core/test/trace/NoopTracer.test.ts 100% <100%> (ø)
...y-core/src/context/propagation/NoopBinaryFormat.ts 100% <100%> (ø)
...ackages/opentelemetry-core/src/trace/NoopTracer.ts 100% <100%> (ø)
.../opentelemetry-core/src/trace/spancontext-utils.ts 88.57% <88.57%> (ø)

@mayurkale22 mayurkale22 merged commit ca96178 into open-telemetry:master Jul 17, 2019
@mayurkale22 mayurkale22 deleted the noopTracer branch July 17, 2019 23:36
*/

export const INVALID_SPANID = '0';
export const INVALID_TRACEID = '0';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be fully padded values? To my knowledge, there aren't many ways a single '0' can sneak into a span 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.

I think the idea was if we are not able to extract the SpanContext correctly, then assign INVALID_SPAN_CONTEXT with INVALID_TRACEID(0) and INVALID_SPANID(0).

Just noticed, in the HTTP plugin we are using _emptySpanContext, ideally we should have used INVALID_SPAN_CONTEXT there.

/cc @dyladan @obecny

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.

Add no-op implementations of Tracer API
6 participants