1717use OpenTelemetry \SemConv \TraceAttributes ;
1818use Throwable ;
1919
20+ /**
21+ * @phan-file-suppress PhanUndeclaredFunction
22+ */
2023class WordpressInstrumentation
2124{
2225 public const NAME = 'wordpress ' ;
@@ -26,7 +29,7 @@ public static function register(): void
2629 $ instrumentation = new CachedInstrumentation (
2730 'io.opentelemetry.contrib.php.wordpress ' ,
2831 null ,
29- 'https://opentelemetry.io/schemas/1.24 .0 '
32+ 'https://opentelemetry.io/schemas/1.30 .0 '
3033 );
3134
3235 self ::_hook ($ instrumentation , 'WP ' , 'main ' , 'WP.main ' );
@@ -48,9 +51,9 @@ class: 'wpdb',
4851 function: '__construct ' ,
4952 pre: static function ($ object , ?array $ params , ?string $ class , ?string $ function , ?string $ filename , ?int $ lineno ) use ($ instrumentation ) {
5053 $ span = self ::builder ($ instrumentation , 'wpdb.__connect ' , $ function , $ class , $ filename , $ lineno )
51- ->setAttribute (TraceAttributes::DB_USER , $ params [0 ] ?? 'unknown ' )
52- ->setAttribute (TraceAttributes::DB_NAME , $ params [2 ] ?? 'unknown ' )
53- ->setAttribute (TraceAttributes::DB_SYSTEM , 'mysql ' )
54+ // ->setAttribute(TraceAttributes::DB_USER, $params[0] ?? 'unknown') //deprecated, no replacement
55+ ->setAttribute (TraceAttributes::DB_NAMESPACE , $ params [2 ] ?? 'unknown ' )
56+ ->setAttribute (TraceAttributes::DB_SYSTEM_NAME , 'mysql ' )
5457 ->startSpan ();
5558 Context::storage ()->attach ($ span ->storeInContext (Context::getCurrent ()));
5659 },
@@ -68,7 +71,7 @@ function: 'query',
6871 pre: static function ($ object , ?array $ params , ?string $ class , ?string $ function , ?string $ filename , ?int $ lineno ) use ($ instrumentation ) {
6972 $ span = self ::builder ($ instrumentation , 'wpdb.query ' , $ function , $ class , $ filename , $ lineno )
7073 ->setSpanKind (SpanKind::KIND_CLIENT )
71- ->setAttribute (TraceAttributes::DB_STATEMENT , $ params [0 ] ?? 'undefined ' )
74+ ->setAttribute (TraceAttributes::DB_QUERY_TEXT , $ params [0 ] ?? 'undefined ' )
7275 ->startSpan ();
7376 Context::storage ()->attach ($ span ->storeInContext (Context::getCurrent ()));
7477 },
@@ -157,10 +160,10 @@ private static function builder(
157160 /** @psalm-suppress ArgumentTypeCoercion */
158161 return $ instrumentation ->tracer ()
159162 ->spanBuilder ($ name )
160- ->setAttribute (TraceAttributes::CODE_FUNCTION , $ function )
163+ ->setAttribute (TraceAttributes::CODE_FUNCTION_NAME , $ function )
161164 ->setAttribute (TraceAttributes::CODE_NAMESPACE , $ class )
162165 ->setAttribute (TraceAttributes::CODE_FILEPATH , $ filename )
163- ->setAttribute (TraceAttributes::CODE_LINENO , $ lineno );
166+ ->setAttribute (TraceAttributes::CODE_LINE_NUMBER , $ lineno );
164167 }
165168
166169 private static function end (?Throwable $ exception ): void
@@ -172,7 +175,7 @@ private static function end(?Throwable $exception): void
172175 $ scope ->detach ();
173176 $ span = Span::fromContext ($ scope ->context ());
174177 if ($ exception ) {
175- $ span ->recordException ($ exception, [TraceAttributes:: EXCEPTION_ESCAPED => true ] );
178+ $ span ->recordException ($ exception );
176179 $ span ->setStatus (StatusCode::STATUS_ERROR , $ exception ->getMessage ());
177180 }
178181
0 commit comments