PHPackages                             cosmastech/statsd-client-adapter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. cosmastech/statsd-client-adapter

ActiveLibrary[HTTP &amp; Networking](/categories/http)

cosmastech/statsd-client-adapter
================================

A StatsD client adapter for use with DataDog or PHPLeague's statsd clients

0.5.0(9mo ago)39.7k↓33.3%[1 PRs](https://github.com/cosmastech/php-statsd-client-adapter/pulls)1WTFPLPHPPHP ^8.2CI passing

Since Jul 2Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/cosmastech/php-statsd-client-adapter)[ Packagist](https://packagist.org/packages/cosmastech/statsd-client-adapter)[ RSS](/packages/cosmastech-statsd-client-adapter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (17)Used By (1)

[![Latest Stable Version](https://camo.githubusercontent.com/9c9bc0b6c81914f2b7a06eb900c1ee14f6dde4d642b03f176053dd5eece11c6b/687474703a2f2f706f7365722e707567782e6f72672f636f736d6173746563682f7374617473642d636c69656e742d616461707465722f76)](https://packagist.org/packages/cosmastech/statsd-client-adapter) [![Total Downloads](https://camo.githubusercontent.com/8e214300e6d77373b37c1f475a83c642052cb97f6d2fa04aebe3e9f866e53a00/687474703a2f2f706f7365722e707567782e6f72672f636f736d6173746563682f7374617473642d636c69656e742d616461707465722f646f776e6c6f616473)](https://packagist.org/packages/cosmastech/statsd-client-adapter) [![License](https://camo.githubusercontent.com/0d8c67f98450e53573dffd8f11a8cc3f699a468d0ce01797ded193a6109b15c5/687474703a2f2f706f7365722e707567782e6f72672f636f736d6173746563682f7374617473642d636c69656e742d616461707465722f6c6963656e7365)](https://packagist.org/packages/cosmastech/statsd-client-adapter) [![PHP Version Require](https://camo.githubusercontent.com/051e25486185ea88ffafdb7e827d97bf56d716050e4ea5e2202eda34734f6ba8/687474703a2f2f706f7365722e707567782e6f72672f636f736d6173746563682f7374617473642d636c69656e742d616461707465722f726571756972652f706870)](https://packagist.org/packages/cosmastech/statsd-client-adapter)

StatsD Client Adapter
=====================

[](#statsd-client-adapter)

This package was originally designed to solve the problem of:

- I use DataDog on production, but
- I don't want to push stats to DataDog on my dev or test environments

Where might I want to push those precious stats? Maybe to a log? Maybe to a locally running [StatsD server](https://github.com/statsd/statsd)? What if in my unit tests, I want to confirm that logs are being pushed, but not go through the hassle of an integration test set up that configures the StatsD server?

While [PHP League's statsd package](https://github.com/thephpleague/statsd) is great, it doesn't allow for sending DataDog specific stats (such as [histogram](https://docs.datadoghq.com/metrics/types/?tab=histogram) or [distribution](https://docs.datadoghq.com/metrics/types/?tab=distribution)). Nor does the DataDog client allow for pushing to another StatsD implementation easily.

The aim here is to allow for a single interface that can wrap around both, and be easily extended for different implementations.

If you would like to use this library in Laravel, check out [laravel-statsd-adapter](https://github.com/cosmastech/laravel-statsd-adapter).

Adapters
--------

[](#adapters)

### InMemoryClientAdapter

[](#inmemoryclientadapter)

This adapter simply records your stats in an object in memory. This is best served as a way to verify stats are recorded in your unit tests.

See [examples/in\_memory.php](examples/in_memory.php) for how you might implement this.

### DataDogStatsDClientAdapter

[](#datadogstatsdclientadapter)

This is a wrapper around DataDog's [php-datadogstatsd](https://github.com/dataDog/php-datadogstatsd/) client.

If you wish to use this adapter, please make sure you install the php-datadogstatsd client.

```
composer require datadog/php-datadogstatsd
```

For specifics on their configuration, see the [official DogStatsD documentation](https://docs.datadoghq.com/developers/dogstatsd/?code-lang=php&tab=hostagent#client-instantiation-parameters).

See [examples/datadog.php](examples/datadog.php) for how you might implement this.

### DatadogLoggingClient

[](#datadogloggingclient)

Envisioned as a client for local development, this adapter writes to a class which implements the [psr-logger interface](https://packagist.org/packages/psr/log). You can find a [list](https://packagist.org/providers/psr/log-implementation) of packages that implement the interface on packagist. If you are using a framework like Symfony or Laravel, then you already have one of the most popular and reliable implementations installed: [monolog/monolog](https://github.com/Seldaek/monolog).

For a local development setup, you could just write the stats to a log. This writes the format exactly as it would be sent to DataDog.

See [examples/log\_datadog.php](examples/log_datadog.php) for how you might implement this.

### ExceptionCatchingDatadogClient

[](#exceptioncatchingdatadogclient)

This client will allow handling exceptions thrown when attempting to write data to DataDog.

See [examples/safe\_datadog.php](examples/safe_datadog.php) for how to use this client.

### LeagueStatsDClientAdapter

[](#leaguestatsdclientadapter)

You can also write to an arbitrary statsd server by leveraging [PHP League's statsd package](https://github.com/thephpleague/statsd).

First ensure that the package has been installed.

```
composer require league/statsd
```

For information on how to configure Client, [read their documentation](https://github.com/thephpleague/statsd?tab=readme-ov-file#configuring).

**Note** the `histogram()` and `distribution()` methods are both no-op by default, as they are not available on statsd.

See [examples/league.php](examples/league.php) for how you might implement this.

Gotchas
-------

[](#gotchas)

1. Only increment/decrement on DataDog's implementation allow for including the sample rate. If you are using a sample rate with other calls, their sample rate will not be included as part of the stat.
2. There are `histogram()` and `distribution()` methods on `LeagueStatsDClientAdapter`, but they will not be sent to statsd.

Testing
-------

[](#testing)

```
composer test
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance58

Moderate activity, may be stable

Popularity29

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~40 days

Recently: every ~100 days

Total

11

Last Release

277d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4bb00a9977a8feb9d2b17a7d1c901126d0df89483f11cbb27332008a0a6595c4?d=identicon)[cosmastech](/maintainers/cosmastech)

---

Top Contributors

[![cosmastech](https://avatars.githubusercontent.com/u/42181698?v=4)](https://github.com/cosmastech "cosmastech (63 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/cosmastech-statsd-client-adapter/health.svg)

```
[![Health](https://phpackages.com/badges/cosmastech-statsd-client-adapter/health.svg)](https://phpackages.com/packages/cosmastech-statsd-client-adapter)
```

###  Alternatives

[symfony/http-kernel

Provides a structured process for converting a Request into a Response

8.1k822.4M6.8k](/packages/symfony-http-kernel)[zircote/swagger-php

Generate interactive documentation for your RESTful API using PHP attributes (preferred) or PHPDoc annotations

5.3k132.9M468](/packages/zircote-swagger-php)[symfony/http-client

Provides powerful methods to fetch HTTP resources synchronously or asynchronously

2.0k314.0M3.4k](/packages/symfony-http-client)[nelmio/api-doc-bundle

Generates documentation for your REST API from attributes

2.3k63.6M233](/packages/nelmio-api-doc-bundle)[shopify/shopify-api

Shopify API Library for PHP

4634.8M16](/packages/shopify-shopify-api)[api-platform/metadata

API Resource-oriented metadata attributes and factories

243.5M96](/packages/api-platform-metadata)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
