Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmastech committed Jul 14, 2024
1 parent 0f3f757 commit 721f344
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"orchestra/testbench": "^9.1",
"laravel/facade-documenter": "dev-main",
"phpstan/phpstan": "^1.11",
"datadog/php-datadogstatsd": "^1.6.1"
"datadog/php-datadogstatsd": "^1.6.1",
"cosmastech/psr-logger-spy": "^0.0.2"
},
"suggest": {
"datadog/php-datadogstatsd": "For DataDog stats",
Expand Down
3 changes: 2 additions & 1 deletion config/statsd-adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
"disable_telemetry" => null,
],
"log_datadog" => [
// see configuration options: https://docs.datadoghq.com/developers/dogstatsd/?code-lang=php&tab=hostagent#client-instantiation-parameters
"adapter" => "log_datadog",
"log_level" => "debug",
"log_channel" => null,
// see configuration options: https://docs.datadoghq.com/developers/dogstatsd/?code-lang=php&tab=hostagent#client-instantiation-parameters
"decimal_precision" => null,
"global_tags" => [],
"metric_prefix" => null,
Expand Down
6 changes: 5 additions & 1 deletion src/AdapterManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,13 @@ protected function createLog_datadogAdapter(array $config): DatadogStatsDClientA
protected function createLogDatadogAdapter(array $config): DatadogStatsDClientAdapter
{
$logLevel = $config['log_level'] ?? 'debug';
$logChannel = $config['log_channel'] ?? null;

$logManager = $this->app->make('log');
$logger = $logManager->channel($logChannel);

return new DatadogStatsDClientAdapter(
new DatadogLoggingClient($this->app->make('log'), $config, $logLevel),
new DatadogLoggingClient($logger, $config, $logLevel),
$this->getDefaultTags(),
clock: $this->getClockImplementation()
);
Expand Down
27 changes: 27 additions & 0 deletions tests/AdapterManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Cosmastech\LaravelStatsDAdapter\Tests;

use Cosmastech\PsrLoggerSpy\LogFactory;
use Cosmastech\PsrLoggerSpy\LoggerSpy;
use Cosmastech\StatsDClientAdapter\Adapters\Datadog\DatadogStatsDClientAdapter;
use Cosmastech\StatsDClientAdapter\Adapters\InMemory\InMemoryClientAdapter;
use Cosmastech\StatsDClientAdapter\Adapters\League\LeagueStatsDClientAdapter;
use Cosmastech\StatsDClientAdapter\Clients\Datadog\DatadogLoggingClient;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use League\StatsD\StatsDClient;
use PHPUnit\Framework\Attributes\Test;

Expand Down Expand Up @@ -74,6 +77,30 @@ public function instance_logDatadog_returnsConfiguredDatadogClient(): void
self::assertInstanceOf(DatadogLoggingClient::class, $datadogClientAdapter->getClient());
}

#[Test]
public function instance_logDatadog_logsToSpecifiedChannel(): void
{
// Given
//Config::set("logging.channels.null.handler");
$loggerSpy = new class(new LogFactory()) extends LoggerSpy {
public function pushProcessor() {

}
};
Log::extend("spy", fn() => $loggerSpy);
Config::set('statsd-adapter.channels.log_datadog.log_channel', "spy");
Config::set('logging.channels.spy', ["driver" => "spy"]);

// And
$datadogLoggingClientAdapter = $this->createAdapterManager()->instance("log_datadog");

// When
$datadogLoggingClientAdapter->increment("testing-counter");

// Then

}

public function instance_league_returnsConfiguredLeagueStatsDClient(): void
{
// Given
Expand Down

0 comments on commit 721f344

Please sign in to comment.