Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

[Core] Enforce strictNullChecks #453

Conversation

mayurkale22
Copy link
Member

Fixes #348. This was the last package remaining for the enforcing strictNullChecks option.

Copy link
Contributor

@draffensperger draffensperger left a comment

Choose a reason for hiding this comment

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

This is great and represents a significant improvement in type safety for the library!!

I made a number of comments, but I do think that getting this enabled is important so if you don't have the time to do all the fixes, I could be open to committing this and then doing follow-up refactors over time.

packages/opencensus-core/src/metrics/metric-registry.ts Outdated Show resolved Hide resolved
@@ -39,21 +38,21 @@ export abstract class BasePlugin implements types.Plugin {
/** The module name */
protected moduleName: string;
/** A tracer object. */
protected tracer: modelTypes.Tracer;
protected tracer!: modelTypes.Tracer;
Copy link
Contributor

Choose a reason for hiding this comment

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

Normally I would discourage ! for properties like this, but I think it is worth it to get the strict null checks enforced.

I think ideally these would be initialized in the constructor for the plugin, but I'm guessing that would involve a bunch more refactoring.

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently users need to pass tracer instance, when enabling the plugins. It would need more work and breaking change in order to initialize same in the constructor.

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!

packages/opencensus-core/src/trace/model/span-base.ts Outdated Show resolved Hide resolved
packages/opencensus-core/src/trace/model/span-base.ts Outdated Show resolved Hide resolved
packages/opencensus-core/src/trace/model/span-base.ts Outdated Show resolved Hide resolved
packages/opencensus-core/src/trace/model/span-base.ts Outdated Show resolved Hide resolved
@@ -246,7 +246,7 @@ export interface SpanOptions {
parentSpanId?: string;
}

export type TraceState = string;
export type TraceState = string|undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

What would you think about instead making the places that use TraceState explicitly include |undefined (maybe even with a find/replace)?

I think making a type include undefined or null is kind of risks confusing people reading the code (and maybe even bugs) because when they see a type that naturally assume it wouldn't be null/undefined.

1. Assign default value to parentSpanId and name.
2. Assign default value({}) to activeTraceParams.
3. Add traceState back for no-record-span-base
@codecov-io
Copy link

codecov-io commented Mar 29, 2019

Codecov Report

Merging #453 into master will decrease coverage by 0.22%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #453      +/-   ##
==========================================
- Coverage   94.89%   94.66%   -0.23%     
==========================================
  Files         148      150       +2     
  Lines        9850     9737     -113     
  Branches      701      723      +22     
==========================================
- Hits         9347     9218     -129     
- Misses        503      519      +16
Impacted Files Coverage Δ
src/common/validations.ts 80% <0%> (-20%) ⬇️
src/trace/model/no-record/no-record-span.ts 54.54% <0%> (-12.13%) ⬇️
src/internal/clock.ts 85.71% <0%> (-5.2%) ⬇️
src/exporters/exporter-buffer.ts 91.66% <0%> (-3.58%) ⬇️
src/resource/resource.ts 87.23% <0%> (-3.47%) ⬇️
...zpages-frontend/page-handlers/rpcz.page-handler.ts 97.72% <0%> (-2.28%) ⬇️
src/trace/model/tracer.ts 85.71% <0%> (-1.33%) ⬇️
src/stats/view.ts 97.59% <0%> (-0.09%) ⬇️
src/http-stats.ts 100% <0%> (ø) ⬆️
test/test-root-span.ts 100% <0%> (ø) ⬆️
... and 29 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ca97ca3...958c997. Read the comment docs.

@mayurkale22
Copy link
Member Author

@draffensperger Finally, a build is passed and all comments are resolved. PTAL

Copy link
Contributor

@draffensperger draffensperger left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fixes!

@@ -39,21 +38,21 @@ export abstract class BasePlugin implements types.Plugin {
/** The module name */
protected moduleName: string;
/** A tracer object. */
protected tracer: modelTypes.Tracer;
protected tracer!: modelTypes.Tracer;
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!

@mayurkale22 mayurkale22 added this to the Release 0.0.10 milestone Mar 30, 2019
@mayurkale22 mayurkale22 merged commit 469d15a into census-instrumentation:master Mar 31, 2019
@mayurkale22 mayurkale22 deleted the enforce_strictNullcheck_core branch March 31, 2019 19:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants