-
Notifications
You must be signed in to change notification settings - Fork 155
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
Conversation
a4726b1
to
d27d4a2
Compare
89e6d4c
to
f26964b
Compare
d7617bc
to
6c720b9
Compare
6c720b9
to
65ba6df
Compare
There was a problem hiding this 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.
src/DDTrace/Transport/Http.php
Outdated
{ | ||
$tracesPayload = $this->encoder->encodeTraces($traces); | ||
|
||
$headers = $this->headers + ['Content-Type' => $this->encoder->getContentType()]; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
src/DDTrace/Transport/Http.php
Outdated
sprintf('Reporting of spans failed, status code %d', $statusCode) | ||
); | ||
} | ||
} else { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion.
src/DDTrace/Transport/Http.php
Outdated
); | ||
} | ||
} else { | ||
throw new RuntimeException(sprintf( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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'] = '-'; |
There was a problem hiding this comment.
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.
src/DDTrace/Encoders/Json.php
Outdated
* @param string $hex | ||
* @return string | ||
*/ | ||
public function hex2dec($hex) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be private.
src/DDTrace/Transport/Http.php
Outdated
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.
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?
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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?
src/DDTrace/Transport/Http.php
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
who catches these RuntimeException
s? 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.
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
bdd6bbe
to
453e82c
Compare
95a7525
to
cd3f4ec
Compare
cd3f4ec
to
1902dd4
Compare
15bad5a
to
5d42770
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR includes the HTTP transport and a test against the actual agent.