diff --git a/src/Context/Swoole/src/SwooleContextStorage.php b/src/Context/Swoole/src/SwooleContextStorage.php index a35b1c9f..a2f80c46 100644 --- a/src/Context/Swoole/src/SwooleContextStorage.php +++ b/src/Context/Swoole/src/SwooleContextStorage.php @@ -26,21 +26,21 @@ public function __construct(ContextStorageInterface $storage) $this->handler = new SwooleContextHandler($storage); } - public function fork($id): void + public function fork(int|string $id): void { $this->handler->switchToActiveCoroutine(); $this->storage->fork($id); } - public function switch($id): void + public function switch(int|string $id): void { $this->handler->switchToActiveCoroutine(); $this->storage->switch($id); } - public function destroy($id): void + public function destroy(int|string $id): void { $this->handler->switchToActiveCoroutine(); diff --git a/src/Instrumentation/ExtRdKafka/src/ExtRdKafkaInstrumentation.php b/src/Instrumentation/ExtRdKafka/src/ExtRdKafkaInstrumentation.php index 72104d5d..308f39b8 100644 --- a/src/Instrumentation/ExtRdKafka/src/ExtRdKafkaInstrumentation.php +++ b/src/Instrumentation/ExtRdKafka/src/ExtRdKafkaInstrumentation.php @@ -74,14 +74,14 @@ private static function addProductionHooks($instrumentation) /** @var CachedInstrumentation $instrumentation */ $builder = $instrumentation ->tracer() - ->spanBuilder(sprintf('%s %s', $exchange->getName(), TraceAttributeValues::MESSAGING_OPERATION_PUBLISH)) + ->spanBuilder(sprintf('%s %s', $exchange->getName(), TraceAttributeValues::MESSAGING_OPERATION_TYPE_PUBLISH)) ->setSpanKind(SpanKind::KIND_PRODUCER) ->setAttribute(TraceAttributes::CODE_FUNCTION, $function) ->setAttribute(TraceAttributes::CODE_NAMESPACE, $class) ->setAttribute(TraceAttributes::CODE_FILEPATH, $filename) ->setAttribute(TraceAttributes::CODE_LINENO, $lineno) ->setAttribute(TraceAttributes::MESSAGING_SYSTEM, TraceAttributeValues::MESSAGING_SYSTEM_KAFKA) - ->setAttribute(TraceAttributes::MESSAGING_OPERATION, TraceAttributeValues::MESSAGING_OPERATION_PUBLISH) + ->setAttribute(TraceAttributes::MESSAGING_OPERATION_TYPE, TraceAttributeValues::MESSAGING_OPERATION_TYPE_PUBLISH) ; $parent = Context::getCurrent(); @@ -147,12 +147,12 @@ private static function addConsumeHooks($instrumentation) $builder = $instrumentation ->tracer() // @phan-suppress-next-line PhanTypeMismatchArgumentInternal - Doesn't seem to know this has to be a string - ->spanBuilder(sprintf('%s %s', $message->topic_name, TraceAttributeValues::MESSAGING_OPERATION_DELIVER)) + ->spanBuilder(sprintf('%s %s', $message->topic_name, TraceAttributeValues::MESSAGING_OPERATION_TYPE_PROCESS)) ->setSpanKind(SpanKind::KIND_CONSUMER) ->setAttribute(TraceAttributes::MESSAGING_SYSTEM, TraceAttributeValues::MESSAGING_SYSTEM_KAFKA) - ->setAttribute(TraceAttributes::MESSAGING_OPERATION, TraceAttributeValues::MESSAGING_OPERATION_DELIVER) + ->setAttribute(TraceAttributes::MESSAGING_OPERATION_TYPE, TraceAttributeValues::MESSAGING_OPERATION_TYPE_PROCESS) ->setAttribute(TraceAttributes::MESSAGING_KAFKA_MESSAGE_KEY, $message->key) - ->setAttribute(TraceAttributes::MESSAGING_KAFKA_MESSAGE_OFFSET, $message->offset) + ->setAttribute(TraceAttributes::MESSAGING_KAFKA_OFFSET, $message->offset) ; if (is_array($message->headers)) { diff --git a/src/Instrumentation/Laravel/src/Hooks/Illuminate/Contracts/Queue/Queue.php b/src/Instrumentation/Laravel/src/Hooks/Illuminate/Contracts/Queue/Queue.php index c58800db..e7103156 100644 --- a/src/Instrumentation/Laravel/src/Hooks/Illuminate/Contracts/Queue/Queue.php +++ b/src/Instrumentation/Laravel/src/Hooks/Illuminate/Contracts/Queue/Queue.php @@ -51,7 +51,7 @@ protected function hookBulk(): bool ->spanBuilder(vsprintf('%s %s', [ /** @phan-suppress-next-line PhanUndeclaredMethod */ method_exists($queue, 'getQueue') ? $queue->getQueue($params[2] ?? null) : $queue->getConnectionName(), - TraceAttributeValues::MESSAGING_OPERATION_PUBLISH, + TraceAttributeValues::MESSAGING_OPERATION_TYPE_PUBLISH, ])) ->setSpanKind(SpanKind::KIND_PRODUCER) ->setAttributes($attributes) @@ -125,7 +125,7 @@ protected function hookPushRaw(): bool ->tracer() ->spanBuilder(vsprintf('%s %s', [ $attributes[TraceAttributes::MESSAGING_DESTINATION_NAME], - TraceAttributeValues::MESSAGING_OPERATION_CREATE, + TraceAttributeValues::MESSAGING_OPERATION_TYPE_CREATE, ])) ->setSpanKind(SpanKind::KIND_PRODUCER) ->setAttributes($attributes) diff --git a/src/Instrumentation/Laravel/src/Hooks/Illuminate/Queue/Worker.php b/src/Instrumentation/Laravel/src/Hooks/Illuminate/Queue/Worker.php index 0e295a69..b346bc10 100644 --- a/src/Instrumentation/Laravel/src/Hooks/Illuminate/Queue/Worker.php +++ b/src/Instrumentation/Laravel/src/Hooks/Illuminate/Queue/Worker.php @@ -99,7 +99,7 @@ private function hookWorkerGetNextJob(): bool ->tracer() ->spanBuilder(vsprintf('%s %s', [ $attributes[TraceAttributes::MESSAGING_DESTINATION_NAME], - TraceAttributeValues::MESSAGING_OPERATION_RECEIVE, + TraceAttributeValues::MESSAGING_OPERATION_TYPE_RECEIVE, ])) ->setSpanKind(SpanKind::KIND_CONSUMER) ->setAttributes($attributes) diff --git a/src/Instrumentation/Laravel/src/Watchers/LogWatcher.php b/src/Instrumentation/Laravel/src/Watchers/LogWatcher.php index 7adcddd9..4b6e9eb9 100644 --- a/src/Instrumentation/Laravel/src/Watchers/LogWatcher.php +++ b/src/Instrumentation/Laravel/src/Watchers/LogWatcher.php @@ -9,7 +9,7 @@ use Illuminate\Log\LogManager; use OpenTelemetry\API\Instrumentation\CachedInstrumentation; use OpenTelemetry\API\Logs\LogRecord; -use OpenTelemetry\API\Logs\Map\Psr3; +use OpenTelemetry\API\Logs\Severity; use TypeError; class LogWatcher extends Watcher @@ -58,7 +58,7 @@ public function recordLog(MessageLogged $log): void $record = (new LogRecord($log->message)) ->setSeverityText($log->level) - ->setSeverityNumber(Psr3::severityNumber($log->level)) + ->setSeverityNumber(Severity::fromPsr3($log->level)) ->setAttributes($attributes); $logger->emit($record); diff --git a/src/Instrumentation/Laravel/src/Watchers/QueryWatcher.php b/src/Instrumentation/Laravel/src/Watchers/QueryWatcher.php index ff1c82d5..fc3ae725 100644 --- a/src/Instrumentation/Laravel/src/Watchers/QueryWatcher.php +++ b/src/Instrumentation/Laravel/src/Watchers/QueryWatcher.php @@ -45,12 +45,13 @@ public function recordQuery(QueryExecuted $query): void $attributes = [ TraceAttributes::DB_SYSTEM => $query->connection->getDriverName(), - TraceAttributes::DB_NAME => $query->connection->getDatabaseName(), - TraceAttributes::DB_OPERATION => $operationName, + TraceAttributes::DB_NAMESPACE => $query->connection->getDatabaseName(), + TraceAttributes::DB_OPERATION_NAME => $operationName, + /** @phan-suppress-next-line PhanDeprecatedClassConstant */ TraceAttributes::DB_USER => $query->connection->getConfig('username'), ]; - $attributes[TraceAttributes::DB_STATEMENT] = $query->sql; + $attributes[TraceAttributes::DB_QUERY_TEXT] = $query->sql; /** @psalm-suppress PossiblyInvalidArgument */ $span->setAttributes($attributes); $span->end($nowInNs); diff --git a/src/Instrumentation/Laravel/src/Watchers/RedisCommand/RedisCommandWatcher.php b/src/Instrumentation/Laravel/src/Watchers/RedisCommand/RedisCommandWatcher.php index 6e798d4e..6a0a1dfe 100644 --- a/src/Instrumentation/Laravel/src/Watchers/RedisCommand/RedisCommandWatcher.php +++ b/src/Instrumentation/Laravel/src/Watchers/RedisCommand/RedisCommandWatcher.php @@ -55,9 +55,9 @@ public function recordRedisCommand(CommandExecuted $event): void // See https://opentelemetry.io/docs/specs/semconv/database/redis/ $attributes = [ TraceAttributes::DB_SYSTEM => TraceAttributeValues::DB_SYSTEM_REDIS, - TraceAttributes::DB_NAME => $this->fetchDbIndex($event->connection), - TraceAttributes::DB_OPERATION => $operationName, - TraceAttributes::DB_STATEMENT => Serializer::serializeCommand($event->command, $event->parameters), + TraceAttributes::DB_NAMESPACE => $this->fetchDbIndex($event->connection), + TraceAttributes::DB_OPERATION_NAME => $operationName, + TraceAttributes::DB_QUERY_TEXT => Serializer::serializeCommand($event->command, $event->parameters), TraceAttributes::SERVER_ADDRESS => $this->fetchDbHost($event->connection), ]; diff --git a/src/Instrumentation/Laravel/src/Watchers/RedisCommand/Serializer.php b/src/Instrumentation/Laravel/src/Watchers/RedisCommand/Serializer.php index a64c4081..e15b4db6 100644 --- a/src/Instrumentation/Laravel/src/Watchers/RedisCommand/Serializer.php +++ b/src/Instrumentation/Laravel/src/Watchers/RedisCommand/Serializer.php @@ -70,7 +70,7 @@ public static function serializeCommand(string $command, array $params): string } // In some cases (for example when using LUA scripts) arrays are valid parameters - $paramsToSerialize = array_map(function($param) { return is_array($param) ? json_encode($param) : $param; }, $paramsToSerialize); + $paramsToSerialize = array_map(function ($param) { return is_array($param) ? json_encode($param) : $param; }, $paramsToSerialize); return $command . ' ' . implode(' ', $paramsToSerialize); } diff --git a/src/Instrumentation/Laravel/tests/Integration/LaravelInstrumentationTest.php b/src/Instrumentation/Laravel/tests/Integration/LaravelInstrumentationTest.php index c5096ff3..848c4d3d 100644 --- a/src/Instrumentation/Laravel/tests/Integration/LaravelInstrumentationTest.php +++ b/src/Instrumentation/Laravel/tests/Integration/LaravelInstrumentationTest.php @@ -58,9 +58,9 @@ public function test_cache_log_db(): void $span = $this->storage[1]; $this->assertSame('sql SELECT', $span->getName()); - $this->assertSame('SELECT', $span->getAttributes()->get('db.operation')); - $this->assertSame(':memory:', $span->getAttributes()->get('db.name')); - $this->assertSame('select 1', $span->getAttributes()->get('db.statement')); + $this->assertSame('SELECT', $span->getAttributes()->get('db.operation.name')); + $this->assertSame(':memory:', $span->getAttributes()->get('db.namespace')); + $this->assertSame('select 1', $span->getAttributes()->get('db.query.text')); $this->assertSame('sqlite', $span->getAttributes()->get('db.system')); /** @var \OpenTelemetry\SDK\Logs\ReadWriteLogRecord $logRecord */ diff --git a/src/Instrumentation/Psr3/src/Psr3Instrumentation.php b/src/Instrumentation/Psr3/src/Psr3Instrumentation.php index 2cca4e8e..3d61be11 100644 --- a/src/Instrumentation/Psr3/src/Psr3Instrumentation.php +++ b/src/Instrumentation/Psr3/src/Psr3Instrumentation.php @@ -7,6 +7,7 @@ use OpenTelemetry\API\Instrumentation\CachedInstrumentation; use OpenTelemetry\API\Instrumentation\ConfigurationResolver; use OpenTelemetry\API\Logs as API; +use OpenTelemetry\API\Logs\Severity; use OpenTelemetry\API\Trace\Span; use OpenTelemetry\Context\Context; use function OpenTelemetry\Instrumentation\hook; @@ -76,7 +77,7 @@ public static function register(): void } $record = (new API\LogRecord($body)) - ->setSeverityNumber(API\Map\Psr3::severityNumber($level)); + ->setSeverityNumber(Severity::fromPsr3($level)); foreach (Formatter::format($context) as $key => $value) { $record->setAttribute((string) $key, $value); } diff --git a/src/Logs/Monolog/src/Handler.php b/src/Logs/Monolog/src/Handler.php index d4fc86f3..94be0124 100644 --- a/src/Logs/Monolog/src/Handler.php +++ b/src/Logs/Monolog/src/Handler.php @@ -9,6 +9,7 @@ use Monolog\Formatter\NormalizerFormatter; use Monolog\Handler\AbstractProcessingHandler; use OpenTelemetry\API\Logs as API; +use OpenTelemetry\API\Logs\Severity; class Handler extends AbstractProcessingHandler { @@ -48,7 +49,7 @@ protected function write($record): void $formatted = $record['formatted']; $logRecord = (new API\LogRecord()) ->setTimestamp((int) $record['datetime']->format('Uu') * 1000) - ->setSeverityNumber(API\Map\Psr3::severityNumber($record['level_name'])) + ->setSeverityNumber(Severity::fromPsr3($record['level_name'])) ->setSeverityText($record['level_name']) ->setBody($formatted['message']) ; diff --git a/src/ResourceDetectors/Azure/src/AppService/Detector.php b/src/ResourceDetectors/Azure/src/AppService/Detector.php index d98a6354..6ed306df 100644 --- a/src/ResourceDetectors/Azure/src/AppService/Detector.php +++ b/src/ResourceDetectors/Azure/src/AppService/Detector.php @@ -60,7 +60,7 @@ public function getResource(): ResourceInfo ResourceAttributes::CLOUD_PROVIDER => self::CLOUD_PROVIDER, ResourceAttributes::CLOUD_REGION => getenv(self::ENV_REGION_NAME_KEY), ResourceAttributes::CLOUD_RESOURCE_ID => self::generateAzureResourceUri($name, $groupName, $subscriptionId), - ResourceAttributes::DEPLOYMENT_ENVIRONMENT => getenv(self::ENV_WEBSITE_SLOT_NAME_KEY), + ResourceAttributes::DEPLOYMENT_ENVIRONMENT_NAME => getenv(self::ENV_WEBSITE_SLOT_NAME_KEY), ResourceAttributes::HOST_ID => getenv(self::ENV_WEBSITE_HOSTNAME_KEY), ResourceAttributes::SERVICE_INSTANCE_ID => getenv(self::ENV_WEBSITE_INSTANCE_ID_KEY), ResourceAttributes::SERVICE_NAME => $name, diff --git a/src/ResourceDetectors/Azure/tests/Unit/AppService/DetectorTest.php b/src/ResourceDetectors/Azure/tests/Unit/AppService/DetectorTest.php index 4c91ebf5..e8cc9754 100644 --- a/src/ResourceDetectors/Azure/tests/Unit/AppService/DetectorTest.php +++ b/src/ResourceDetectors/Azure/tests/Unit/AppService/DetectorTest.php @@ -32,7 +32,7 @@ public function test_valid_app_service_attributes() [ResourceAttributes::CLOUD_PROVIDER, null, 'azure'], [ResourceAttributes::CLOUD_RESOURCE_ID, Detector::ENV_REGION_NAME_KEY, '/subscriptions/owner_name/resourceGroups/resouce_group/providers/Microsoft.Web/sites/demo-app'], [ResourceAttributes::CLOUD_REGION, Detector::ENV_REGION_NAME_KEY, 'westus'], - [ResourceAttributes::DEPLOYMENT_ENVIRONMENT, Detector::ENV_WEBSITE_SLOT_NAME_KEY, 'testing'], + [ResourceAttributes::DEPLOYMENT_ENVIRONMENT_NAME, Detector::ENV_WEBSITE_SLOT_NAME_KEY, 'testing'], [ResourceAttributes::HOST_ID, Detector::ENV_WEBSITE_HOSTNAME_KEY, 'example.com'], [ResourceAttributes::SERVICE_INSTANCE_ID, Detector::ENV_WEBSITE_INSTANCE_ID_KEY, uniqid()], [ResourceAttributes::SERVICE_NAME, Detector::ENV_WEBSITE_SITE_NAME_KEY, self::SERVICE_NAME],