Skip to content

Commit

Permalink
Fixed a bit of warnings and deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
intuibase committed Nov 5, 2024
1 parent 27a188b commit f8f40cb
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/Context/Swoole/src/SwooleContextStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
10 changes: 5 additions & 5 deletions src/Instrumentation/ExtRdKafka/src/ExtRdKafkaInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/Instrumentation/Laravel/src/Watchers/LogWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/Instrumentation/Laravel/src/Watchers/QueryWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
3 changes: 2 additions & 1 deletion src/Instrumentation/Psr3/src/Psr3Instrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Logs/Monolog/src/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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'])
;
Expand Down
2 changes: 1 addition & 1 deletion src/ResourceDetectors/Azure/src/AppService/Detector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit f8f40cb

Please sign in to comment.