Skip to content

Commit 4659315

Browse files
Merge branch 'open-telemetry:main' into Add-contributing-guide
2 parents 9e81e32 + 96f0d0c commit 4659315

File tree

8 files changed

+42
-9
lines changed

8 files changed

+42
-9
lines changed

src/Instrumentation/ExtRdKafka/tests/Integration/ExtRdKafkaInstrumentationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function test_produce_creates_new_span()
136136
private function produceMessage(
137137
string $message,
138138
?string $key = null,
139-
array $headers = null,
139+
?array $headers = null,
140140
bool $produceWithoutHeaders = false
141141
): void {
142142
$conf = new Conf();
@@ -163,7 +163,7 @@ private function consumeMessage(): int|Message
163163
{
164164
$conf = new Conf();
165165

166-
$conf->setRebalanceCb(function (KafkaConsumer $kafka, $err, array $partitions = null) {
166+
$conf->setRebalanceCb(function (KafkaConsumer $kafka, $err, ?array $partitions = null) {
167167
switch ($err) {
168168
case RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS:
169169
$kafka->assign($partitions);

src/Instrumentation/HttpAsyncClient/tests/Integration/HttpAsyncClientInstrumentationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function __construct($response)
9494
$this->response = $response;
9595
}
9696

97-
public function then(callable $onFulfilled = null, callable $onRejected = null): Promise
97+
public function then(?callable $onFulfilled = null, ?callable $onRejected = null): Promise
9898
{
9999
$this->onFulfilled = $onFulfilled;
100100
$this->onRejected = $onRejected;

src/Instrumentation/MongoDB/src/MongoDBInstrumentation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class MongoDBInstrumentation
1414
/**
1515
* @param callable(object):?string $commandSerializer
1616
*/
17-
public static function register(callable $commandSerializer = null): void
17+
public static function register(?callable $commandSerializer = null): void
1818
{
1919
$instrumentation = new CachedInstrumentation(
2020
'io.opentelemetry.contrib.php.mongodb',

src/Instrumentation/PDO/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,14 @@ The extension can be disabled via [runtime configuration](https://opentelemetry.
2323
```shell
2424
OTEL_PHP_DISABLED_INSTRUMENTATIONS=pdo
2525
```
26+
27+
In case UI used to view telemetry data does not support links between spans (for example newrelic),
28+
you can optionally enable setting db statements attribute to `fetchAll` and `execute` spans using
29+
configuration directive:
30+
```
31+
otel.instrumentation.pdo.distribute_statement_to_linked_spans = true
32+
```
33+
or environment variable:
34+
```shell
35+
OTEL_PHP_INSTRUMENTATION_PDO_DISTRIBUTE_STATEMENT_TO_LINKED_SPANS=true
36+
```

src/Instrumentation/PDO/src/PDOInstrumentation.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OpenTelemetry\API\Trace\SpanKind;
1111
use OpenTelemetry\API\Trace\StatusCode;
1212
use OpenTelemetry\Context\Context;
13+
use OpenTelemetry\SDK\Common\Configuration\Configuration;
1314
use function OpenTelemetry\Instrumentation\hook;
1415
use OpenTelemetry\SemConv\TraceAttributes;
1516
use PDO;
@@ -200,6 +201,9 @@ public static function register(): void
200201
'fetchAll',
201202
pre: static function (PDOStatement $statement, array $params, string $class, string $function, ?string $filename, ?int $lineno) use ($pdoTracker, $instrumentation) {
202203
$attributes = $pdoTracker->trackedAttributesForStatement($statement);
204+
if (self::isDistributeStatementToLinkedSpansEnabled()) {
205+
$attributes[TraceAttributes::DB_STATEMENT] = $statement->queryString;
206+
}
203207
/** @psalm-suppress ArgumentTypeCoercion */
204208
$builder = self::makeBuilder($instrumentation, 'PDOStatement::fetchAll', $function, $class, $filename, $lineno)
205209
->setSpanKind(SpanKind::KIND_CLIENT)
@@ -221,6 +225,11 @@ public static function register(): void
221225
'execute',
222226
pre: static function (PDOStatement $statement, array $params, string $class, string $function, ?string $filename, ?int $lineno) use ($pdoTracker, $instrumentation) {
223227
$attributes = $pdoTracker->trackedAttributesForStatement($statement);
228+
229+
if (self::isDistributeStatementToLinkedSpansEnabled()) {
230+
$attributes[TraceAttributes::DB_STATEMENT] = $statement->queryString;
231+
}
232+
224233
/** @psalm-suppress ArgumentTypeCoercion */
225234
$builder = self::makeBuilder($instrumentation, 'PDOStatement::execute', $function, $class, $filename, $lineno)
226235
->setSpanKind(SpanKind::KIND_CLIENT)
@@ -268,4 +277,13 @@ private static function end(?Throwable $exception): void
268277

269278
$span->end();
270279
}
280+
281+
private static function isDistributeStatementToLinkedSpansEnabled(): bool
282+
{
283+
if (class_exists('OpenTelemetry\SDK\Common\Configuration\Configuration')) {
284+
return Configuration::getBoolean('OTEL_PHP_INSTRUMENTATION_PDO_DISTRIBUTE_STATEMENT_TO_LINKED_SPANS', false);
285+
}
286+
287+
return get_cfg_var('otel.instrumentation.pdo.distribute_statement_to_linked_spans');
288+
}
271289
}

src/Sampler/RuleBased/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
composer.lock
2+
13
.phpunit.cache
4+
5+
var
6+
vendor

src/Sampler/RuleBased/composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"license": "Apache-2.0",
66
"require": {
77
"php": "^8.1",
8-
"open-telemetry/api": "dev-main as 1.1.0",
9-
"open-telemetry/sdk": "dev-main as 1.1.0",
10-
"open-telemetry/sdk-configuration": "dev-main as 0.99"
8+
"open-telemetry/api": "^1.1.0",
9+
"open-telemetry/sdk": "^1.1.0",
10+
"open-telemetry/sdk-configuration": "^0.0.5"
1111
},
1212
"require-dev": {
1313
"symfony/config": "^5.4 || ^6.4 || ^7.0",
@@ -32,7 +32,6 @@
3232
"spi": {
3333
"OpenTelemetry\\Config\\SDK\\Configuration\\ComponentProvider": [
3434
"OpenTelemetry\\Contrib\\Sampler\\RuleBased\\ComponentProvider\\SamplerRuleBased",
35-
3635
"OpenTelemetry\\Contrib\\Sampler\\RuleBased\\ComponentProvider\\SamplingRuleAttribute",
3736
"OpenTelemetry\\Contrib\\Sampler\\RuleBased\\ComponentProvider\\SamplingRuleLink",
3837
"OpenTelemetry\\Contrib\\Sampler\\RuleBased\\ComponentProvider\\SamplingRuleParent",

src/Symfony/tests/Unit/OtelSdkBundle/Factory/GenericFactoryTraitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ class TestedDefaultNullClass
395395
private $fooBar;
396396
private $fooBaz;
397397

398-
public function __construct(string $fooBar, stdClass $fooBaz = null)
398+
public function __construct(string $fooBar, ?stdClass $fooBaz = null)
399399
{
400400
$this->fooBar = $fooBar;
401401
$this->fooBaz = $fooBaz;

0 commit comments

Comments
 (0)