Skip to content

Activity Status support#47506

Merged
tarekgh merged 2 commits intodotnet:masterfrom
tarekgh:ActivityStatus
Jan 28, 2021
Merged

Activity Status support#47506
tarekgh merged 2 commits intodotnet:masterfrom
tarekgh:ActivityStatus

Conversation

@tarekgh
Copy link
Member

@tarekgh tarekgh commented Jan 27, 2021

Fixes #46689

@ghost
Copy link

ghost commented Jan 27, 2021

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@tarekgh
Copy link
Member Author

tarekgh commented Jan 27, 2021

@cijothomas @reyang could you please have a look? Thanks.

/// </remarks>
public Activity SetStatus(ActivityStatusCode code, string? description = null)
{
if (code <= ActivityStatusCode.Unset || code > ActivityStatusCode.Error)
Copy link
Member

Choose a reason for hiding this comment

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

Would it be easier to understand as just:

if (code != ActivityStatusCode.Ok && code != ActivityStatusCode.Error)

?

{
if (code <= ActivityStatusCode.Unset || code > ActivityStatusCode.Error)
{
throw new ArgumentException(SR.Format(SR.InvalidStatusCode, code), nameof(code));
Copy link
Member

Choose a reason for hiding this comment

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

ArgumentOutOfRangeExcception?

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 am not sure of that if they try Unset value. should this case considered out of range?

Copy link
Member

@noahfalk noahfalk Jan 27, 2021

Choose a reason for hiding this comment

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

What if we let them set any value they want and don't have this error condition at all?

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't see any reason why we want to prevent users from calling SetStatus(ActivityStatusCode.Unset). Only restriction is about Ignoring Description except for Error.

Copy link
Member Author

Choose a reason for hiding this comment

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

The Question now for @noahfalk suggestion. do you think we can allow any arbitrary values? I mean is it ok to use something like (ActivityStatusCode) (-10)?

@reyang as you were the one advocating for not allowing Unset, could you please respond if you have any objection allowing Unset to be set and what you think allowing any status code even not defined ones in ActivityStatusCode?

If all agrees, I can modify the code as follows:

  • Allow any status code to be set (including non defined values).
  • Any code not equal Error, I'll reset the status description to null.

Copy link
Contributor

Choose a reason for hiding this comment

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

I will refer to the spec https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#set-status.
My interpretation is that:

  • the default value is unset
  • instrumentation library could set it to error, with an optional description
  • others (e.g. application) could set it to ok, in this case there shouldn't be a description (so the description is set back to null)

Other cases should not happen, we can either ignore, throw exception, or fall back to a default behavior.

Copy link
Member Author

@tarekgh tarekgh Jan 27, 2021

Choose a reason for hiding this comment

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

I had offline discussion with @reyang and @cijothomas and here is the behavior we are going with:

  • We'll allow setting all status codes. That include Unset or even undefined values (e.g. (ActivityStatusCode)100).
  • Setting any code different than Error will reset the description to null.
  • The description can be non null only with Error code.
  • We'll never throw exceptions from setting the status.

I'll go ahead and update the code according to that.

{
if (code <= ActivityStatusCode.Unset || code > ActivityStatusCode.Error)
{
throw new ArgumentException(SR.Format(SR.InvalidStatusCode, code), nameof(code));
Copy link
Member

Choose a reason for hiding this comment

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

FWIW, I'm still not clear on why it's deemed acceptable to transition back and forth between Ok and Error but why it's not ok to transition to Unset.

Copy link
Member Author

Choose a reason for hiding this comment

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

@cijothomas @reyang may answer this better.

The specs says: Description MUST be IGNORED for StatusCode Ok & Unset values.. This means it is allowed to set Unset. Also, my current implementation is throwing in such cases. Should we just ignore the description in such cases as the specs suggest?

Copy link
Member

Choose a reason for hiding this comment

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

If the spec says these conditions are ok, and we're adding these to support the spec, I don't know why we'd add our own artificial limitations. (At that point, you don't even need this method and could just put setters on the properties.)

Copy link
Member Author

@tarekgh tarekgh Jan 27, 2021

Choose a reason for hiding this comment

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

I think we still need SetStatus. The reason is we need to reset the description message to null when setting the code to something different than Error. That is what the specs is requiring.

We can still do that in properties, but would confusing if setting one property changing the other comparing to SetStatus which already take description parameter which we can define and document the behavior there.

Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

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

LGTM

@tarekgh tarekgh merged commit 974e96b into dotnet:master Jan 28, 2021
@tarekgh tarekgh deleted the ActivityStatus branch January 28, 2021 00:03
@ghost ghost locked as resolved and limited conversation to collaborators Feb 27, 2021
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.

Add Status field to Activity API

5 participants