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

Only set status of the root span on exit if an HTTP response code has been set #194

Merged
merged 2 commits into from
Jul 19, 2018

Conversation

klibbbs
Copy link
Contributor

@klibbbs klibbbs commented Jul 17, 2018

Hi!

I'd like to contribute a fix to prevent an invalid Status from being set on the root span when there is no available HTTP response code. When OpenCensus is used in a CLI context with the StackdriverExporter, the Stackdriver Trace API rejects the false status code (returned by http_response_code) as invalid.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@klibbbs
Copy link
Contributor Author

klibbbs commented Jul 17, 2018

Need to reproduce test failures locally and link CLA-authorized email to GitHub.

@klibbbs klibbbs closed this Jul 17, 2018
@klibbbs klibbbs reopened this Jul 17, 2018
@bogdandrutu
Copy link

Once you sign the CLA please reply "I signed it!"

@chingor13
Copy link
Member

@klibbbs The tests are failing when then c-extension is installed.

@klibbbs
Copy link
Contributor Author

klibbbs commented Jul 17, 2018

@bogdandrutu I'm operating under a corporate CLA that has already been signed, but I hadn't attached my organization email address to my public GitHub account when I first submitted this (it's attached now). Does it need to be visible?

@googlebot
Copy link

CLAs look good, thanks!

@klibbbs
Copy link
Contributor Author

klibbbs commented Jul 17, 2018

Thanks @chingor13, able to reproduce. Will update PR when I have a fix.

$this->assertEquals(200, $spanData->status()->code());
$this->assertEquals([Span::ATTRIBUTE_STATUS_CODE => 200], $spanData->attributes());

if (extension_loaded('opencensus')) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a bug in the extension that causes it to ignore status? If so, let's open another bug - the behavior when the extension is installed should be the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There appears to be no analogous concept of a Status object (or the status field, for that matter) on the span data maintained by the extension. Unlike other SpanData fields, status is set directly on a Span instead of via methods on Tracer. So when Span::setStatus is invoked on the root span on shutdown, there is no mechanism for propagating that to the state being tracked by the extension.

I'll submit a bug describing this, and I can outline some options for fixing the behavior, but I'm still relatively new to OpenCensus so I'm not that familiar with how opinionated it is on these features or whether it should match how the other language libraries do it, etc.

In the meantime, is this PR acceptable for addressing the issue with HTTP codes in a CLI context? The extension-dependent behavior of status being asserted in the unit test didn't actually change as part of this PR -- it's just being exposed in a test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Submitted Issue #196 to describe this

Copy link
Member

@chingor13 chingor13 left a comment

Choose a reason for hiding this comment

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

LGTM

@chingor13 chingor13 merged commit 39585f2 into census-instrumentation:master Jul 19, 2018
@Stantheman Stantheman mentioned this pull request Sep 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants