Skip to content

Add Stackdriver Trace sample code for the doc #561

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

Merged
merged 3 commits into from
Mar 1, 2018
Merged

Conversation

tmatsuo
Copy link
Contributor

@tmatsuo tmatsuo commented Feb 28, 2018

@tmatsuo tmatsuo requested a review from bshaffer February 28, 2018 21:25
@@ -65,6 +65,7 @@ do
fi
fi
pushd ${DIR}
mkdir -p build/logs
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

}

# [START exporter_setup]
$exporter = new StackdriverExporter(
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not in the PSR coding standards, but I've been doing these like this, so it'd be better for internal sample consistency:

$exporter = new StackdriverExporter([
    'clientConfig' => [
        'projectId' => $projectId
    ]
]);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done (with the next commit)


function use_trace()
{
# [START span_with_closure]
Copy link
Contributor

Choose a reason for hiding this comment

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

The reference block here is off.. the END ref should be inside the function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

'projectId' => $projectId
]]);
# [END exporter_setup]
// For testing
Copy link
Contributor

Choose a reason for hiding this comment

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

How about this comment instead?

// When running tests, use a null exporter instead.

But a better question is, why not just use StackdriverExporter?

Or, in the tests, just call Trace::start(new NullExporter); before calling use_trace()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having integration test is good in general, but unfortunately now there's no way to fetch the trace from the API. I would just have the unit test like this for now.

Tracer::start($exporter);
# [END tracer_start]

function use_trace()
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like a more descriptive name for this function here. How about trace_callable()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@tmatsuo
Copy link
Contributor Author

tmatsuo commented Mar 1, 2018

@bshaffer Thanks, PTAL

@chingor13
Copy link
Member

LGTM

@tmatsuo tmatsuo merged commit f0b81fc into master Mar 1, 2018
@tmatsuo tmatsuo deleted the trace-sample branch March 1, 2018 20:08
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.

3 participants