Wikia / opentracing-php

MIT License
11 stars 2 forks source link

Add idiomatic PHP injector/extractor #8

Open beberlei opened 8 years ago

beberlei commented 8 years ago

PHP uses $_SERVER superglobals to transmit HTTP headers, that means for joining a trace we could add an idiomatic PHP extractor:

$span = $tracer->join('some op', \OpenTracing\Propagation::SERVER_GLOBAL, $_SERVER);

This would require adding a constant for the default propagation mechanism:

class Propagation
{
    const SPLIT_TEXT = 'split_text';
    const SPLIT_BINARY = 'split_binary';
    const SERVER_GLOBAL = 'server_global';
}

The tracer can then just pick for example $_SERVER'['X_B3_TRACEID'], $_SERVER['X_B3_SPANID'] and $_SERVER['X_B3_PARENTSPANID'] for Zipkin, or anything else for other tracers.

Extra: If we make $carrier optional ($carrier = null) in join, the code could simpliy to:

$span = $tracer->join('some op', \OpenTracing\Propagation::SERVER_GLOBAL, $_SERVER);
wladekb commented 8 years ago

We definitely need to do something to streamline this popular use case. However I'm worried a bit about the details. The SERVER_GLOBAL would actually support only extracting. What should happen in case someone tries to inject the format SERVER_GLOBAL? Just an exception? Should we somehow document that?

Most of the time you'll use curl to call other HTTP services. It could also make perfect sense to create something like CURL for injecting. On the other hand most of the HTTP client libraries hide the curl handle and expose only methods like setHeaders(array $headers). Maybe an injector that would accept plain array as a carrier. That would help handle more cases in general.

@beberlei Ideas and comments welcome

beberlei commented 8 years ago

@wladekb i just saw that the kind of payload/carrier is changing again in opentracing-go's latest pull requests, so i guess we should wait anyways what will be going on.

beberlei commented 8 years ago

@wladekb ok, both SplitBinaryCarrier and SplitTextCarrier were completly removed, the only default way of importing is a Text Map now, and rather idomatic to Go.

I am wondering how we can do this in PHP, arrays spring to mind:

 $span = $tracer->join('some op', \OpenTracing\Propagation::ARRAY_MAP, $data);
 $tracer->inject($span, \OpenTracing\Propagation::ARRAY_MAP, $data);
wladekb commented 8 years ago

Propagating through arrays was my first idea implemented in the beginning but then I reworked that into the Split*Carrier. We're coming back to the roots ;-)