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

Improves readme. #10

Merged
merged 6 commits into from
Mar 23, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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
91 changes: 86 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,106 @@
# 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)
[![OpenTracing Badge](https://img.shields.io/badge/OpenTracing-enabled-blue.svg)](http://opentracing.io)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg)](https://php.net/)

PHP APM Client
Datadog APM client that implements an [OpenTracing](http://opentracing.io) Tracer.

## Install
## Installation

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

## Contribution
## Requirements

### Run tests
- PHP 5.6 or later
Copy link
Contributor

Choose a reason for hiding this comment

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

Miss bcmath extension. I know this is still wip but that way I don't forget :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


## Usage

In order to be familiar with tracing elements it is recommended to read the [OpenTracing specification](https://github.com/opentracing/specification/blob/master/specification.md).

### Creating a tracer

To start using the Datadog Tracer with the OpenTracing API, you should first initialize the tracer:

```php
use DDTrace\Encoders\Json;
use DDTrace\Propagators\TextMap;
use DDTrace\Tracer;
use DDTrace\Transport\Http;
use OpenTracing\Formats;

...

// Transport layer that communicates with the agent
$transport = new Http(new Json(), $logger, [
'endpoint_url' => 'http://localhost:8126/v0.3/traces',
]);

// Propagation for inject/extract contexts to/from the wire
$textMap = new TextMap();

// Config for tracer
$config = [
'service_name' => 'my_service',
'enabled' => true,
'global_tags' => ['host' => 'hostname'],
];

$tracer = new Tracer($transport, [
Copy link
Contributor

Choose a reason for hiding this comment

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

general design: can't we provide reasonable defaults to avoid all this configuration? it's quite long to configure the tracer. If it already has defaults, let's create an advanced section with this snippet and a simple "Getting Started" where you initialize the tracer with defaults + trace a code-block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tracer comes with all this defaults, the reason why I included it in the example was to show all accepted arguments in the config. We can definitively move them to a advanced config or simply add a link in the bottom to the actual code (which also includes information).

Formats\TEXT_MAP => $textMap,
$config,
]);

// Sets a global tracer (singleton). Ideally tracer should be
// injected as a dependency
GlobalTracer::set($tracer);
```

### Creating Spans

- [Starting a root span](https://github.com/opentracing/opentracing-php#starting-an-empty-trace-by-creating-a-root-span)
- [Starting a span for a given request](https://github.com/opentracing/opentracing-php#creating-a-span-given-an-existing-request)
- [Active span and scope manager](https://github.com/opentracing/opentracing-php#active-spans-and-scope-manager)
- [Creating a child span assigning parent manually](https://github.com/opentracing/opentracing-php#creating-a-child-span-assigning-parent-manually)
- [Creating a child span using automatic active span management](https://github.com/opentracing/opentracing-php#creating-a-child-span-using-automatic-active-span-management)
- [Using span options](https://github.com/opentracing/opentracing-php#using-span-options)

### Propagation of context

- [Serializing context to the wire](https://github.com/opentracing/opentracing-php#serializing-to-the-wire)
- [Deserializing context from the wire](https://github.com/opentracing/opentracing-php#deserializing-from-the-wire)
- [Propagation formats](https://github.com/opentracing/opentracing-php#propagation-formats)

### Flushing Spans to the agent

PHP as a request scoped language has no simple means to pass the collected spans data to a background process without blocking the main request thread/process. It is mandatory to execute the `Tracer::flush()` after the response is served to the client by using [`register_shutdown_function`](http://php.net/manual/en/function.register-shutdown-function.php).

```php
use OpenTracing\GlobalTracer;

$application->run();

register_shutdown_function(function() {
GlobalTracer::get()->flush();
});
```

## Contributing

### Run tests

```bash
composer test
```

### Fix lint

```
```bash
composer fix-lint
```

## Releasing

See [RELEASING](RELEASING.md) for more information on releasing new versions.
9 changes: 9 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Releasing DD Trace PHP

## Packagist Package

1. Create a GitHub release.

1. Click `Update` from the admin view of the [datadog/dd-trace][packagist] package.

[packagist]: https://packagist.org/packages/datadog/dd-trace
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"minimum-stability": "dev",
"require": {
"php": "^5.6||^7.0",
"ext-bcmath": "*",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kevinlebrun removed the dependency.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great!

"opentracing/opentracing": "1.0.0-beta2",
"symfony/polyfill": "~1.7.0",
"guzzlehttp/psr7": "^1.4@dev",
Expand All @@ -43,6 +42,9 @@
"DDTrace\\Tests\\": "./tests/"
}
},
"provide": {
"opentracing/opentracing": "1.0.0-beta2"
},
"scripts": {
"test": [
"@test-unit",
Expand Down
9 changes: 1 addition & 8 deletions src/DDTrace/Encoders/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,7 @@ private function encodeSpan(Span $span)
*/
private function hex2dec($hex)
{
$decimal = 0;
$len = strlen($hex);

for ($i = 1; $i <= $len; $i++) {
$decimal = bcadd($decimal, bcmul((string) hexdec($hex[$i - 1]), bcpow('16', (string) ($len - $i))));
}

return $decimal;
return base_convert($hex, 16, 10);
}

/**
Expand Down