feat: ensure spans are non-null#680
Conversation
|
This would be semver major if existing user code must be changed in order to continue working. I haven't reviewed due to the DNR warning at the top, but my suspicion is that this is not semver major. |
|
@ofrobots I'll add an example of how it changed in the abstract shortly. I also think it's not, but wanted to make sure everyone was on the same page. |
Codecov Report
@@ Coverage Diff @@
## master #680 +/- ##
==========================================
- Coverage 90% 89.99% -0.02%
==========================================
Files 30 29 -1
Lines 1411 1419 +8
Branches 289 288 -1
==========================================
+ Hits 1270 1277 +7
- Misses 56 57 +1
Partials 85 85
Continue to review full report at Codecov.
|
8d50449 to
b23273e
Compare
|
|
||
| // This is only used in tests (and is temporary), so it doesn't apply in the | ||
| // comment in getRootContext about the possible values of namespace.get('root'). | ||
| // It's functionally identical to setRootContext(null). |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| // The span name will be of form "grpc:/[Service]/[MethodName]". | ||
| var span = api.createChildSpan({ name: 'grpc:' + method.path }); | ||
| if (!span) { | ||
| if (span.type !== api.spanTypes.CHILD) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| traceUtil.truncate(spanName, Constants.TRACE_SERVICE_SPAN_NAME_LIMIT); | ||
| this.span = new TraceSpan(spanName, randomSpanId(), parentSpanId); | ||
| trace.spans.push(this.span); | ||
| trace: Trace, spanName: string, parentSpanId: string, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| readonly span: TraceSpan; | ||
| readonly trace: Trace; | ||
| readonly type: SpanDataType.ROOT; | ||
| }|{ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
|
||
| // This is only used in tests (and is temporary), so it doesn't apply in the | ||
| // comment in getRootContext about the possible values of namespace.get('root'). | ||
| // It's functionally identical to setRootContext(null). |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| endSpan(): void; | ||
| } | ||
|
|
||
| // export type SpanData = RootSpanData|ChildSpanData; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * @returns The return value of calling fn. | ||
| */ | ||
| runInRootSpan<T>(options: RootSpanOptions, fn: (span: SpanData|null) => T): T; | ||
| runInRootSpan<T>(options: RootSpanOptions, fn: (span: SpanData) => T): T; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| traceUtil.truncate(spanName, Constants.TRACE_SERVICE_SPAN_NAME_LIMIT); | ||
| this.span = new TraceSpan(spanName, randomSpanId(), parentSpanId); | ||
| trace.spans.push(this.span); | ||
| trace: Trace, spanName: string, parentSpanId: string, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| // tslint:disable-next-line:no-any | ||
| addLabel(key: string, value: any) {}, | ||
| endSpan() {} | ||
| } as SpanData & {readonly type: T}); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| } | ||
|
|
||
| // Helper function to generate static virtual trace spans. | ||
| const createDummySpanData = |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| // The span name will be of form "grpc:/[Service]/[MethodName]". | ||
| var span = api.createChildSpan({ name: 'grpc:' + method.path }); | ||
| if (!span) { | ||
| if (span.type !== api.spanTypes.CHILD) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Note the example you provide in OP The test should be self-documenting. Right now you needed a comment to explain what the test is achieving. |
8e885e7 to
d4f2bfd
Compare
|
@ofrobots PTAL |
| import {Trace, TraceSpan} from './trace'; | ||
|
|
||
| export type RealRootContext = { | ||
| readonly span: TraceSpan; readonly trace: Trace; readonly type: SpanDataType |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| name: string; | ||
| spanId: string; | ||
| parentSpanId: string; | ||
| parentSpanId?: string; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Node 4 CI will pass in ~10 min (tests passed, but SSH connection is open) |
Fixes #656
This PR changes the public API so that spans are never null (in
runInRootSpanorcreateChildSpan). Instead, they now expose atypefield which represents whether they are real or "virtual spans". The code docs forSpanDataTypein this file should explain the purpose oftype.Open questions:
SpanData#typeneed to have distinctROOTandCHILDvalues?Example