Adds http transport#9
Conversation
a4726b1 to
d27d4a2
Compare
89e6d4c to
f26964b
Compare
d7617bc to
6c720b9
Compare
6c720b9 to
65ba6df
Compare
kevinlebrun
left a comment
There was a problem hiding this comment.
Some nitpick but overall GTM.
| { | ||
| $tracesPayload = $this->encoder->encodeTraces($traces); | ||
|
|
||
| $headers = $this->headers + ['Content-Type' => $this->encoder->getContentType()]; |
There was a problem hiding this comment.
It is already done inside sendRequest
| sprintf('Reporting of spans failed, status code %d', $statusCode) | ||
| ); | ||
| } | ||
| } else { |
There was a problem hiding this comment.
Doing this check in reverse can reduce the indentation level and make the code a little bit easier to read.
| ); | ||
| } | ||
| } else { | ||
| throw new RuntimeException(sprintf( |
There was a problem hiding this comment.
Do you plan to intercept this exception inside the tracer or do you expect the developer to catch this exception?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Either way works for me.
| - checkout | ||
| - run: | ||
| name: Install php-bcmath | ||
| command: sudo docker-php-ext-install bcmath |
There was a problem hiding this comment.
This should be part of the README in a "requirements" section.
There was a problem hiding this comment.
Totally what about postponing this for then it is time to write the README?
|
|
||
| if ($span->isFinished()) { | ||
| $arraySpan['duration_micro'] = 0; | ||
| $arraySpan['duration_micro'] = '-'; |
There was a problem hiding this comment.
I prefer this way! It is clearer that a trick exists during the payload construction.
| * @param string $hex | ||
| * @return string | ||
| */ | ||
| public function hex2dec($hex) |
There was a problem hiding this comment.
I'm not sure this should be public.
There was a problem hiding this comment.
It should be private.
| curl_close($handle); | ||
|
|
||
| if ($statusCode === 415) { | ||
| throw new RuntimeException('Reporting of spans failed, try with version 0.2'); |
There was a problem hiding this comment.
The message is misleading there are no implementation for version 0.2 right now, is it?
There was a problem hiding this comment.
Right, what should we say instead? Upgrade your agent? cc @palazzem
| "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", |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
bdd6bbe to
453e82c
Compare
95a7525 to
cd3f4ec
Compare
cd3f4ec to
1902dd4
Compare
15bad5a to
5d42770
Compare
This PR includes the HTTP transport and a test against the actual agent.