Skip to content

Commit

Permalink
Merge pull request #44 from worldia/fix/lint
Browse files Browse the repository at this point in the history
Add compatibility with OpenTelemetry 1.0
  • Loading branch information
cyve authored Jun 7, 2023
2 parents 2bd7af5 + ef74d26 commit 47d829f
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 30 deletions.
2 changes: 0 additions & 2 deletions src/Bridge/GoogleCloud/Logging/Formatter/StdOutFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public function __construct(private string $project)
*
* @see https://cloud.google.com/logging/docs/agent/configuration#process-payload
* @see https://github.com/GoogleCloudPlatform/fluent-plugin-google-cloud/blob/master/lib/fluent/plugin/out_google_cloud.rb
*
* @return mixed
*/
protected function normalize($data, int $depth = 0)
{
Expand Down
21 changes: 10 additions & 11 deletions src/Semantics/Attribute/DoctrineConnectionAttributeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use Doctrine\DBAL\Platforms;
use OpenTelemetry\SemConv\TraceAttributes;
use OpenTelemetry\SemConv\TraceAttributeValues;

class DoctrineConnectionAttributeProvider implements DoctrineConnectionAttributeProviderInterface
{
Expand Down Expand Up @@ -40,9 +39,9 @@ public function getAttributes(Platforms\AbstractPlatform $platform, array $param
}

if (isset($params['unix_socket'])) {
$attributes[TraceAttributes::NET_TRANSPORT] = TraceAttributeValues::NET_TRANSPORT_UNIX;
$attributes[TraceAttributes::NET_TRANSPORT] = 'unix';
} elseif (isset($params['memory'])) {
$attributes[TraceAttributes::NET_TRANSPORT] = TraceAttributeValues::NET_TRANSPORT_INPROC;
$attributes[TraceAttributes::NET_TRANSPORT] = 'inproc';
}

return $attributes;
Expand All @@ -51,27 +50,27 @@ public function getAttributes(Platforms\AbstractPlatform $platform, array $param
private function getSystemAttribute(Platforms\AbstractPlatform $platform): string
{
if ($platform instanceof Platforms\MariaDBPlatform) {
return TraceAttributeValues::DB_SYSTEM_MARIADB;
return 'mariadb';
}
if ($platform instanceof Platforms\PostgreSQLPlatform) {
return TraceAttributeValues::DB_SYSTEM_POSTGRESQL;
return 'postgresql';
}
if ($platform instanceof Platforms\AbstractMySQLPlatform) {
return TraceAttributeValues::DB_SYSTEM_MYSQL;
return 'mysql';
}
if ($platform instanceof Platforms\SQLServerPlatform) {
return TraceAttributeValues::DB_SYSTEM_MSSQL;
return 'mssql';
}
if ($platform instanceof Platforms\SqlitePlatform) {
return TraceAttributeValues::DB_SYSTEM_SQLITE;
return 'sqlite';
}
if ($platform instanceof Platforms\OraclePlatform) {
return TraceAttributeValues::DB_SYSTEM_ORACLE;
return 'oracle';
}
if ($platform instanceof Platforms\DB2Platform) {
return TraceAttributeValues::DB_SYSTEM_DB2;
return 'db2';
}

return TraceAttributeValues::DB_SYSTEM_OTHER_SQL;
return 'other_sql';
}
}
3 changes: 1 addition & 2 deletions src/Semantics/Attribute/MessageAttributeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace Instrumentation\Semantics\Attribute;

use OpenTelemetry\SemConv\TraceAttributes;
use OpenTelemetry\SemConv\TraceAttributeValues;
use Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpReceivedStamp;
use Symfony\Component\Messenger\Bridge\Redis\Transport\RedisReceivedStamp;
use Symfony\Component\Messenger\Envelope;
Expand All @@ -22,7 +21,7 @@ class MessageAttributeProvider implements MessageAttributeProviderInterface
public function getAttributes(Envelope $envelope): array
{
$attributes = [
TraceAttributes::MESSAGING_DESTINATION_KIND => TraceAttributeValues::MESSAGING_DESTINATION_KIND_QUEUE,
TraceAttributes::MESSAGING_DESTINATION_KIND => 'queue',
'messenger.message' => \get_class($envelope->getMessage()),
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface MessageAttributeProviderInterface
* @return array{
* 'messenger.message':class-string,
* 'messenger.bus'?:string,
* 'messaging.destination_kind':'queue'|'topic',
* 'messaging.destination.kind':'queue'|'topic',
* 'messaging.system'?:'rabbitmq'|'redis',
* 'messaging.protocol'?:'AMQP',
* 'messaging.message_id'?:string
Expand Down
2 changes: 1 addition & 1 deletion src/Semantics/Normalizer/ExceptionNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ExceptionNormalizer
public static function normalizeException(\Throwable $exception): array
{
return [
'type' => \get_class($exception),
'type' => $exception::class,
'message' => 'PHP Warning: '.(string) $exception,
// Stacktrace is already included in message
// 'stacktrace' => $exception->getTraceAsString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@

namespace Instrumentation\Semantics\OperationName;

use OpenTelemetry\SemConv\TraceAttributeValues;
use Symfony\Component\Messenger\Envelope;

interface MessageOperationNameResolverInterface
{
/**
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.9.0/specification/trace/semantic_conventions/messaging.md#operation-names
*
* @param TraceAttributeValues::MESSAGING_OPERATION_* $operation One of 'send', 'receive' or 'process'
* @param string $operation One of 'send', 'receive' or 'process'
*
* @return string&non-empty-string
*/
Expand Down
3 changes: 0 additions & 3 deletions src/Tracing/Instrumentation/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ public function query(string $sql): Result
return $this->trace(self::OP_CONN_QUERY, $sql, fn (): Result => $this->decorated->query($sql));
}

/**
* @return mixed
*/
public function quote($value, $type = ParameterType::STRING)
{
return $this->decorated->quote($value, $type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use OpenTelemetry\SDK\Trace\Span;
use OpenTelemetry\SDK\Trace\SpanProcessorInterface;
use OpenTelemetry\SDK\Trace\TracerProvider;
use OpenTelemetry\SemConv\TraceAttributeValues;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Event\AbstractWorkerMessageEvent;
Expand Down Expand Up @@ -71,7 +70,7 @@ public function onConsume(WorkerMessageReceivedEvent $event): void
if ($this->createSubSpan) {
$operationName = $this->operationNameResolver->getOperationName(
$event->getEnvelope(),
TraceAttributeValues::MESSAGING_OPERATION_PROCESS
'process'
);

$strategy = $this->getStrategy($event->getEnvelope());
Expand Down
2 changes: 1 addition & 1 deletion src/Tracing/Instrumentation/TracerAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function startSpan(string $name, array $attributes = []): SpanInterfac
* @param array<string,string> $attributes
* @param SpanKind::KIND_* $kind
*/
protected function traceFunction(string $name, array $attributes, callable $callback, ?Context $parentContext = null, ?int $kind = null): mixed
protected function traceFunction(string $name, array $attributes, callable $callback, Context $parentContext = null, int $kind = null): mixed
{
$span = $this->getTracer()
->spanBuilder($name) // @phpstan-ignore-line
Expand Down
2 changes: 1 addition & 1 deletion src/Tracing/Propagation/ContextInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function fromW3CHeader(string $header): ScopeInterface
return static::activateContext($header);
}

public static function activateContext(string $parent, ?string $state = null): ScopeInterface
public static function activateContext(string $parent, string $state = null): ScopeInterface
{
$context = TraceContextPropagator::getInstance()->extract(array_filter([
TraceContextPropagator::TRACEPARENT => $parent,
Expand Down
2 changes: 1 addition & 1 deletion src/Tracing/Tracer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(private BaseTracerInterface $decorated)
{
}

public function trace(string $operation, ?array $attributes = null, ?int $kind = null, ?Context $parentContext = null): SpanInterface
public function trace(string $operation, array $attributes = null, int $kind = null, Context $parentContext = null): SpanInterface
{
return $this->decorated->spanBuilder($operation)
->setAttributes($attributes ?: [])
Expand Down
2 changes: 1 addition & 1 deletion src/Tracing/TracerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ interface TracerInterface extends BaseTracerInterface
* @param array<string,string> $attributes
* @param SpanKind::KIND_* $kind
*/
public function trace(string $operation, ?array $attributes = null, ?int $kind = null, ?Context $parentContext = null): SpanInterface;
public function trace(string $operation, array $attributes = null, int $kind = null, Context $parentContext = null): SpanInterface;
}
2 changes: 1 addition & 1 deletion src/Tracing/Tracing.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class Tracing
* @param array<string,string> $attributes
* @param SpanKind::KIND_* $kind
*/
public static function trace(string $operation, ?array $attributes = null, ?int $kind = null, ?Context $parentContext = null): SpanInterface
public static function trace(string $operation, array $attributes = null, int $kind = null, Context $parentContext = null): SpanInterface
{
return static::getTracer()->spanBuilder($operation)
->setAttributes($attributes ?: [])
Expand Down
2 changes: 1 addition & 1 deletion src/Tracing/Twig/Extension/TracingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getTraceId(): string
return Span::getCurrent()->getContext()->getTraceId();
}

public function getTraceUrl(?string $traceId = null): ?string
public function getTraceUrl(string $traceId = null): ?string
{
if ($traceId && $this->traceUrlGenerator) {
return $this->traceUrlGenerator->getTraceUrl($traceId);
Expand Down

0 comments on commit 47d829f

Please sign in to comment.