Skip to content

Commit

Permalink
changes for Lumen support
Browse files Browse the repository at this point in the history
  • Loading branch information
dkudrin committed Apr 3, 2024
1 parent 83f0504 commit 5664521
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 108 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

This is a read-only subtree split of https://github.com/open-telemetry/opentelemetry-php-contrib.

# OpenTelemetry Laravel auto-instrumentation
# OpenTelemetry Lumen auto-instrumentation

Please read https://opentelemetry.io/docs/instrumentation/php/automatic/ for instructions on how to
install and configure the extension and SDK.
Expand Down
6 changes: 3 additions & 3 deletions _register.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

use OpenTelemetry\Contrib\Instrumentation\Laravel\LaravelInstrumentation;
use OpenTelemetry\Contrib\Instrumentation\Lumen\LumenInstrumentation;
use OpenTelemetry\SDK\Sdk;

if (class_exists(Sdk::class) && Sdk::isInstrumentationDisabled(LaravelInstrumentation::NAME) === true) {
if (class_exists(Sdk::class) && Sdk::isInstrumentationDisabled(LumenInstrumentation::NAME) === true) {
return;
}

Expand All @@ -15,4 +15,4 @@
return;
}

LaravelInstrumentation::register();
LumenInstrumentation::register();
29 changes: 7 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "open-telemetry/opentelemetry-auto-laravel",
"description": "OpenTelemetry auto-instrumentation for Laravel",
"keywords": ["opentelemetry", "otel", "open-telemetry", "tracing", "laravel", "instrumentation"],
"name": "open-telemetry/opentelemetry-auto-lumen",
"description": "OpenTelemetry auto-instrumentation for Lumen",
"keywords": ["opentelemetry", "otel", "open-telemetry", "tracing", "lumen", "instrumentation"],
"type": "library",
"homepage": "https://opentelemetry.io/docs/php",
"readme": "./README.md",
Expand All @@ -11,37 +11,22 @@
"php": "^8.0",
"ext-json": "*",
"ext-opentelemetry": "*",
"laravel/framework": ">=6.0",
"illuminate/routing": "8.x-dev",
"laravel/lumen-framework": "^8.0",
"open-telemetry/api": "^1.0",
"open-telemetry/sem-conv": "^1.23"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3",
"guzzlehttp/guzzle": "*",
"laravel/tinker": "*",
"nunomaduro/collision": "*",
"open-telemetry/sdk": "^1.0",
"orchestra/testbench": ">=4.0",
"phan/phan": "^5.0",
"php-http/mock-client": "*",
"phpstan/phpstan": "^1.1",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5",
"psalm/plugin-phpunit": "^0.18.4",
"spatie/laravel-ignition": "*",
"vimeo/psalm": "^5.0"
},
"autoload": {
"psr-4": {
"OpenTelemetry\\Contrib\\Instrumentation\\Laravel\\": "src/"
"OpenTelemetry\\Contrib\\Instrumentation\\Lumen\\": "src/"
},
"files": [
"_register.php"
]
},
"autoload-dev": {
"psr-4": {
"OpenTelemetry\\Tests\\Contrib\\Instrumentation\\Laravel\\": "tests/"
"OpenTelemetry\\Tests\\Contrib\\Instrumentation\\Lumen\\": "tests/"
}
},
"config": {
Expand Down
2 changes: 1 addition & 1 deletion src/ConsoleInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace OpenTelemetry\Contrib\Instrumentation\Laravel;
namespace OpenTelemetry\Contrib\Instrumentation\Lumen;

use Illuminate\Console\Command;
use Illuminate\Contracts\Console\Kernel;
Expand Down
2 changes: 1 addition & 1 deletion src/HeadersPropagator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace OpenTelemetry\Contrib\Instrumentation\Laravel;
namespace OpenTelemetry\Contrib\Instrumentation\Lumen;

use function assert;
use Illuminate\Http\Request;
Expand Down
2 changes: 1 addition & 1 deletion src/HttpInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace OpenTelemetry\Contrib\Instrumentation\Laravel;
namespace OpenTelemetry\Contrib\Instrumentation\Lumen;

use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
Expand Down
69 changes: 0 additions & 69 deletions src/LaravelInstrumentation.php

This file was deleted.

48 changes: 48 additions & 0 deletions src/LumenInstrumentation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Contrib\Instrumentation\Lumen;

use Illuminate\Contracts\Foundation\Application;
use OpenTelemetry\API\Instrumentation\CachedInstrumentation;
use OpenTelemetry\Contrib\Instrumentation\Lumen\Watchers\CacheWatcher;
use OpenTelemetry\Contrib\Instrumentation\Lumen\Watchers\ClientRequestWatcher;
use OpenTelemetry\Contrib\Instrumentation\Lumen\Watchers\ExceptionWatcher;
use OpenTelemetry\Contrib\Instrumentation\Lumen\Watchers\LogWatcher;
use OpenTelemetry\Contrib\Instrumentation\Lumen\Watchers\QueryWatcher;
use OpenTelemetry\Contrib\Instrumentation\Lumen\Watchers\RequestWatcher;
use OpenTelemetry\Contrib\Instrumentation\Lumen\Watchers\Watcher;
use function OpenTelemetry\Instrumentation\hook;
use Throwable;

class LumenInstrumentation
{
public const NAME = 'lumen';

public static function registerWatchers(Application $app, Watcher $watcher)
{
$watcher->register($app);
}

public static function register(): void
{
$instrumentation = new CachedInstrumentation('io.opentelemetry.contrib.php.lumen');

hook(
Application::class,
'__construct',
post: static function (Application $application, array $params, mixed $returnValue, ?Throwable $exception) use ($instrumentation) {
self::registerWatchers($application, new CacheWatcher());
self::registerWatchers($application, new ClientRequestWatcher($instrumentation));
self::registerWatchers($application, new ExceptionWatcher());
self::registerWatchers($application, new LogWatcher());
self::registerWatchers($application, new QueryWatcher($instrumentation));
self::registerWatchers($application, new RequestWatcher());
},
);

ConsoleInstrumentation::register($instrumentation);
HttpInstrumentation::register($instrumentation);
}
}
2 changes: 1 addition & 1 deletion src/ResponsePropagationSetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace OpenTelemetry\Contrib\Instrumentation\Laravel;
namespace OpenTelemetry\Contrib\Instrumentation\Lumen;

use function assert;
use Illuminate\Http\Response;
Expand Down
7 changes: 4 additions & 3 deletions src/Watchers/CacheWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

declare(strict_types=1);

namespace OpenTelemetry\Contrib\Instrumentation\Laravel\Watchers;
namespace OpenTelemetry\Contrib\Instrumentation\Lumen\Watchers;

use Illuminate\Cache\Events\CacheHit;
use Illuminate\Cache\Events\CacheMissed;
use Illuminate\Cache\Events\KeyForgotten;
use Illuminate\Cache\Events\KeyWritten;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Facades\Date;
use OpenTelemetry\API\Trace\Span;
use OpenTelemetry\Context\Context;

Expand Down Expand Up @@ -50,13 +51,13 @@ public function recordCacheSet(KeyWritten $event): void
'key' => $event->key,
'tags' => json_encode($event->tags),
'expires_at' => $ttl > 0
? now()->addSeconds($ttl)->getTimestamp()
? Date::now()->addSeconds($ttl)->getTimestamp()
: 'never',
'expires_in_seconds' => $ttl > 0
? $ttl
: 'never',
'expires_in_human' => $ttl > 0
? now()->addSeconds($ttl)->diffForHumans()
? Date::now()->addSeconds($ttl)->diffForHumans()
: 'never',
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Watchers/ClientRequestWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace OpenTelemetry\Contrib\Instrumentation\Laravel\Watchers;
namespace OpenTelemetry\Contrib\Instrumentation\Lumen\Watchers;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Client\Events\ConnectionFailed;
Expand Down
2 changes: 1 addition & 1 deletion src/Watchers/ExceptionWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace OpenTelemetry\Contrib\Instrumentation\Laravel\Watchers;
namespace OpenTelemetry\Contrib\Instrumentation\Lumen\Watchers;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Log\Events\MessageLogged;
Expand Down
2 changes: 1 addition & 1 deletion src/Watchers/LogWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace OpenTelemetry\Contrib\Instrumentation\Laravel\Watchers;
namespace OpenTelemetry\Contrib\Instrumentation\Lumen\Watchers;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Log\Events\MessageLogged;
Expand Down
2 changes: 1 addition & 1 deletion src/Watchers/QueryWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace OpenTelemetry\Contrib\Instrumentation\Laravel\Watchers;
namespace OpenTelemetry\Contrib\Instrumentation\Lumen\Watchers;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Database\Events\QueryExecuted;
Expand Down
2 changes: 1 addition & 1 deletion src/Watchers/RequestWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace OpenTelemetry\Contrib\Instrumentation\Laravel\Watchers;
namespace OpenTelemetry\Contrib\Instrumentation\Lumen\Watchers;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Routing\Events\RouteMatched;
Expand Down
2 changes: 1 addition & 1 deletion src/Watchers/Watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace OpenTelemetry\Contrib\Instrumentation\Laravel\Watchers;
namespace OpenTelemetry\Contrib\Instrumentation\Lumen\Watchers;

use Illuminate\Contracts\Foundation\Application;

Expand Down

0 comments on commit 5664521

Please sign in to comment.