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

Setup the project and the CI configuration. #1

Merged
merged 2 commits into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
version: 2.0

jobs:
"php-5.6":
docker:
- image: circleci/php:5.6
working_directory: ~/datadog
steps:
- checkout
- run: composer install -n
- run:
name: Run lint
command: composer lint
- run:
name: Run tests
command: composer test

"php-7.0":
docker:
- image: circleci/php:7.0
working_directory: ~/datadog
steps:
- checkout
- run: composer install
- run:
name: Run lint
command: composer lint
- run:
name: Run tests
command: composer test

"php-7.1":
docker:
- image: circleci/php:7.1
working_directory: ~/datadog
steps:
- checkout
- run: composer install
- run:
name: Run lint
command: composer lint
- run:
name: Run tests
command: composer test

"php-7.2":
docker:
- image: circleci/php:7.2
working_directory: ~/datadog
steps:
- checkout
- run: composer install
- run:
name: Run lint
command: composer lint
- run:
name: Run tests
command: composer test

workflows:
version: 2
build:
jobs:
- "php-5.6"
- "php-7.0"
- "php-7.1"
- "php-7.2"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor/
composer.lock
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
# dd-trace-php
Datadog PHP Tracer
# DD Trace PHP

[![CircleCI](https://circleci.com/gh/DataDog/dd-trace-php/tree/master.svg?style=svg)](https://circleci.com/gh/DataDog/dd-trace-php/tree/master)

PHP APM Client

## Install

```
composer require datadog/dd-trace
```

## Contribution

### Run tests

```
composer test
```

### Fix lint

```
composer fix-lint
```
44 changes: 44 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "datadog/dd-trace",
"description": "PHP APM Client",
"keywords": ["datadog", "php", "tracing"],
"type": "library",
"license": "BSD-3-Clause",
"authors": [
{
"name": "José Carlos Chávez",
"email": "jcchavezs@gmail.com"
},
{
"name": "DataDog",
"email": "dev@datadoghq.com",
"role": "Developer"
}
],
"minimum-stability": "dev",
"require": {
"opentracing/opentracing": "1.0.0-beta2"
},
"require-dev": {
"phpunit/phpunit": "~5.7.19",
"squizlabs/php_codesniffer": "3.*"
},
"autoload": {
"psr-4": {
"DDTrace\\": "./src/"
},
"files": [
"./src/DDTrace/MicroTime.php"
]
},
"autoload-dev": {
"psr-4": {
"DDTrace\\Tests\\": "./tests/"
}
},
"scripts": {
"test": "./vendor/bin/phpunit ./tests",
"lint": "./vendor/bin/phpcs --standard=ZEND --standard=PSR2 --ignore=*/vendor/* ./",
"fix-lint": "./vendor/bin/phpcbf --standard=ZEND --standard=PSR2 --ignore=*/vendor/* ./"
}
}
27 changes: 27 additions & 0 deletions src/DDTrace/MicroTime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Although DataDog uses nanotime to report spans PHP does not support nanotime
* plus, nanotime is a uint64 which is not supported either. Microtime will be used
* and there will be transformations in reporting in order to send nanotime.
*/
namespace DDTrace\MicroTime;

/**
* @return int
*/
function now()
{
return (int) (microtime(true) * 1000 * 1000);
}

/**
* @param mixed $microtime
* @return bool
*/
function isValid($microtime)
{
return
($microtime === (int) $microtime)
&& ctype_digit((string) $microtime)
&& strlen((string) $microtime) === 16;
}
35 changes: 35 additions & 0 deletions tests/Unit/MicroTimeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace DDTrace\Tests;

use DDTrace\MicroTime;

final class MicroTimeTest extends \PHPUnit_Framework_TestCase
{
public function testNowHasTheExpectedLength()
{
$now = MicroTime\now();
$this->assertEquals(16, strlen((string) $now));
}

/**
* @dataProvider microtimeProvider
*/
public function testIsValidHasTheExpectedOutput($microtime, $isValid)
{
$this->assertEquals($isValid, MicroTime\isValid($microtime));
}

public function microtimeProvider()
{
return [
[MicroTime\now(), true],
[1234567890123456, true],
[123456789012345, false],
['1234567890123456', false],
['123456789012345', false],
['123456789012345a', false],
['abcdefgh12345678', false]
];
}
}