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

Change status codes from grpc status codes, remove setting status in instrumentations except on ERROR #1282

Merged
merged 25 commits into from
Oct 28, 2020

Conversation

lzchen
Copy link
Contributor

@lzchen lzchen commented Oct 26, 2020

Fixes #1214

Changes status canonical codes to comply with spec changes. Also changes behavior for setting status within instrumentations. The general idea is: instrumentations should not set status ever unless if an error happens. Span api/sdk should not set status either, so the only time that the span status is set to OK is by the user.

  1. Renames StatusCanonicalCode to StatusCode: Remove "canonical" adjective from Status Code opentelemetry-specification#1081
  2. Changes default StatusCode to UNSET.
  3. Change UNKNOWN to ERROR
  4. Change http_to_canonical_code to follow https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md#status
  5. On span creation, default status has status code StatusCode.UNSET. Do not set status to StatusCode.OK upon span end if not set.
  6. Instrumentations do not set status anymore except on ERROR

TODO:

  1. Fix otlpexporter/opencensusexporter mapping from statuscode once protobuf is updated.
  2. Add record_exception option to span __exit__
  3. Add set_status_on_exception parameter to start_as_current_span

@lzchen lzchen changed the title Consistent way for error handling with status codes Remove grpc status codes Oct 27, 2020
@lzchen lzchen marked this pull request as ready for review October 27, 2020 21:26
@lzchen lzchen requested review from a team, codeboten and toumorokoshi and removed request for a team October 27, 2020 21:26
Copy link
Contributor

@owais owais left a comment

Choose a reason for hiding this comment

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

Looks good on first pass. I see comments about removing status setting code from instrumentations. Spec says instrumentation should set status in case of errors. Is the idea that instrumenation should not catch exceptions and let tracer/span context handle the exeptions and record status? That sounds good but it should be a general guideline and not a hard rule as in some cases, it might make sense for instrumentation to set status anyway.

@@ -159,8 +160,12 @@ def _translate_links(self, sdk_span: SDKSpan) -> None:

def _translate_status(self, sdk_span: SDKSpan) -> None:
if sdk_span.status is not None:
# TODO: Update this when the proto definitions are updated to include UNSET and ERROR
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this TODO required for GA? If so, may be create an issue and link it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -109,12 +109,13 @@ async def traced_execution(
try:
result = await query_method(*args, **kwargs)
if span.is_recording():
span.set_status(Status(StatusCanonicalCode.OK))
# TODO: Remove setting status in instrumentation
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# TODO: Remove setting status in instrumentation
# TODO: Remove setting OK status in instrumentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's not exactly accurate. The TODO is removing any set_status in instrumentations that pertain to OK or UNSET. I should probably name it to remove setting non-ERROR status in instrumentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update: I made the changes and will be just removing the TODOs.

Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

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

Thanks! I think the one blocker for me is the field "canonical_code" still being in the codebase. Or let me know if that's intended.

@lzchen
Copy link
Contributor Author

lzchen commented Oct 28, 2020

@owais

Is the idea that instrumenation should not catch exceptions and let tracer/span context handle the exeptions and record status?

No that comment about instrumentations not recording status is few lines of code cleanup left to do for the instrumentations that I left so to not bloat up the PR (like here: https://github.com/open-telemetry/opentelemetry-python/pull/1282/files#r513361923). The general idea is: instrumentations should not set status ever unless if an error happens. Span api/sdk should not set status either, so the only time that the span status is set to OK is by the user. I updated the description to address this.

@lzchen
Copy link
Contributor Author

lzchen commented Oct 28, 2020

@owais

No that comment about instrumentations not recording status is few lines of code cleanup left to do for the instrumentations that I left so to not bloat up the PR

Update: I made the changes and will be just removing the TODOs.

@lzchen lzchen changed the title Remove grpc status codes Change status codes from grpc status codes, remove setting status in instrumentations except on ERROR Oct 28, 2020
Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

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

Thanks! I'd not the one change to eachdist that may be worth reverting.

tox.ini Outdated
@@ -369,7 +369,7 @@ commands_pre =
python scripts/eachdist.py install --editable --with-test-deps

commands =
python scripts/eachdist.py lint --check-only
python scripts/eachdist.py lint
Copy link
Member

Choose a reason for hiding this comment

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

will this command still fail on fixing styling commands? I think the reason this was --check-only was to use that tox command for CI, rather than for users trying to run lint / formatting rules.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry left it in by accident =p

"""Converts an HTTP status code to an OpenTelemetry canonical status code

Args:
status (int): HTTP status code
"""
# pylint:disable=too-many-branches,too-many-return-statements
# See: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md#status
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this section could be refactored to a much simpler tree of conditions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps. I left it in there just to show the possible httpstatuses.

@lzchen lzchen merged commit f3cdfa2 into open-telemetry:master Oct 28, 2020
@lzchen lzchen deleted the status branch October 28, 2020 21:29
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.

Update StatusCodes to comply with specs
3 participants