Skip to content

Commit

Permalink
Improved build process on Travis CI (#53)
Browse files Browse the repository at this point in the history
* Setting up the PHP_CodeSniffer

* Fixed code style

* Improved build process on Travis CI

* Add PHP 5.6 to allow_failures block

Refs:
#46 (comment)

* Moved all tests to the its own namespace

* Add jaeger-idl to the ignore paths

* Amended docs
  • Loading branch information
sergeyklay authored and jonahgeorge committed Aug 6, 2018
1 parent 57457a1 commit f32c1a3
Show file tree
Hide file tree
Showing 33 changed files with 271 additions and 81 deletions.
9 changes: 8 additions & 1 deletion .gitignore
@@ -1,8 +1,15 @@
.settings/
.settings
.buildpath
.project
.idea

jaeger-idl
vendor

composer.lock
composer.phar

jaeger-client-php.iml

phpunit.xml
phpcs.xml
26 changes: 24 additions & 2 deletions .travis.yml
@@ -1,12 +1,34 @@
sudo: false
dist: trusty

language: php

php:
- '5.6'
- '7.0'
- '7.1'
- '7.2'
- nightly

git:
depth: 1

matrix:
fast_finish: true
allow_failures:
- php: '5.6'
- php: nightly

install:
- composer install
- |
composer install \
--prefer-dist \
--no-interaction \
--no-ansi \
--no-progress \
--optimize-autoloader \
--no-suggest
script:
- vendor/bin/phpunit
- vendor/bin/phpcs
- vendor/bin/phpunit
13 changes: 8 additions & 5 deletions composer.json
@@ -1,25 +1,28 @@
{
"name": "jonahgeorge/jaeger-client-php",
"description": "Jaeger Bindings for PHP OpenTracing API",
"license": "MIT",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.0",
"php": "^5.6||^7.0",
"ext-sockets": "*",
"packaged/thrift": "0.10.0",
"opentracing/opentracing" : "1.0.0-beta5",
"phlib/base_convert": "^1.0",
"psr/log": "1.0.2",
"ext-sockets": "*"
"psr/log": "1.0.2"
},
"provide": {
"opentracing/opentracing": "1.0.0-beta5"
},
"require-dev": {
"phpunit/phpunit": "^6.4"
"phpunit/phpunit": "~5.6||^6.4",
"squizlabs/php_codesniffer": "3.*"
},
"autoload": {
"psr-4": {
"Jaeger\\": "src/Jaeger/"
"Jaeger\\": "src/Jaeger/",
"Jaeger\\Tests\\": "tests/Jaeger/"
},
"files": [
"./src/Jaeger/Constants.php"
Expand Down
37 changes: 37 additions & 0 deletions phpcs.xml.dist
@@ -0,0 +1,37 @@
<?xml version="1.0"?>
<ruleset name="Jaeger">

<!--
The name attribute of the ruleset tag is displayed
when running PHP_CodeSniffer with the -v command line
argument. The description tag below is not displayed anywhere
except in this file, so it can contain information for
developers who may change this file in the future.
-->
<description>The coding standard for Jaeger Client</description>

<!-- Show sniff codes in all reports -->
<arg value="s"/>

<!-- Use PSR-2 as a base -->
<rule ref="PSR2"/>

<!-- Uncomment to use colors in progress or report -->
<!-- arg name="colors" / -->

<!--
If no files or directories are specified on the command line
your custom standard can specify what files should be checked
instead.
Note that specifying any file or directory path
on the command line will ignore all file tags.
-->
<file>src</file>

<!--
You can hard-code ignore patterns directly into your
custom standard so you don't have to specify the
patterns on the command line.
-->
<exclude-pattern>src/Jaeger/Thrift/*</exclude-pattern>
</ruleset>
23 changes: 20 additions & 3 deletions src/Jaeger/Codec/BinaryCodec.php
Expand Up @@ -7,16 +7,33 @@

class BinaryCodec implements CodecInterface
{
/**
* {@inheritdoc}
*
* @see \Jaeger\Tracer::inject
*
* @param SpanContext $spanContext
* @param mixed $carrier
*
* @return void
*/
public function inject(SpanContext $spanContext, &$carrier)
{
throw new UnsupportedFormat('Binary encoding not implemented');
}

/**
* @return SpanContext|null
/**
* {@inheritdoc}
*
* @see \Jaeger\Tracer::extract
*
* @param mixed $carrier
* @return SpanContext|null
*
* @throws UnsupportedFormat
*/
public function extract($carrier)
{
throw new UnsupportedFormat('Binary encoding not implemented');
}
}
}
27 changes: 24 additions & 3 deletions src/Jaeger/Codec/CodecInterface.php
Expand Up @@ -6,10 +6,31 @@

interface CodecInterface
{
/**
* Handle the logic behind injecting propagation scheme specific information into the carrier
* (e.g. http request headers, amqp message headers, etc.).
*
* This method can modify the carrier.
*
* @see \Jaeger\Tracer::inject
*
* @param SpanContext $spanContext
* @param mixed $carrier
*
* @return void
*/
public function inject(SpanContext $spanContext, &$carrier);

/**
* @return SpanContext|null
/**
* Handle the logic behind extracting propagation-scheme specific information from carrier
* (e.g. http request headers, amqp message headers, etc.).
*
* This method must not modify the carrier.
*
* @see \Jaeger\Tracer::extract
*
* @param mixed $carrier
* @return SpanContext|null
*/
public function extract($carrier);
}
}
19 changes: 15 additions & 4 deletions src/Jaeger/Codec/TextCodec.php
Expand Up @@ -30,15 +30,24 @@ public function __construct(
string $traceIdHeader = TRACE_ID_HEADER,
string $baggageHeaderPrefix = BAGGAGE_HEADER_PREFIX,
string $debugIdHeader = DEBUG_ID_HEADER_KEY
)
{
) {
$this->urlEncoding = $urlEncoding;
$this->traceIdHeader = str_replace('_', '-', strtolower($traceIdHeader));
$this->baggagePrefix = str_replace('_', '-', strtolower($baggageHeaderPrefix));
$this->debugIdHeader = str_replace('_', '-', strtolower($debugIdHeader));
$this->prefixLength = strlen($baggageHeaderPrefix);
}

/**
* {@inheritdoc}
*
* @see \Jaeger\Tracer::inject
*
* @param SpanContext $spanContext
* @param mixed $carrier
*
* @return void
*/
public function inject(SpanContext $spanContext, &$carrier)
{
$carrier[$this->traceIdHeader] = $this->spanContextToString(
Expand All @@ -65,9 +74,11 @@ public function inject(SpanContext $spanContext, &$carrier)
}

/**
* Extract a span context from a carrier.
* {@inheritdoc}
*
* @see \Jaeger\Tracer::extract
*
* @param array|\Traversable $carrier
* @param mixed $carrier
* @return SpanContext|null
*
* @throws Exception
Expand Down
18 changes: 15 additions & 3 deletions src/Jaeger/Codec/ZipkinCodec.php
Expand Up @@ -18,8 +18,14 @@ class ZipkinCodec implements CodecInterface
const FLAGS_NAME = 'X-B3-Flags';

/**
* {@inheritdoc}
*
* @see \Jaeger\Tracer::inject
*
* @param SpanContext $spanContext
* @param array $carrier
* @param mixed $carrier
*
* @return void
*/
public function inject(SpanContext $spanContext, &$carrier)
{
Expand All @@ -32,7 +38,11 @@ public function inject(SpanContext $spanContext, &$carrier)
}

/**
* @param array $carrier
* {@inheritdoc}
*
* @see \Jaeger\Tracer::extract
*
* @param mixed $carrier
* @return SpanContext|null
*/
public function extract($carrier)
Expand All @@ -43,7 +53,9 @@ public function extract($carrier)
$flags = 0;

if (isset($carrier[strtolower(self::SAMPLED_NAME)])) {
if ($carrier[strtolower(self::SAMPLED_NAME)] === "1" || strtolower($carrier[strtolower(self::SAMPLED_NAME)] === "true")) {
if ($carrier[strtolower(self::SAMPLED_NAME)] === "1" ||
strtolower($carrier[strtolower(self::SAMPLED_NAME)] === "true")
) {
$flags = $flags | SAMPLED_FLAG;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Jaeger/Config.php
Expand Up @@ -157,7 +157,11 @@ private function getSampler(): SamplerInterface
*/
private function getLocalAgentSender(): UdpSender
{
$udp = new ThriftUdpTransport($this->getLocalAgentReportingHost(), $this->getLocalAgentReportingPort(), $this->logger);
$udp = new ThriftUdpTransport(
$this->getLocalAgentReportingHost(),
$this->getLocalAgentReportingPort(),
$this->logger
);

$transport = new TBufferedTransport($udp, $this->getMaxBufferLength(), $this->getMaxBufferLength());
try {
Expand Down
2 changes: 1 addition & 1 deletion src/Jaeger/Constants.php
Expand Up @@ -86,7 +86,7 @@

const DEFAULT_SAMPLING_PORT = 5778;

const LOCAL_AGENT_DEFAULT_ENABLED = True;
const LOCAL_AGENT_DEFAULT_ENABLED = true;

const ZIPKIN_SPAN_FORMAT = 'zipkin-span-format';

Expand Down
1 change: 1 addition & 0 deletions src/Jaeger/Sampler/ConstSampler.php
@@ -1,6 +1,7 @@
<?php

namespace Jaeger\Sampler;

use const Jaeger\SAMPLER_PARAM_TAG_KEY;
use const Jaeger\SAMPLER_TYPE_CONST;
use const Jaeger\SAMPLER_TYPE_TAG_KEY;
Expand Down
3 changes: 2 additions & 1 deletion src/Jaeger/Sender/UdpSender.php
Expand Up @@ -167,7 +167,8 @@ private function addZipkinAnnotations(JaegerSpan $span, Endpoint $endpoint)
$host = $this->makeEndpoint(
$span->peer['ipv4'] ?? 0,
$span->peer['port'] ?? 0,
$span->peer['service_name'] ?? '');
$span->peer['service_name'] ?? ''
);

$key = ($isClient) ? self::SERVER_ADDR : self::CLIENT_ADDR;

Expand Down
5 changes: 2 additions & 3 deletions src/Jaeger/Span.php
Expand Up @@ -88,8 +88,7 @@ public function __construct(
string $operationName,
array $tags = [],
$startTime = null
)
{
) {
$this->context = $context;
$this->tracer = $tracer;

Expand Down Expand Up @@ -205,7 +204,7 @@ public function overwriteOperationName($newOperationName)
/**
* {@inheritdoc}
*
* @param array|\Traversable $tags
* @param array $tags
* @return void
*/
public function setTags($tags)
Expand Down
8 changes: 7 additions & 1 deletion src/Jaeger/SpanContext.php
Expand Up @@ -67,7 +67,13 @@ public function getBaggageItem($key)
*/
public function withBaggageItem($key, $value)
{
return new self($this->traceId, $this->spanId, $this->parentId, $this->flags, [$key => $value] + $this->baggage);
return new self(
$this->traceId,
$this->spanId,
$this->parentId,
$this->flags,
[$key => $value] + $this->baggage
);
}

public function getTraceId()
Expand Down
7 changes: 4 additions & 3 deletions src/Jaeger/ThriftUdpTransport.php
Expand Up @@ -58,7 +58,7 @@ public function isOpen()
public function open()
{
$ok = @socket_connect($this->socket, $this->host, $this->port);
if ($ok === FALSE) {
if ($ok === false) {
throw new TTransportException('socket_connect failed');
}
}
Expand All @@ -75,9 +75,10 @@ public function close()
/**
* Read some data into the array.
*
* @todo
*
* @param int $len How much to read
* @return string The data that has been read
* @throws TTransportException if cannot read any more data
*/
public function read($len)
{
Expand All @@ -96,7 +97,7 @@ public function write($buf)
}

$ok = @socket_write($this->socket, $buf);
if ($ok === FALSE) {
if ($ok === false) {
throw new TTransportException('socket_write failed');
}
}
Expand Down

0 comments on commit f32c1a3

Please sign in to comment.