Skip to content

Commit e6c283a

Browse files
committed
Initial commit to add Instana Propagator
1 parent e201e11 commit e6c283a

File tree

12 files changed

+1200
-0
lines changed

12 files changed

+1200
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
* text=auto
2+
3+
*.md diff=markdown
4+
*.php diff=php
5+
6+
/.gitattributes export-ignore
7+
/.gitignore export-ignore
8+
/.php-cs-fixer.php export-ignore
9+
/phpstan.neon.dist export-ignore
10+
/phpunit.xml.dist export-ignore
11+
/psalm.xml.dist export-ignore
12+
/tests export-ignore

src/Propagation/Instana/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor/

src/Propagation/Instana/.phan/config.php

Lines changed: 371 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
$finder = PhpCsFixer\Finder::create()
3+
->exclude('vendor')
4+
->exclude('var/cache')
5+
->in(__DIR__);
6+
7+
$config = new PhpCsFixer\Config();
8+
return $config->setRules([
9+
'concat_space' => ['spacing' => 'one'],
10+
'declare_equal_normalize' => ['space' => 'none'],
11+
'is_null' => true,
12+
'modernize_types_casting' => true,
13+
'ordered_imports' => true,
14+
'php_unit_construct' => true,
15+
'single_line_comment_style' => true,
16+
'yoda_style' => false,
17+
'@PSR2' => true,
18+
'array_syntax' => ['syntax' => 'short'],
19+
'blank_line_after_opening_tag' => true,
20+
'blank_line_before_statement' => true,
21+
'cast_spaces' => true,
22+
'declare_strict_types' => true,
23+
'type_declaration_spaces' => true,
24+
'include' => true,
25+
'lowercase_cast' => true,
26+
'new_with_parentheses' => true,
27+
'no_extra_blank_lines' => true,
28+
'no_leading_import_slash' => true,
29+
'echo_tag_syntax' => true,
30+
'no_unused_imports' => true,
31+
'no_useless_else' => true,
32+
'no_useless_return' => true,
33+
'phpdoc_order' => true,
34+
'phpdoc_scalar' => true,
35+
'phpdoc_types' => true,
36+
'short_scalar_cast' => true,
37+
'blank_lines_before_namespace' => true,
38+
'single_quote' => true,
39+
'trailing_comma_in_multiline' => true,
40+
])
41+
->setRiskyAllowed(true)
42+
->setFinder($finder);
43+

src/Propagation/Instana/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
OpenTelemetry Instana Propagator
2+
3+
[![NPM Published Version][npm-img]][npm-url]
4+
[![Apache License][license-image]][license-image]
5+
6+
7+
The OpenTelemetry Propagator for Instana provides HTTP header propagation for systems that are using IBM Observability by Instana.
8+
This propagator translates the Instana trace correlation headers (`X-INSTANA-T/X-INSTANA-S/X-INSTANA-L`) into the OpenTelemetry `SpanContext`, and vice versa.
9+
It does not handle `TraceState`.
10+
11+
12+
## Installation
13+
14+
```sh
15+
composer require @instana/opentelemetry-php-propagator-instana
16+
```
17+
18+
## Usage
19+
20+
21+
22+
## Propagator Details
23+
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).
25+
26+
Example header triplet:
27+
28+
* `X-INSTANA-T: 80f198ee56343ba864fe8b2a57d3eff7`,
29+
* `X-INSTANA-S: e457b5a2e4d86bd1`,
30+
* `X-INSTANA-L: 1`.
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>.
33+
34+
### X-INSTANA-T -- trace ID
35+
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.
40+
41+
### X-INSTANA-S -- parent span ID
42+
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).
45+
46+
### X-INSTANA-L - sampling level
47+
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).
51+
52+
## Useful links
53+
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/>
56+
57+
58+
## License
59+
60+
Apache 2.0 - See [LICENSE][license-url] for more information.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
use OpenTelemetry\Extension\Propagator\Instana\InstanaMultiPropagator;
5+
use OpenTelemetry\SDK\Registry;
6+
7+
if (!class_exists(Registry::class)) {
8+
return;
9+
}
10+
Registry::registerTextMapPropagator(
11+
'instana',
12+
InstanaMultiPropagator::getInstance()
13+
);
14+
15+
Registry::registerCompositePropagator(
16+
'instana',
17+
InstanaPropagator::getInstance()
18+
);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "open-telemetry/opentelemetry-propagation-server-timing",
3+
"description": "OpenTelemetry server-timing propagator.",
4+
"keywords": ["opentelemetry", "otel", "open-telemetry", "propagator", "server-timing"],
5+
"type": "library",
6+
"readme": "./README.md",
7+
"license": "Apache-2.0",
8+
"minimum-stability": "dev",
9+
"prefer-stable": true,
10+
"require": {
11+
"php": "^8.1",
12+
"open-telemetry/api": "^1.0",
13+
"open-telemetry/context": "^1.0"
14+
},
15+
"autoload": {
16+
"psr-4": {
17+
"OpenTelemetry\\Contrib\\Propagation\\Instana\\": "src/"
18+
}
19+
},
20+
"require-dev": {
21+
"friendsofphp/php-cs-fixer": "^3",
22+
"phan/phan": "^5.0",
23+
"phpstan/phpstan": "^1.1",
24+
"phpstan/phpstan-phpunit": "^1.0",
25+
"psalm/plugin-phpunit": "^0.19.2",
26+
"open-telemetry/sdk": "^1.0",
27+
"phpunit/phpunit": "^9.5",
28+
"vimeo/psalm": "^4|^5|^6",
29+
"symfony/http-client": "^5.4|^6.0",
30+
"guzzlehttp/promises": "^1.5|^2",
31+
"php-http/message-factory": "^1.0",
32+
"nyholm/psr7": "^1.5"
33+
},
34+
"config": {
35+
"allow-plugins": {
36+
"php-http/discovery": true,
37+
"tbachert/spi": true
38+
}
39+
}
40+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
includes:
2+
- vendor/phpstan/phpstan-phpunit/extension.neon
3+
4+
parameters:
5+
tmpDir: var/cache/phpstan
6+
level: 5
7+
paths:
8+
- src
9+
- tests
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
6+
backupGlobals="false"
7+
backupStaticAttributes="false"
8+
cacheResult="false"
9+
colors="false"
10+
convertErrorsToExceptions="true"
11+
convertNoticesToExceptions="true"
12+
convertWarningsToExceptions="true"
13+
forceCoversAnnotation="false"
14+
processIsolation="false"
15+
stopOnError="false"
16+
stopOnFailure="false"
17+
stopOnIncomplete="false"
18+
stopOnSkipped="false"
19+
stopOnRisky="false"
20+
timeoutForSmallTests="1"
21+
timeoutForMediumTests="10"
22+
timeoutForLargeTests="60"
23+
verbose="true">
24+
25+
<coverage processUncoveredFiles="true" disableCodeCoverageIgnore="false">
26+
<include>
27+
<directory>src</directory>
28+
</include>
29+
</coverage>
30+
31+
<php>
32+
<ini name="date.timezone" value="UTC" />
33+
<ini name="display_errors" value="On" />
34+
<ini name="display_startup_errors" value="On" />
35+
<ini name="error_reporting" value="E_ALL" />
36+
</php>
37+
38+
<testsuites>
39+
<testsuite name="unit">
40+
<directory>tests/Unit</directory>
41+
</testsuite>
42+
</testsuites>
43+
44+
</phpunit>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="3"
4+
cacheDirectory="var/cache/psalm"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
8+
<projectFiles>
9+
<directory name="src"/>
10+
<directory name="tests"/>
11+
</projectFiles>
12+
<plugins>
13+
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
14+
</plugins>
15+
</psalm>

0 commit comments

Comments
 (0)