Skip to content

Commit

Permalink
chore: reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
plunkettscott committed Feb 25, 2023
1 parent 67e19fd commit 89d6766
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 44 deletions.
1 change: 0 additions & 1 deletion src/Concerns/InteractsWithCurrentSpan.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace PlunkettScott\LaravelOpenTelemetry\Concerns;

use Exception;
use OpenTelemetry\SDK\Trace\Span;
use PlunkettScott\LaravelOpenTelemetry\CurrentSpan;

trait InteractsWithCurrentSpan
Expand Down
19 changes: 10 additions & 9 deletions src/Otel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@
namespace PlunkettScott\LaravelOpenTelemetry;

use Illuminate\Foundation\Application;
use OpenTelemetry\API\Trace\NoopSpanBuilder;
use OpenTelemetry\API\Trace\NoopTracer;
use OpenTelemetry\API\Trace\SpanInterface;
use OpenTelemetry\API\Trace\SpanKind;
use OpenTelemetry\API\Trace\StatusCode;
use OpenTelemetry\API\Trace\TracerInterface;
use OpenTelemetry\Context\Context;
use OpenTelemetry\SDK\Trace\TracerProviderInterface;
use PlunkettScott\LaravelOpenTelemetry\Contracts\NamedSpanManagerContract;
use Throwable;

class Otel
{
use Concerns\RegistersWatchers,
Concerns\InteractsWithCurrentSpan;

static public TracerInterface $tracer;
public static TracerInterface $tracer;

/**
* Start OpenTelemetry for Laravel
Expand Down Expand Up @@ -80,17 +77,21 @@ public static function tracer(): TracerInterface
* scope. The scope must be detached and the span must be ended manually. Passing the returned array to spanEnd will
* end the span and detach the scope for you.
*
* @param string $name The name of the span
* @param callable|null $callable A callable that will be executed within the span context. The activated Span will be passed as the first argument.
* @param int $kind The kind of span to create. Defaults to SpanKind::KIND_INTERNAL
* @param iterable $attributes Attributes to add to the span. Defaults to an empty array, but can be any iterable.
* @param string $name The name of the span
* @param callable|null $callable A callable that will be executed within the span context. The activated Span will be passed as the first argument.
* @param int $kind The kind of span to create. Defaults to SpanKind::KIND_INTERNAL
* @param iterable $attributes Attributes to add to the span. Defaults to an empty array, but can be any iterable.
* @return mixed The result of the callable
*
* @throws Throwable If the callable throws an exception, it will be rethrown and the span will be ended with the exception recorded.
*/
public static function span(string $name, callable $callable = null, int $kind = SpanKind::KIND_INTERNAL, iterable $attributes = []): mixed
{
if (! config('otel.enabled')) {
if (is_null($callable)) return null;
if (is_null($callable)) {
return null;
}

return $callable(CurrentSpan::get());
}

Expand Down
4 changes: 0 additions & 4 deletions src/OtelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
namespace PlunkettScott\LaravelOpenTelemetry;

use Illuminate\Support\ServiceProvider;
use OpenTelemetry\API\Trace\TracerInterface;
use OpenTelemetry\API\Trace\TracerProviderInterface;
use PlunkettScott\LaravelOpenTelemetry\Console\Commands;
use PlunkettScott\LaravelOpenTelemetry\Contracts\NamedSpanManagerContract;
use PlunkettScott\LaravelOpenTelemetry\Support\NamedSpanManager;

class OtelServiceProvider extends ServiceProvider
{
Expand Down
2 changes: 1 addition & 1 deletion src/Watchers/CacheWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CacheWatcher extends Watcher
public ?string $optionsClass = CacheWatcherOptions::class;

/**
* @inheritDoc
* {@inheritDoc}
*/
public function register(Application $app): void
{
Expand Down
10 changes: 5 additions & 5 deletions src/Watchers/CacheWatcherOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
final readonly class CacheWatcherOptions extends WatcherOptions
{
/**
* @param bool $record_cache_hit When true, cache hits will be recorded as span events.
* @param bool $record_cache_miss When true, cache misses will be recorded as span events.
* @param bool $record_cache_set When true, cache sets will be recorded as span events.
* @param bool $record_cache_forget When true, cache forgets will be recorded as span events.
* @param array $ignored An array of cache keys to ignore. Accepts wildcards, e.g. 'users.*'.
* @param bool $record_cache_hit When true, cache hits will be recorded as span events.
* @param bool $record_cache_miss When true, cache misses will be recorded as span events.
* @param bool $record_cache_set When true, cache sets will be recorded as span events.
* @param bool $record_cache_forget When true, cache forgets will be recorded as span events.
* @param array $ignored An array of cache keys to ignore. Accepts wildcards, e.g. 'users.*'.
*/
public function __construct(
public bool $record_cache_hit = true,
Expand Down
2 changes: 1 addition & 1 deletion src/Watchers/ClientRequestWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function recordRequest(RequestSending $request): void
$processedUrl = $parsedUrl->get('scheme').'://'.$parsedUrl->get('host').$parsedUrl->get('path', '');

if ($parsedUrl->has('query')) {
$processedUrl .= '?' . $parsedUrl->get('query');
$processedUrl .= '?'.$parsedUrl->get('query');
}

$span = $this->tracer->spanBuilder('http '.$request->request->method().' '.$request->request->url())
Expand Down
31 changes: 8 additions & 23 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
* Returns an OpenTelemetry tracer instance. If OpenTelemetry is not enabled,
* a NoopTracer will be returned instead making this function safe to call
* in all environments.
*
* @return TracerInterface
*/
function tracer(): TracerInterface
{
Expand All @@ -27,10 +25,10 @@ function tracer(): TracerInterface
* be ended when the callable returns or throws an exception. The callable may
* modify the active span by accepting a SpanInterface as its first argument.
*
* @param string $name The name of the span
* @param callable $callable A callable that will be executed within the span context. The activated Span will be passed as the first argument.
* @param int $kind The kind of span to create. Defaults to SpanKind::KIND_INTERNAL
* @param iterable $attributes Attributes to add to the span. Defaults to an empty array, but can be any iterable.
* @param string $name The name of the span
* @param callable $callable A callable that will be executed within the span context. The activated Span will be passed as the first argument.
* @param int $kind The kind of span to create. Defaults to SpanKind::KIND_INTERNAL
* @param iterable $attributes Attributes to add to the span. Defaults to an empty array, but can be any iterable.
* @return mixed The result of the callable
*
* @throws Throwable If the callable throws an exception, it will be rethrown and the span will be ended with the exception recorded.
Expand All @@ -43,9 +41,8 @@ function span(string $name, callable $callable, int $kind = SpanKind::KIND_INTER

if (! function_exists('span_event')) {
/**
* @param string $name Event name
* @param iterable $attributes Event attributes
* @return SpanInterface
* @param string $name Event name
* @param iterable $attributes Event attributes
*/
function span_event(string $name, iterable $attributes = []): SpanInterface
{
Expand All @@ -55,9 +52,8 @@ function span_event(string $name, iterable $attributes = []): SpanInterface

if (! function_exists('span_attribute')) {
/**
* @param string $name Attribute name
* @param mixed $value Attribute value
* @return SpanInterface
* @param string $name Attribute name
* @param mixed $value Attribute value
*/
function span_attribute(string $name, mixed $value): SpanInterface
{
Expand All @@ -68,9 +64,6 @@ function span_attribute(string $name, mixed $value): SpanInterface
if (! function_exists('span_error')) {
/**
* Set the Span status to Error with an optional description.
*
* @param string|null $description
* @return SpanInterface
*/
function span_error(string $description = null): SpanInterface
{
Expand All @@ -82,10 +75,6 @@ function span_error(string $description = null): SpanInterface
/**
* Set the Span status to Error if the condition is true. Otherwise, return
* the current span.
*
* @param bool $condition
* @param string|null $description
* @return SpanInterface
*/
function span_error_if(bool $condition, string $description = null): SpanInterface
{
Expand All @@ -97,10 +86,6 @@ function span_error_if(bool $condition, string $description = null): SpanInterfa
/**
* Set the Span status to Error if the condition is false. Otherwise, return
* the current span.
*
* @param bool $condition
* @param string|null $description
* @return SpanInterface
*/
function span_error_unless(bool $condition, string $description = null): SpanInterface
{
Expand Down

0 comments on commit 89d6766

Please sign in to comment.