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

Tracing: Add code and message to Span -> Status #328

Merged
merged 3 commits into from
Feb 6, 2019

Conversation

mayurkale22
Copy link
Member

Fixes #327

@mayurkale22 mayurkale22 changed the title Add code and message to Span->Status Tracing: Add code and message to Span->Status Feb 5, 2019
@mayurkale22 mayurkale22 changed the title Tracing: Add code and message to Span->Status Tracing: Add code and message to Span -> Status Feb 5, 2019
@codecov-io
Copy link

codecov-io commented Feb 5, 2019

Codecov Report

Merging #328 into master will increase coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #328      +/-   ##
========================================
+ Coverage   94.95%    95%   +0.04%     
========================================
  Files         119    120       +1     
  Lines        8172   8202      +30     
  Branches      732    730       -2     
========================================
+ Hits         7760   7792      +32     
+ Misses        412    410       -2
Impacted Files Coverage Δ
src/http.ts 89.23% <0%> (-0.58%) ⬇️
src/zpages.ts 91.04% <0%> (-0.51%) ⬇️
src/adapters.ts 96.87% <0%> (-0.07%) ⬇️
src/index.ts 100% <0%> (ø) ⬆️
src/trace/model/span-base.ts 100% <0%> (ø) ⬆️
test/test-span.ts 100% <0%> (ø) ⬆️
src/grpc.ts 93.78% <0%> (ø) ⬆️
src/trace/model/types.ts 100% <0%> (ø)
test/test-grpc.ts 99.58% <0%> (ø) ⬆️
test/test-http.ts 99.43% <0%> (ø) ⬆️
... and 2 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 94cc98c...5741699. Read the comment docs.

*/
setStatus(code: number, message?: string) {
this.status.code = code;
if (message) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If someone sets a new code but no message, would this check leave the old message assigned to status?

Could this function just be this.status = {code, message}, since we the message field is optional?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! Done.

* with an optional descriptive message.
*/
export interface Status {
/** The status code. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add in the comment that this status code should correspond with a specific set of OpenCensus trace status codes and that HTTP status codes should be appropriately converted per the specs at https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/HTTP.md#mapping-from-http-status-codes-to-trace-status-codes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done as per #328 (comment).

/**
* Should set a status
*/
describe('addStatus()', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: 'setStatus'

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

rootSpan.start();
const span = new Span(rootSpan);
span.start();
span.setStatus(400, 'This is an error');
Copy link
Contributor

Choose a reason for hiding this comment

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

Per comment about about the canonical values, could this be a number like span.SetSTatus('3', 'Invalid argument') ?

/** A developer-facing error message. */
message?: string;
}

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 adding an enum with the list of OpenCensus status codes from the table referenced above?

Copy link
Contributor

Choose a reason for hiding this comment

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

To be clear I'm not suggesting the type of the code field be the enum (that might limit clients of the library if a new status is added but they can't upgrade yet, and for opencensus-web I want to keep @opencensus/core just as a dev dependency). But just having the enum provides documentation for what the possible canonical status codes are.

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 checked in Java implementation, we are using enum for code -> https://github.com/census-instrumentation/opencensus-java/blob/master/api/src/main/java/io/opencensus/trace/Status.java#L384. This is also matching with status spec.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I'd be fine with using an enum for it.

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 pending a couple new comments

@@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
- Add ignoreIncomingPaths and ignoreOutgoingUrls support to the http and https tracing instrumentations.
- Add ```opencensus-resource-util``` to auto detect AWS, GCE and Kubernetes(K8S) monitored resource, based on the environment where the application is running.
- Add optional `uncompressedSize` and `compressedSize` fields to `MessageEvent` interface.
- Add a ```setStatus``` method in the Span.

**This release has multiple breaking changes. Please test your code accordingly after upgrading.**
Copy link
Contributor

Choose a reason for hiding this comment

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

Should you mention that the status field on Span is no longer a number, since that's a breaking change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -258,4 +258,35 @@ describe('Span', () => {
assert.ok(instanceOfLink(span.messageEvents[0]));
});
});

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: what would you think about removing this comment? I personally find it a bit redundant with the describe('setStatus

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@@ -219,15 +219,15 @@ export class GrpcPlugin extends BasePlugin {
// tslint:disable-next-line:no-any
value: any, trailer: grpcTypes.Metadata, flags: grpcTypes.writeFlags) {
if (err) {
rootSpan.status = GrpcPlugin.convertGrpcStatusToSpanStatus(err.code);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to make similar changes to HttpPlugin.convertTraceStatus to make use of this new enum?

See:

static convertTraceStatus(statusCode: number): number {

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! I think I got lost in the changes there and did not look closely enough.

@mayurkale22
Copy link
Member Author

Thanks @draffensperger for the reviews.

@mayurkale22 mayurkale22 merged commit 57b1da5 into census-instrumentation:master Feb 6, 2019
@mayurkale22 mayurkale22 deleted the set_status branch February 6, 2019 18:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants