Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ updates:
- "/src/Aws"
- "/src/Aws/examples/AwsClientApp"
- "/src/Context/Swoole"
- "/src/ContextPropagator"
- "/src/Exporter/Instana"
- "/src/Instrumentation/AwsSdk"
- "/src/Instrumentation/CakePHP"
Expand Down Expand Up @@ -101,6 +102,7 @@ updates:
- "/src/ResourceDetectors/DigitalOcean"
- "/src/Sampler/RuleBased"
- "/src/Shims/OpenTracing"
- "/src/SqlCommenter"
- "/src/Symfony"
- "/src/Symfony/src/OtelBundle"
- "/src/Symfony/src/OtelSdkBundle"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
project: [
'Aws',
'Context/Swoole',
'ContextPropagator',
'Exporter/Instana',
'Instrumentation/AwsSdk',
'Instrumentation/CakePHP',
Expand Down Expand Up @@ -65,6 +66,7 @@ jobs:
'Sampler/RuleBased',
'Sampler/Xray',
'Shims/OpenTracing',
'SqlCommenter',
'Symfony',
'Utils/Test'
]
Expand Down
4 changes: 4 additions & 0 deletions .gitsplit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ splits:
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-aws.git"
- prefix: "src/Context/Swoole"
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/context-swoole.git"
- prefix: "src/ContextPropagator"
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-context-propagator.git"
- prefix: "src/Exporter/Instana"
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-exporter-instana.git"
- prefix: "src/Instrumentation/AwsSdk"
Expand Down Expand Up @@ -94,6 +96,8 @@ splits:
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-sampler-aws-xray.git"
- prefix: "src/Shims/OpenTracing"
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-shim-opentracing.git"
- prefix: "src/SqlCommenter"
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-sqlcommenter.git"
- prefix: "src/Symfony"
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-sdk-bundle.git"
- prefix: "src/Utils/Test"
Expand Down
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"psr-4": {
"OpenTelemetry\\Contrib\\Aws\\": "src/Aws/src",
"OpenTelemetry\\Contrib\\Context\\Swoole\\": "src/Context/Swoole/src",
"OpenTelemetry\\Contrib\\ContextPropagator\\": "src/ContextPropagator/src",
"OpenTelemetry\\Contrib\\Exporter\\Instana\\": "src/Exporter/Instana/src",
"OpenTelemetry\\Contrib\\Instrumentation\\AwsSdk\\": "src/Instrumentation/AwsSdk/src",
"OpenTelemetry\\Contrib\\Instrumentation\\CakePHP\\": "src/Instrumentation/CakePHP/src",
Expand Down Expand Up @@ -55,6 +56,7 @@
"OpenTelemetry\\Contrib\\Resource\\Detector\\DigitalOcean\\": "src/ResourceDetectors/DigitalOcean/src",
"OpenTelemetry\\Contrib\\Sampler\\RuleBased\\": "src/Sampler/RuleBased/src",
"OpenTelemetry\\Contrib\\Shim\\OpenTracing\\": "src/Shims/OpenTracing/src",
"OpenTelemetry\\Contrib\\SqlCommenter\\": "src/SqlCommenter/src",
"OpenTelemetry\\Contrib\\Symfony\\": "src/Symfony/src",
"OpenTelemetry\\TestUtils\\": "src/Utils/Test/src"
},
Expand Down Expand Up @@ -125,12 +127,15 @@
"OpenTelemetry\\Tests\\Propagation\\CloudTrace\\": "src/Propagation/CloudTrace/tests",
"OpenTelemetry\\Tests\\Resource\\Detector\\Azure\\": "src/ResourceDetectors/Azure/tests",
"OpenTelemetry\\Contrib\\Resource\\Detector\\DigitalOcean\\": "src/ResourceDetectors/DigitalOcean/tests",
"OpenTelemetry\\Tests\\Contrib\\ContextPropagator\\": "src/ContextPropagator/tests",
"OpenTelemetry\\Tests\\Contrib\\SqlCommenter\\": "src/SqlCommenter/tests",
"OpenTelemetry\\Tests\\Contrib\\Symfony\\": "src/Symfony/tests",
"OpenTelemetry\\TestUtils\\Tests\\": "src/Utils/Test/tests"
}
},
"replace": {
"open-telemetry/context-swoole": "self.version",
"open-telemetry/opentelemetry-context-propagator": "self.version",
"open-telemetry/contrib-aws": "self.version",
"open-telemetry/contrib-sdk-bundle": "self.version",
"open-telemetry/contrib-symfony-instrumentation-bundle": "self.version",
Expand Down Expand Up @@ -171,6 +176,7 @@
"open-telemetry/opentelemetry-propagation-instana": "self.version",
"open-telemetry/opentelemetry-propagation-server-timing": "self.version",
"open-telemetry/opentelemetry-propagation-traceresponse": "self.version",
"open-telemetry/opentelemetry-sqlcommenter": "self.version",
"open-telemetry/opentracing-shim": "self.version",
"open-telemetry/sampler-rule-based": "self.version",
"open-telemetry/symfony-sdk-bundle": "self.version",
Expand Down
12 changes: 12 additions & 0 deletions src/ContextPropagator/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
* text=auto

*.md diff=markdown
*.php diff=php

/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.php export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/psalm.xml.dist export-ignore
/tests export-ignore
1 change: 1 addition & 0 deletions src/ContextPropagator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
43 changes: 43 additions & 0 deletions src/ContextPropagator/.php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->exclude('var/cache')
->in(__DIR__);

$config = new PhpCsFixer\Config();
return $config->setRules([
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => ['space' => 'none'],
'is_null' => true,
'modernize_types_casting' => true,
'ordered_imports' => true,
'php_unit_construct' => true,
'single_line_comment_style' => true,
'yoda_style' => false,
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_after_opening_tag' => true,
'blank_line_before_statement' => true,
'cast_spaces' => true,
'declare_strict_types' => true,
'type_declaration_spaces' => true,
'include' => true,
'lowercase_cast' => true,
'new_with_parentheses' => true,
'no_extra_blank_lines' => true,
'no_leading_import_slash' => true,
'echo_tag_syntax' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_types' => true,
'short_scalar_cast' => true,
'blank_lines_before_namespace' => true,
'single_quote' => true,
'trailing_comma_in_multiline' => true,
])
->setRiskyAllowed(true)
->setFinder($finder);

47 changes: 47 additions & 0 deletions src/ContextPropagator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[![Releases](https://img.shields.io/badge/releases-purple)](https://github.com/opentelemetry-php/contrib-context-propagator/releases)
[![Issues](https://img.shields.io/badge/issues-pink)](https://github.com/open-telemetry/opentelemetry-php/issues)
[![Source](https://img.shields.io/badge/source-contrib-green)](https://github.com/open-telemetry/opentelemetry-php-contrib/tree/main/src/ContextPropagator)
[![Mirror](https://img.shields.io/badge/mirror-opentelemetry--php--contrib-blue)](https://github.com/opentelemetry-php/contrib-context-propagator)
[![Latest Version](http://poser.pugx.org/open-telemetry/opentelemetry-context-propagator/v/unstable)](https://packagist.org/packages/open-telemetry/opentelemetry-context-propagator/)
[![Stable](http://poser.pugx.org/open-telemetry/opentelemetry-context-propagator/v/stable)](https://packagist.org/packages/open-telemetry/opentelemetry-context-propagator/)

This is a read-only subtree split of https://github.com/open-telemetry/opentelemetry-php-contrib.

# OpenTelemetry Context Propagator

This package provides a context Propagator to support retrieving contexts for [open-telemetry/opentelemetry-sqlcommenter](https://github.com/open-telemetry/opentelemetry-php-contrib/tree/main/src/SqlCommenter).

## Usage

```php
$contextPropagator = (new ContextPropagatorFactory())->create();
$comments = [];
$contextPropagator->inject($comments);
```

## Installation via composer

```bash
$ composer require open-telemetry/opentelemetry-context-propagator
```

## Configuration

```shell
OTEL_PHP_INSTRUMENTATION_CONTEXT_PROPAGATORS=tracecontext
```
specifies propagators to be used in a comma-separated list. Default value: `''`

```shell
OTEL_PHP_INSTRUMENTATION_CONTEXT_PROPAGATION_ATTRIBUTE=true
```
specifies to include context propagtion in the span attributes. Default value: `false`

## Installing dependencies and executing tests

From ContextPropagator subdirectory:

```bash
$ composer install
$ ./vendor/bin/phpunit tests
```
40 changes: 40 additions & 0 deletions src/ContextPropagator/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "open-telemetry/opentelemetry-context-propagator",
"description": "OpenTelemetry context propagator.",
"keywords": ["opentelemetry", "otel", "open-telemetry", "context propagator"],
"type": "library",
"homepage": "https://opentelemetry.io/docs/php",
"readme": "./README.md",
"license": "Apache-2.0",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.1",
"open-telemetry/context": "^1.0"
},
"autoload": {
"psr-4": {
"OpenTelemetry\\Contrib\\ContextPropagator\\": "src/"
}
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3",
"phan/phan": "^5.0",
"phpstan/phpstan": "^1.1",
"phpstan/phpstan-phpunit": "^1.0",
"psalm/plugin-phpunit": "^0.19.2",
"open-telemetry/sdk": "^1.0",
"phpunit/phpunit": "^9.5",
"vimeo/psalm": "6.4.0",
"symfony/http-client": "^5.4|^6.0",
"guzzlehttp/promises": "^2",
"php-http/message-factory": "^1.0",
"nyholm/psr7": "^1.5"
},
"config": {
"allow-plugins": {
"php-http/discovery": true,
"tbachert/spi": true
}
}
}
9 changes: 9 additions & 0 deletions src/ContextPropagator/phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon

parameters:
tmpDir: var/cache/phpstan
level: 5
paths:
- src
- tests
44 changes: 44 additions & 0 deletions src/ContextPropagator/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
cacheResult="false"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
verbose="true">

<coverage processUncoveredFiles="true" disableCodeCoverageIgnore="false">
<include>
<directory>src</directory>
</include>
</coverage>

<php>
<ini name="date.timezone" value="UTC" />
<ini name="display_errors" value="On" />
<ini name="display_startup_errors" value="On" />
<ini name="error_reporting" value="E_ALL" />
</php>

<testsuites>
<testsuite name="unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>

</phpunit>
15 changes: 15 additions & 0 deletions src/ContextPropagator/psalm.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="3"
cacheDirectory="var/cache/psalm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
<projectFiles>
<directory name="src"/>
<directory name="tests"/>
</projectFiles>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
</psalm>
17 changes: 17 additions & 0 deletions src/ContextPropagator/src/ContextPropagation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Contrib\ContextPropagator;

class ContextPropagation
{
public static function isAttributeEnabled(): bool
{
if (class_exists('OpenTelemetry\SDK\Common\Configuration\Configuration') && \OpenTelemetry\SDK\Common\Configuration\Configuration::getBoolean('OTEL_PHP_INSTRUMENTATION_CONTEXT_PROPAGATION_ATTRIBUTE', false)) {
return true;
}

return filter_var(get_cfg_var('otel.instrumentation.context_propagation.attribute'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? false;
}
}
Loading
Loading