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

Adds http transport #9

Merged
merged 5 commits into from
Mar 14, 2018
Merged

Adds http transport #9

merged 5 commits into from
Mar 14, 2018

Conversation

jcchavezs
Copy link
Contributor

This PR includes the HTTP transport and a test against the actual agent.

@jcchavezs jcchavezs force-pushed the adds_http_transport branch 4 times, most recently from a4726b1 to d27d4a2 Compare March 1, 2018 17:13
@palazzem palazzem added the 🍏 core Changes to the core tracing functionality label Mar 6, 2018
@palazzem palazzem added this to the 0.1.0 milestone Mar 6, 2018
Copy link
Contributor

@kevinlebrun kevinlebrun left a comment

Choose a reason for hiding this comment

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

Some nitpick but overall GTM.

{
$tracesPayload = $this->encoder->encodeTraces($traces);

$headers = $this->headers + ['Content-Type' => $this->encoder->getContentType()];
Copy link
Contributor

Choose a reason for hiding this comment

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

It is already done inside sendRequest

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

sprintf('Reporting of spans failed, status code %d', $statusCode)
);
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Doing this check in reverse can reduce the indentation level and make the code a little bit easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion.

);
}
} else {
throw new RuntimeException(sprintf(
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 plan to intercept this exception inside the tracer or do you expect the developer to catch this exception?

Copy link
Contributor Author

@jcchavezs jcchavezs Mar 6, 2018

Choose a reason for hiding this comment

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

I prefer tracer to catch this and decide what to do with it: log it, increase metrics, etc.

Go returns the error https://github.com/DataDog/dd-trace-go/blob/master/tracer/transport.go#L108 and then send it over a channel: https://github.com/DataDog/dd-trace-go/blob/ba302ada363a5775d77da620ae9993f964b71f2a/tracer/tracer.go#L294 then logs the errors. Maybe we need an interface for ErrorHandler or something. @palazzem

Copy link
Contributor

Choose a reason for hiding this comment

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

To me it's fine till no exceptions must be handled by the user.

$tracer = new Tracer(new Noop);

$httpTransport = new Http(new Json, [
'endpoint' => 'http://0.0.0.0:8127/v0.3/traces'
Copy link
Contributor

Choose a reason for hiding this comment

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

Those tests assume you have an agent running. I wondering if this is a good idea to tag those tests with integration and let the possibility to run the complete test suite with and without external dependencies. Does it make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally, I first thought to launch the agent with docker-php but it is meant for PHP 7.1. I like the tag thing but not sure how to do it (you mean annotations?)

Anyways, ideally it could be:
composer test: composer unit-test && composer integration-test
composer unit-test: phpunit run tests\Unit
composer integration-test: phpunit run tests\Integration

Makes sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I was thinking about annotations. You can use @group (https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.group) for this purpose. Inside your phpunit.xml file you can then define test suites based on groups.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since tests are separated in folders I think it is just easier to use that to separate the execution as described below:

Anyways, ideally it could be:
composer test: composer unit-test && composer integration-test
composer unit-test: phpunit run tests\Unit
composer integration-test: docker run ... && phpunit run tests\Integration && docker stop ...

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Either way works for me.

working_directory: ~/datadog
steps:
- checkout
- run:
name: Install php-bcmath
command: sudo docker-php-ext-install bcmath
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be part of the README in a "requirements" section.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally what about postponing this for then it is time to write the README?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok.

@@ -48,11 +85,11 @@ private function spanToArray(Span $span)
}

if ($span->isFinished()) {
$arraySpan['duration_micro'] = 0;
$arraySpan['duration_micro'] = '-';
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer this way! It is clearer that a trick exists during the payload construction.

* @param string $hex
* @return string
*/
public function hex2dec($hex)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this should be public.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be private.

curl_close($handle);

if ($statusCode === 415) {
throw new RuntimeException('Reporting of spans failed, try with version 0.2');
Copy link
Contributor

Choose a reason for hiding this comment

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

The message is misleading there are no implementation for version 0.2 right now, is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, what should we say instead? Upgrade your agent? cc @palazzem

composer.json Outdated
"test-unit": "./vendor/bin/phpunit ./tests/Unit",
"test-integration":[
"echo \"Integration tests require the agent up and running. Use composer run-agent.\"",
"nc localhost 8126",
Copy link
Contributor

Choose a reason for hiding this comment

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

This directive will block if nothing is sent to nc. Did I miss something?

curl_close($handle);

if ($statusCode === 415) {
throw new RuntimeException('Reporting of spans failed, try with version 0.2');
Copy link
Contributor

Choose a reason for hiding this comment

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

who catches these RuntimeExceptions? anyway the message should suggest to upgrade the client library to the latest versions. 415 is unsupported media type that means the client is sending something maybe correct to the wrong endpoint so it's the client that should upgrade, not the agent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding these exceptions I am not sure how DD wants to deal with them. In zipkin we inject a metrics service where we report when the the send fails. In my experience, logging this errors floods the logs. Any ideas? cc @palazzem @kevinlebrun

@jcchavezs jcchavezs force-pushed the adds_http_transport branch 3 times, most recently from 95a7525 to cd3f4ec Compare March 12, 2018 17:25
Copy link
Contributor

@kevinlebrun kevinlebrun left a comment

Choose a reason for hiding this comment

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

LGTM

@jcchavezs jcchavezs merged commit fe401b5 into master Mar 14, 2018
@jcchavezs jcchavezs deleted the adds_http_transport branch March 14, 2018 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍏 core Changes to the core tracing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants