|
1 | | -OpenTelemetry Instana Propagator |
| 1 | +[](https://github.com/opentelemetry-php/contrib-instana-exporter/releases) |
| 2 | +[](https://www.ibm.com/support/pages/instana-support) |
| 3 | +[](https://github.com/open-telemetry/opentelemetry-php-contrib/tree/main/src/Exporter/Instana) |
| 4 | +[](https://github.com/opentelemetry-php/contrib-instana-exporter) |
| 5 | +[](https://packagist.org/packages/open-telemetry/opentelemetry-instana-exporter/) |
| 6 | +[](https://packagist.org/packages/open-telemetry/opentelemetry-instana-exporter/) |
2 | 7 |
|
3 | | -The OpenTelemetry Propagator for Instana provides HTTP header propagation for systems that are using IBM Observability by Instana. |
4 | | -This propagator translates the Instana trace correlation headers (`X-INSTANA-T/X-INSTANA-S/X-INSTANA-L`) into the OpenTelemetry `SpanContext`, and vice versa. |
5 | | -It does not handle `TraceState`. |
| 8 | +This is a read-only subtree split of https://github.com/open-telemetry/opentelemetry-php-contrib. |
6 | 9 |
|
| 10 | +# Instana OpenTelemetry PHP Exporter |
7 | 11 |
|
8 | | -## Installation |
| 12 | +Instana exporter for OpenTelemetry. |
9 | 13 |
|
10 | | -```sh |
11 | | -composer require open-telemetry/opentelemetry-propagation-instana |
12 | | -``` |
13 | | - |
14 | | -## Usage |
| 14 | +## Documentation |
15 | 15 |
|
16 | | -``` |
17 | | -$propagator = InstanaMultiPropagator::getInstance(); |
18 | | -``` |
| 16 | +https://www.ibm.com/docs/en/instana-observability/current?topic=php-opentelemetry-exporter |
19 | 17 |
|
20 | | -Both of the above have extract and inject methods available to extract and inject respectively into the header. |
| 18 | +## Installing via Composer |
21 | 19 |
|
22 | | -## Propagator Details |
| 20 | +Install Composer in a common location or in your project |
23 | 21 |
|
24 | | -There are three headers that the propagator handles: `X-INSTANA-T` (the trace ID), `X-INSTANA-S` (the parent span ID), and `X-INSTANA-L` (the sampling level). |
| 22 | +```bash |
| 23 | +curl -s https://getcomposer.org/installer | php |
| 24 | +``` |
25 | 25 |
|
26 | | -Example header triplet: |
| 26 | +Install via Composer |
27 | 27 |
|
28 | | -* `X-INSTANA-T: 80f198ee56343ba864fe8b2a57d3eff7`, |
29 | | -* `X-INSTANA-S: e457b5a2e4d86bd1`, |
30 | | -* `X-INSTANA-L: 1`. |
| 28 | +```bash |
| 29 | +composer require instana/contrib-instana-exporter |
| 30 | +``` |
31 | 31 |
|
32 | | -A short summary for each of the headers is provided below. More details are available at <https://www.ibm.com/docs/en/obi/current?topic=monitoring-traces#tracing-headers>. |
| 32 | +## Usage |
33 | 33 |
|
34 | | -### X-INSTANA-T -- trace ID |
35 | 34 |
|
36 | | -* A string of either 16 or 32 characters from the alphabet `0-9a-f`, representing either a 64 bit or 128 bit ID. |
37 | | -* This header corresponds to the [OpenTelemetry TraceId](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#spancontext). |
38 | | -* If the propagator receives an X-INSTANA-T header value that is shorter than 32 characters when _extracting_ headers into the OpenTelemetry span context, it will left-pad the string with the character "0" to length 32. |
39 | | -* No length transformation is applied when _injecting_ the span context into headers. |
| 35 | +Utilizing the OpenTelemetry PHP SDK, we can send spans natively to Instana, by providing an OpenTelemetry span processor our `SpanExporterInterface`. |
40 | 36 |
|
41 | | -### X-INSTANA-S -- parent span ID |
| 37 | +This can be manually constructed, or created from the `SpanExporterFactory`. See the factory implementation for how to manually construct the `SpanExporter`. The factory reads from two environment variables which can be set according, else will fallback onto the following defaults |
42 | 38 |
|
43 | | -* Format: A string of 16 characters from the alphabet `0-9a-f`, representing a 64 bit ID. |
44 | | -* This header corresponds to the [OpenTelemetry SpanId](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#spancontext). |
| 39 | +```bash |
| 40 | +INSTANA_AGENT_HOST=127.0.0.1 |
| 41 | +INSTANA_AGENT_PORT=42699 |
| 42 | +``` |
45 | 43 |
|
46 | | -### X-INSTANA-L - sampling level |
| 44 | +The service name that is visible in the Instana UI can be configured with the following environment variables. OpenTelemetry provides `OTEL_SERVICE_NAME` (see documentation [here](https://opentelemetry.io/docs/languages/sdk-configuration/general/#otel_service_name)) as a way to customize this within the SDK. We also provide `INSTANA_SERVICE_NAME` which will be taken as the highest precedence. |
47 | 45 |
|
48 | | -* The only two valid values are `1` and `0`. |
49 | | -* A level of `1` means that this request is to be sampled, a level of `0` means that the request should not be sampled. |
50 | | -* This header corresponds to the sampling bit of the [OpenTelemetry TraceFlags](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#spancontext). |
| 46 | +```bash |
| 47 | +INSTANA_SERVICE_NAME=custom-service-name |
| 48 | +``` |
51 | 49 |
|
52 | | -## Useful links |
| 50 | +## Example |
53 | 51 |
|
54 | | -* For more information on Instana, visit <https://www.instana.com/> and [Instana' documentation](https://www.ibm.com/docs/en/obi/current). |
55 | | -* For more information on OpenTelemetry, visit: <https://opentelemetry.io/> |
| 52 | +```php |
| 53 | +use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor; |
| 54 | +use OpenTelemetry\SDK\Trace\TracerProvider; |
56 | 55 |
|
57 | | -## Installing dependencies and executing tests |
| 56 | +$tracerProvider = new TracerProvider( |
| 57 | + new SimpleSpanProcessor( |
| 58 | + Registry::spanExporterFactory("instana")->create() |
| 59 | + ) |
| 60 | +); |
| 61 | +$tracer = $tracerProvider->getTracer('io.instana.opentelemetry.php'); |
58 | 62 |
|
59 | | -From Instana subdirectory: |
| 63 | +$span = $tracer->spanBuilder('root')->startSpan(); |
| 64 | +$span->setAttribute('remote_ip', '1.2.3.4') |
| 65 | + ->setAttribute('country', 'CAN'); |
| 66 | +$span->addEvent('generated_session', [ |
| 67 | + 'id' => md5((string) microtime(true)), |
| 68 | +]); |
| 69 | +$span->end(); |
60 | 70 |
|
61 | | -``` sh |
62 | | -$ composer install |
63 | | -$ ./vendor/bin/phpunit tests |
| 71 | +$tracerProvider->shutdown(); |
64 | 72 | ``` |
| 73 | + |
| 74 | +## Contributions |
| 75 | + |
| 76 | +This repo is maintained by IBM Instana and is read-only. Issues and other contributions should be reported as part of standard [Instana product support](https://www.ibm.com/support/pages/instana-support). |
0 commit comments