Skip to content

Commit ab3a035

Browse files
authored
Merge branch 'open-telemetry:main' into main
2 parents ae2c852 + 40eea2b commit ab3a035

File tree

8 files changed

+121
-31
lines changed

8 files changed

+121
-31
lines changed

.github/dependabot.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ updates:
7878
- "/src/Instrumentation/MySqli"
7979
- "/src/Instrumentation/OpenAIPHP"
8080
- "/src/Instrumentation/PDO"
81+
- "/src/Instrumentation/Psr3"
82+
- "/src/Instrumentation/Psr6"
8183
- "/src/Instrumentation/Psr14"
8284
- "/src/Instrumentation/Psr15"
8385
- "/src/Instrumentation/Psr16"
8486
- "/src/Instrumentation/Psr18"
85-
- "/src/Instrumentation/Psr3"
86-
- "/src/Instrumentation/Psr6"
8787
- "/src/Instrumentation/ReactPHP"
8888
- "/src/Instrumentation/Slim"
8989
- "/src/Instrumentation/Symfony"

.github/workflows/ossf-scorecard.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ jobs:
2828
results_file: results.sarif
2929
results_format: sarif
3030
publish_results: true
31+
# file_mode is needed in this repo because .gitattributes excludes the .github directory
32+
# (see https://github.com/ossf/scorecard/issues/4679#issuecomment-3013550752)
33+
file_mode: git
3134

3235
# Upload the results as artifacts (optional). Commenting out will disable
3336
# uploads of run results in SARIF format to the repository Actions tab.
@@ -42,6 +45,6 @@ jobs:
4245
# Upload the results to GitHub's code scanning dashboard (optional).
4346
# Commenting out will disable upload of results to your repo's Code Scanning dashboard
4447
- name: "Upload to code-scanning"
45-
uses: github/codeql-action/upload-sarif@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
48+
uses: github/codeql-action/upload-sarif@4e828ff8d448a8a6e532957b1811f387a63867e8 # v3.29.4
4649
with:
4750
sarif_file: results.sarif

.gitsplit.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,24 @@ project_url: "https://github.com/open-telemetry/opentelemetry-php-contrib.git"
66

77
# List of splits.
88
splits:
9-
- prefix: "src/MetaPackages/opentelemetry"
10-
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/opentelemetry-meta.git"
9+
- prefix: "src/AutoInstrumentationInstaller"
10+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-instrumentation-installer.git"
1111
- prefix: "src/Aws"
1212
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-aws.git"
13+
- prefix: "src/Context/Swoole"
14+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/context-swoole.git"
1315
- prefix: "src/Exporter/Instana"
1416
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-exporter-instana.git"
15-
- prefix: "src/Symfony"
16-
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-sdk-bundle.git"
17+
- prefix: "src/Instrumentation/AwsSdk"
18+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-aws-sdk.git"
19+
- prefix: "src/Instrumentation/CakePHP"
20+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-cakephp.git"
1721
- prefix: "src/Instrumentation/CodeIgniter"
1822
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-codeigniter.git"
1923
- prefix: "src/Instrumentation/Curl"
2024
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-curl.git"
25+
- prefix: "src/Instrumentation/Doctrine"
26+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-doctrine.git"
2127
- prefix: "src/Instrumentation/ExtAmqp"
2228
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-ext-amqp.git"
2329
- prefix: "src/Instrumentation/ExtRdKafka"
@@ -58,20 +64,12 @@ splits:
5864
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-symfony.git"
5965
- prefix: "src/Instrumentation/Wordpress"
6066
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-wordpress.git"
61-
- prefix: "src/Instrumentation/CakePHP"
62-
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-cakephp.git"
6367
- prefix: "src/Instrumentation/Yii"
6468
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-yii.git"
65-
- prefix: "src/Instrumentation/Doctrine"
66-
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-doctrine.git"
67-
- prefix: "src/Instrumentation/AwsSdk"
68-
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-aws-sdk.git"
69-
- prefix: "src/Context/Swoole"
70-
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/context-swoole.git"
71-
- prefix: "src/AutoInstrumentationInstaller"
72-
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-instrumentation-installer.git"
7369
- prefix: "src/Logs/Monolog"
7470
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-logger-monolog.git"
71+
- prefix: "src/MetaPackages/opentelemetry"
72+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/opentelemetry-meta.git"
7573
- prefix: "src/Propagation/Instana"
7674
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-propagator-instana.git"
7775
- prefix: "src/Propagation/ServerTiming"
@@ -88,6 +86,8 @@ splits:
8886
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-sampler-rulebased.git"
8987
- prefix: "src/Shims/OpenTracing"
9088
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-shim-opentracing.git"
89+
- prefix: "src/Symfony"
90+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-sdk-bundle.git"
9191
- prefix: "src/Utils/Test"
9292
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-utils-test.git"
9393
# List of references to split (defined as regexp)

composer.json

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
"OpenTelemetry\\Contrib\\Aws\\": "src/Aws/src",
1919
"OpenTelemetry\\Contrib\\Context\\Swoole\\": "src/Context/Swoole/src",
2020
"OpenTelemetry\\Contrib\\Exporter\\Instana\\": "src/Exporter/Instana/src",
21+
"OpenTelemetry\\Contrib\\Instrumentation\\AwsSdk\\": "src/Instrumentation/AwsSdk/src",
2122
"OpenTelemetry\\Contrib\\Instrumentation\\CakePHP\\": "src/Instrumentation/CakePHP/src",
2223
"OpenTelemetry\\Contrib\\Instrumentation\\CodeIgniter\\": "src/Instrumentation/CodeIgniter/src",
2324
"OpenTelemetry\\Contrib\\Instrumentation\\Curl\\": "src/Instrumentation/Curl/src",
25+
"OpenTelemetry\\Contrib\\Instrumentation\\Doctrine\\": "src/Instrumentation/Doctrine/src",
2426
"OpenTelemetry\\Contrib\\Instrumentation\\ExtAmqp\\": "src/Instrumentation/ExtAmqp/src",
2527
"OpenTelemetry\\Contrib\\Instrumentation\\ExtRdKafka\\": "src/Instrumentation/ExtRdKafka/src",
2628
"OpenTelemetry\\Contrib\\Instrumentation\\Guzzle\\": "src/Instrumentation/Guzzle/src",
@@ -46,15 +48,21 @@
4648
"OpenTelemetry\\Contrib\\Propagation\\Instana\\": "src/Propagation/Instana/src",
4749
"OpenTelemetry\\Contrib\\Propagation\\ServerTiming\\": "src/Propagation/ServerTiming/src",
4850
"OpenTelemetry\\Contrib\\Propagation\\TraceResponse\\": "src/Propagation/TraceResponse/src",
51+
"OpenTelemetry\\Contrib\\Resource\\Detector\\Azure\\": "src/ResourceDetectors/Azure/src",
4952
"OpenTelemetry\\Contrib\\Resource\\Detector\\Container\\": "src/ResourceDetectors/Container/src",
5053
"OpenTelemetry\\Contrib\\Resource\\Detector\\DigitalOcean\\": "src/ResourceDetectors/DigitalOcean/src",
54+
"OpenTelemetry\\Contrib\\Sampler\\RuleBased\\": "src/Sampler/RuleBased/src",
5155
"OpenTelemetry\\Contrib\\Shim\\OpenTracing\\": "src/Shims/OpenTracing/src",
52-
"OpenTelemetry\\Contrib\\Symfony\\": "src/Symfony/src"
56+
"OpenTelemetry\\Contrib\\Symfony\\": "src/Symfony/src",
57+
"OpenTelemetry\\TestUtils\\": "src/Utils/Test/src"
5358
},
5459
"files": [
60+
"src/Exporter/Instana/_register.php",
61+
"src/Instrumentation/AwsSdk/_register.php",
5562
"src/Instrumentation/CakePHP/_register.php",
5663
"src/Instrumentation/CodeIgniter/_register.php",
5764
"src/Instrumentation/Curl/_register.php",
65+
"src/Instrumentation/Doctrine/_register.php",
5866
"src/Instrumentation/ExtAmqp/_register.php",
5967
"src/Instrumentation/ExtRdKafka/_register.php",
6068
"src/Instrumentation/Guzzle/_register.php",
@@ -76,34 +84,68 @@
7684
"src/Instrumentation/Symfony/_register.php",
7785
"src/Instrumentation/Wordpress/_register.php",
7886
"src/Instrumentation/Yii/_register.php",
87+
"src/Propagation/Instana/_register.php",
88+
"src/ResourceDetectors/Azure/_register.php",
7989
"src/ResourceDetectors/Container/_register.php",
8090
"src/ResourceDetectors/DigitalOcean/_register.php"
8191
]
8292
},
8393
"autoload-dev": {
8494
"psr-4": {
85-
"OpenTelemetry\\TestUtils\\": "src/",
86-
"OpenTelemetry\\TestUtils\\Tests\\": "tests/"
95+
"OpenTelemetry\\Tests\\Aws\\": "src/Aws/tests",
96+
"OpenTelemetry\\Tests\\Exporter\\Instana\\": "src/Exporter/Instana/tests",
97+
"OpenTelemetry\\Tests\\Instrumentation\\AwsSdk\\": "src/Instrumentation/AwsSdk/tests",
98+
"OpenTelemetry\\Tests\\Instrumentation\\CakePHP\\": "src/Instrumentation/CakePHP/tests",
99+
"OpenTelemetry\\Tests\\Instrumentation\\CakePHP\\Integration\\App\\": "src/Instrumentation/CakePHP/tests/Integration/App",
100+
"OpenTelemetry\\Tests\\Instrumentation\\CodeIgniter\\": "src/Instrumentation/CodeIgniter/tests",
101+
"OpenTelemetry\\Tests\\Instrumentation\\Curl\\": "src/Instrumentation/Curl/tests",
102+
"OpenTelemetry\\Tests\\Instrumentation\\Doctrine\\": "src/Instrumentation/Doctrine/tests",
103+
"OpenTelemetry\\Tests\\Instrumentation\\ExtAmqp\\tests\\": "src/Instrumentation/ExtAmqp/tests",
104+
"OpenTelemetry\\Tests\\Instrumentation\\ExtRdKafka\\tests\\": "src/Instrumentation/ExtRdKafka/tests",
105+
"OpenTelemetry\\Tests\\Instrumentation\\Guzzle\\": "src/Instrumentation/Guzzle/tests",
106+
"OpenTelemetry\\Tests\\Instrumentation\\IO\\": "src/Instrumentation/IO/tests",
107+
"OpenTelemetry\\Tests\\Contrib\\Instrumentation\\Laravel\\": "src/Instrumentation/Laravel/tests",
108+
"OpenTelemetry\\Tests\\Instrumentation\\MongoDB\\": "src/Instrumentation/MongoDB/tests",
109+
"OpenTelemetry\\Tests\\Instrumentation\\MySqli\\": "src/Instrumentation/MySqli/tests",
110+
"OpenTelemetry\\Contrib\\Instrumentation\\OpenAIPHP\\Tests\\": "src/Instrumentation/OpenAIPHP/tests",
111+
"OpenTelemetry\\Tests\\Instrumentation\\PDO\\": "src/Instrumentation/PDO/tests",
112+
"OpenTelemetry\\Tests\\Instrumentation\\Psr6\\": "src/Instrumentation/Psr6/tests",
113+
"OpenTelemetry\\Instrumentation\\Psr14\\Tests\\": "src/Instrumentation/Psr14/tests",
114+
"OpenTelemetry\\Tests\\Instrumentation\\Psr16\\": "src/Instrumentation/Psr16/tests",
115+
"OpenTelemetry\\Tests\\Instrumentation\\ReactPHP\\": "src/Instrumentation/ReactPHP/tests",
116+
"OpenTelemetry\\Tests\\Instrumentation\\Slim\\": "src/Instrumentation/Slim/tests",
117+
"OpenTelemetry\\Tests\\Instrumentation\\Symfony\\tests\\": "src/Instrumentation/Symfony/tests",
118+
"OpenTelemetry\\Tests\\Instrumentation\\Wordpress\\": "src/Instrumentation/Wordpress/tests",
119+
"OpenTelemetry\\Tests\\Instrumentation\\Yii\\": "src/Instrumentation/Yii/tests",
120+
"OpenTelemetry\\Tests\\Resource\\Detector\\Azure\\": "src/ResourceDetectors/Azure/tests",
121+
"OpenTelemetry\\Contrib\\Resource\\Detector\\DigitalOcean\\": "src/ResourceDetectors/DigitalOcean/tests",
122+
"OpenTelemetry\\Tests\\Contrib\\Symfony\\": "src/Symfony/tests",
123+
"OpenTelemetry\\TestUtils\\Tests\\": "src/Utils/Test/tests"
87124
}
88125
},
89126
"replace": {
127+
"open-telemetry/context-swoole": "self.version",
90128
"open-telemetry/contrib-aws": "self.version",
91129
"open-telemetry/contrib-sdk-bundle": "self.version",
92-
"open-telemetry/context-swoole": "self.version",
130+
"open-telemetry/contrib-symfony-instrumentation-bundle": "self.version",
131+
"open-telemetry/detector-azure": "self.version",
132+
"open-telemetry/detector-container": "self.version",
133+
"open-telemetry/detector-digitalocean": "self.version",
134+
"open-telemetry/opentelemetry-auto-aws-sdk": "self.version",
93135
"open-telemetry/opentelemetry-auto-cakephp": "self.version",
94136
"open-telemetry/opentelemetry-auto-codeigniter": "self.version",
95137
"open-telemetry/opentelemetry-auto-curl": "self.version",
138+
"open-telemetry/opentelemetry-auto-doctrine": "self.version",
96139
"open-telemetry/opentelemetry-auto-ext-amqp": "self.version",
97-
"open-telemetry/opentelemetry-exporter-instana": "self.version",
98140
"open-telemetry/opentelemetry-auto-ext-rdkafka": "self.version",
99141
"open-telemetry/opentelemetry-auto-guzzle": "self.version",
100142
"open-telemetry/opentelemetry-auto-http-async": "self.version",
101143
"open-telemetry/opentelemetry-auto-io": "self.version",
102144
"open-telemetry/opentelemetry-auto-laravel": "self.version",
103145
"open-telemetry/opentelemetry-auto-mongodb": "self.version",
104146
"open-telemetry/opentelemetry-auto-mysqli": "self.version",
105-
"open-telemetry/opentelemetry-auto-pdo": "self.version",
106147
"open-telemetry/opentelemetry-auto-openai-php": "self.version",
148+
"open-telemetry/opentelemetry-auto-pdo": "self.version",
107149
"open-telemetry/opentelemetry-auto-psr3": "self.version",
108150
"open-telemetry/opentelemetry-auto-psr6": "self.version",
109151
"open-telemetry/opentelemetry-auto-psr14": "self.version",
@@ -115,14 +157,15 @@
115157
"open-telemetry/opentelemetry-auto-symfony": "self.version",
116158
"open-telemetry/opentelemetry-auto-wordpress": "self.version",
117159
"open-telemetry/opentelemetry-auto-yii": "self.version",
160+
"open-telemetry/opentelemetry-exporter-instana": "self.version",
161+
"open-telemetry/opentelemetry-instrumentation-installer": "self.version",
162+
"open-telemetry/opentelemetry-logger-monolog": "self.version",
118163
"open-telemetry/opentelemetry-propagation-instana": "self.version",
119164
"open-telemetry/opentelemetry-propagation-server-timing": "self.version",
120165
"open-telemetry/opentelemetry-propagation-traceresponse": "self.version",
121-
"open-telemetry/opentelemetry-logger-monolog": "self.version",
122-
"open-telemetry/detector-container": "self.version",
123-
"open-telemetry/detector-digitalocean": "self.version",
124-
"open-telemetry/symfony-sdk-bundle": "self.version",
125166
"open-telemetry/opentracing-shim": "self.version",
167+
"open-telemetry/sampler-rule-based": "self.version",
168+
"open-telemetry/symfony-sdk-bundle": "self.version",
126169
"open-telemetry/test-utils": "self.version"
127170
},
128171
"config": {

src/Instrumentation/Laravel/src/Watchers/LogWatcher.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use OpenTelemetry\API\Instrumentation\CachedInstrumentation;
1111
use OpenTelemetry\API\Logs\LogRecord;
1212
use OpenTelemetry\API\Logs\Severity;
13+
use OpenTelemetry\SDK\Common\Exception\StackTraceFormatter;
14+
use Throwable;
1315
use TypeError;
1416

1517
class LogWatcher extends Watcher
@@ -52,8 +54,21 @@ public function recordLog(MessageLogged $log): void
5254
// Should this fail, we should continue to emit the LogRecord.
5355
}
5456

57+
$contextToEncode = array_filter($log->context);
58+
59+
$exception = $this->getExceptionFromContext($log->context);
60+
61+
if ($exception !== null) {
62+
unset($contextToEncode['exception']);
63+
}
64+
5565
$attributes = [
56-
'context' => json_encode(array_filter($log->context)),
66+
'context' => json_encode($contextToEncode),
67+
...$exception !== null ? [
68+
'exception.type' => $exception::class,
69+
'exception.message' => $exception->getMessage(),
70+
'exception.stacktrace' => StackTraceFormatter::format($exception),
71+
] : [],
5772
];
5873

5974
$logger = $this->instrumentation->logger();
@@ -65,4 +80,16 @@ public function recordLog(MessageLogged $log): void
6580

6681
$logger->emit($record);
6782
}
83+
84+
private function getExceptionFromContext(array $context): ?Throwable
85+
{
86+
if (
87+
! isset($context['exception']) ||
88+
! $context['exception'] instanceof Throwable
89+
) {
90+
return null;
91+
}
92+
93+
return $context['exception'];
94+
}
6895
}

src/Instrumentation/Laravel/tests/Integration/LaravelInstrumentationTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Integration;
66

7+
use Exception;
78
use Illuminate\Routing\Router;
89
use Illuminate\Support\Facades\DB;
910
use Illuminate\Support\Facades\Http;
@@ -106,6 +107,16 @@ public function test_route_span_name_if_not_found(): void
106107
$this->assertSame('GET', $span->getName());
107108
}
108109

110+
public function test_records_exception_in_logs(): void
111+
{
112+
$this->router()->get('/exception', fn () => throw new Exception('Test exception'));
113+
$this->call('GET', '/exception');
114+
$logRecord = $this->storage[0];
115+
$this->assertEquals(Exception::class, $logRecord->getAttributes()->get(TraceAttributes::EXCEPTION_TYPE));
116+
$this->assertEquals('Test exception', $logRecord->getAttributes()->get(TraceAttributes::EXCEPTION_MESSAGE));
117+
$this->assertNotNull($logRecord->getAttributes()->get(TraceAttributes::EXCEPTION_STACKTRACE));
118+
}
119+
109120
private function router(): Router
110121
{
111122
/** @psalm-suppress PossiblyNullReference */

src/Instrumentation/Wordpress/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"open-telemetry/api": "^1.0",
1515
"open-telemetry/sem-conv": "^1.32",
1616
"nyholm/psr7": "^1",
17-
"nyholm/psr7-server": "^1"
17+
"nyholm/psr7-server": "^1",
18+
"psr/http-message": "2.0"
1819
},
1920
"require-dev": {
2021
"friendsofphp/php-cs-fixer": "^3",

src/Instrumentation/Wordpress/src/WordpressInstrumentation.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use function OpenTelemetry\Instrumentation\hook;
1717
use OpenTelemetry\SemConv\TraceAttributes;
1818
use OpenTelemetry\SemConv\Version;
19+
use Psr\Http\Message\ServerRequestInterface;
1920
use Throwable;
2021

2122
/**
@@ -92,7 +93,7 @@ function: 'wp_initial_constants',
9293

9394
$span = $instrumentation
9495
->tracer()
95-
->spanBuilder(sprintf('%s', $request->getMethod()))
96+
->spanBuilder(sprintf('%s %s', $request->getMethod(), self::getScriptNameFromRequest($request)))
9697
->setParent($parent)
9798
->setSpanKind(SpanKind::KIND_SERVER)
9899
->setAttribute(TraceAttributes::URL_FULL, (string) $request->getUri())
@@ -114,7 +115,6 @@ function_exists('is_admin') && $span->setAttribute('wp.is_admin', is_admin());
114115

115116
if (function_exists('is_404') && is_404()) {
116117
$span->setAttribute(TraceAttributes::HTTP_RESPONSE_STATUS_CODE, 404);
117-
$span->setStatus(StatusCode::STATUS_ERROR);
118118
}
119119
//@todo check for other errors?
120120
@@ -183,4 +183,9 @@ private static function end(?Throwable $exception): void
183183

184184
$span->end();
185185
}
186+
187+
private static function getScriptNameFromRequest(ServerRequestInterface $request): string
188+
{
189+
return $request->getServerParams()['SCRIPT_NAME'] ?? '/';
190+
}
186191
}

0 commit comments

Comments
 (0)