Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ on:
permissions:
contents: read

env:
FRANKENPHP_VERSION: v1.11.2
ROADRUNNER_VERSION: v2025.1.7

# Cancel in progress workflows on pull_requests.
# https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
concurrency:
Expand Down Expand Up @@ -71,6 +75,10 @@ jobs:
- name: Remove unused dependencies
run: composer remove vimeo/psalm phpstan/phpstan friendsofphp/php-cs-fixer --dev --no-interaction --no-update

- name: Remove RoadRunner dependencies on unsupported PHP versions
if: ${{ matrix.os == 'windows-latest' || matrix.php.version == '7.2' || matrix.php.version == '7.3' || matrix.php.version == '7.4' || matrix.php.version == '8.0' }}
run: composer remove spiral/roadrunner-http spiral/roadrunner-worker --dev --no-interaction --no-update

- name: Set phpunit/phpunit version constraint
run: composer require phpunit/phpunit:'${{ matrix.php.phpunit }}' --dev --no-interaction --no-update

Expand All @@ -96,3 +104,138 @@ jobs:
- name: Check benchmarks
run: vendor/bin/phpbench run --revs=1 --iterations=1
if: ${{ matrix.dependencies == 'highest' && matrix.php.version == '8.4' }}

runtime-tests-frankenphp:
name: Runtime tests (FrankenPHP)
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: none

- name: Determine Composer cache directory
id: composer-cache
run: echo "directory=$(composer config cache-dir)" >> "$GITHUB_OUTPUT"
shell: bash

- name: Cache Composer dependencies
uses: actions/cache@v5
with:
path: ${{ steps.composer-cache.outputs.directory }}
key: ${{ runner.os }}-runtime-frankenphp-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-runtime-frankenphp-composer-

- name: Install dependencies
run: composer install --no-progress --no-interaction --prefer-dist

- name: Install FrankenPHP
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail

case "$(uname -m)" in
x86_64) asset="frankenphp-linux-x86_64" ;;
aarch64|arm64) asset="frankenphp-linux-aarch64" ;;
*) echo "Unsupported architecture: $(uname -m)"; exit 1 ;;
esac

digest="$(gh api "repos/php/frankenphp/releases/tags/${FRANKENPHP_VERSION}" --jq ".assets[] | select(.name == \"${asset}\") | .digest")"

if [ -z "${digest}" ]; then
echo "Unable to resolve digest for ${asset} (${FRANKENPHP_VERSION})."
exit 1
fi

gh release download "${FRANKENPHP_VERSION}" \
--repo php/frankenphp \
--pattern "${asset}" \
--output "${asset}"

echo "${digest#sha256:} ${asset}" | sha256sum --check --
mkdir -p "${RUNNER_TEMP}/bin"
install -m 0755 "${asset}" "${RUNNER_TEMP}/bin/frankenphp"
echo "${RUNNER_TEMP}/bin" >> "${GITHUB_PATH}"
"${RUNNER_TEMP}/bin/frankenphp" version
shell: bash

- name: Run PHPUnit tests (excluding PHPT)
run: vendor/bin/phpunit tests --test-suffix Test.php --verbose

runtime-tests-roadrunner:
name: Runtime tests (RoadRunner)
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: none

- name: Determine Composer cache directory
id: composer-cache
run: echo "directory=$(composer config cache-dir)" >> "$GITHUB_OUTPUT"
shell: bash

- name: Cache Composer dependencies
uses: actions/cache@v5
with:
path: ${{ steps.composer-cache.outputs.directory }}
key: ${{ runner.os }}-runtime-roadrunner-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-runtime-roadrunner-composer-

- name: Install dependencies
run: composer install --no-progress --no-interaction --prefer-dist

- name: Install RoadRunner
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail

case "$(uname -m)" in
x86_64) arch="amd64" ;;
aarch64|arm64) arch="arm64" ;;
*) echo "Unsupported architecture: $(uname -m)"; exit 1 ;;
esac

version_no_prefix="${ROADRUNNER_VERSION#v}"
asset="roadrunner-${version_no_prefix}-linux-${arch}.tar.gz"

digest="$(gh api "repos/roadrunner-server/roadrunner/releases/tags/${ROADRUNNER_VERSION}" --jq ".assets[] | select(.name == \"${asset}\") | .digest")"

if [ -z "${digest}" ]; then
echo "Unable to resolve digest for ${asset} (${ROADRUNNER_VERSION})."
exit 1
fi

gh release download "${ROADRUNNER_VERSION}" \
--repo roadrunner-server/roadrunner \
--pattern "${asset}" \
--output "${asset}"

echo "${digest#sha256:} ${asset}" | sha256sum --check --
tar -xzf "${asset}" --strip-components=1 "${asset%.tar.gz}/rr"
mkdir -p "${RUNNER_TEMP}/bin"
install -m 0755 rr "${RUNNER_TEMP}/bin/rr"
echo "${RUNNER_TEMP}/bin" >> "${GITHUB_PATH}"
"${RUNNER_TEMP}/bin/rr" --version
shell: bash

- name: Run PHPUnit tests (excluding PHPT)
run: vendor/bin/phpunit tests --test-suffix Test.php --verbose

3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@
"guzzlehttp/promises": "^2.0.3",
"guzzlehttp/psr7": "^1.8.4|^2.1.1",
"monolog/monolog": "^1.6|^2.0|^3.0",
"nyholm/psr7": "^1.8",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "^1.3",
"phpunit/phpunit": "^8.5.52|^9.6.34",
"spiral/roadrunner-http": "^3.6",
"spiral/roadrunner-worker": "^3.6",
"vimeo/psalm": "^4.17"
},
"suggest": {
Expand Down
23 changes: 9 additions & 14 deletions src/Logs/Logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Sentry\Logs;

use Sentry\EventId;
use Sentry\SentrySdk;

class Logs
{
Expand All @@ -13,14 +14,8 @@ class Logs
*/
private static $instance;

/**
* @var LogsAggregator
*/
private $aggregator;

private function __construct()
{
$this->aggregator = new LogsAggregator();
}

public static function getInstance(): self
Expand All @@ -39,7 +34,7 @@ public static function getInstance(): self
*/
public function trace(string $message, array $values = [], array $attributes = []): void
{
$this->aggregator->add(LogLevel::trace(), $message, $values, $attributes);
$this->aggregator()->add(LogLevel::trace(), $message, $values, $attributes);
}

/**
Expand All @@ -49,7 +44,7 @@ public function trace(string $message, array $values = [], array $attributes = [
*/
public function debug(string $message, array $values = [], array $attributes = []): void
{
$this->aggregator->add(LogLevel::debug(), $message, $values, $attributes);
$this->aggregator()->add(LogLevel::debug(), $message, $values, $attributes);
}

/**
Expand All @@ -59,7 +54,7 @@ public function debug(string $message, array $values = [], array $attributes = [
*/
public function info(string $message, array $values = [], array $attributes = []): void
{
$this->aggregator->add(LogLevel::info(), $message, $values, $attributes);
$this->aggregator()->add(LogLevel::info(), $message, $values, $attributes);
}

/**
Expand All @@ -69,7 +64,7 @@ public function info(string $message, array $values = [], array $attributes = []
*/
public function warn(string $message, array $values = [], array $attributes = []): void
{
$this->aggregator->add(LogLevel::warn(), $message, $values, $attributes);
$this->aggregator()->add(LogLevel::warn(), $message, $values, $attributes);
}

/**
Expand All @@ -79,7 +74,7 @@ public function warn(string $message, array $values = [], array $attributes = []
*/
public function error(string $message, array $values = [], array $attributes = []): void
{
$this->aggregator->add(LogLevel::error(), $message, $values, $attributes);
$this->aggregator()->add(LogLevel::error(), $message, $values, $attributes);
}

/**
Expand All @@ -89,15 +84,15 @@ public function error(string $message, array $values = [], array $attributes = [
*/
public function fatal(string $message, array $values = [], array $attributes = []): void
{
$this->aggregator->add(LogLevel::fatal(), $message, $values, $attributes);
$this->aggregator()->add(LogLevel::fatal(), $message, $values, $attributes);
}

/**
* Flush the captured logs and send them to Sentry.
*/
public function flush(): ?EventId
{
return $this->aggregator->flush();
return $this->aggregator()->flush();
}

/**
Expand All @@ -107,6 +102,6 @@ public function flush(): ?EventId
*/
public function aggregator(): LogsAggregator
{
return $this->aggregator;
return SentrySdk::getCurrentRuntimeContext()->getLogsAggregator();
}
}
4 changes: 2 additions & 2 deletions src/Logs/LogsAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ public function add(
$this->logs[] = $log;
}

public function flush(): ?EventId
public function flush(?HubInterface $hub = null): ?EventId
{
if (empty($this->logs)) {
return null;
}

$hub = SentrySdk::getCurrentHub();
$hub = $hub ?? SentrySdk::getCurrentHub();
$event = Event::createLogs()->setLogs($this->logs);

$this->logs = [];
Expand Down
5 changes: 3 additions & 2 deletions src/Metrics/MetricsAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Sentry\Metrics\Types\GaugeMetric;
use Sentry\Metrics\Types\Metric;
use Sentry\SentrySdk;
use Sentry\State\HubInterface;
use Sentry\State\Scope;
use Sentry\Unit;
use Sentry\Util\RingBuffer;
Expand Down Expand Up @@ -134,13 +135,13 @@ public function add(
$this->metrics->push($metric);
}

public function flush(): ?EventId
public function flush(?HubInterface $hub = null): ?EventId
{
if ($this->metrics->isEmpty()) {
return null;
}

$hub = SentrySdk::getCurrentHub();
$hub = $hub ?? SentrySdk::getCurrentHub();
$event = Event::createMetrics()->setMetrics($this->metrics->drain());

return $hub->captureEvent($event);
Expand Down
20 changes: 10 additions & 10 deletions src/Metrics/TraceMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Sentry\Metrics\Types\CounterMetric;
use Sentry\Metrics\Types\DistributionMetric;
use Sentry\Metrics\Types\GaugeMetric;
use Sentry\SentrySdk;
use Sentry\Unit;

class TraceMetrics
Expand All @@ -17,14 +18,8 @@ class TraceMetrics
*/
private static $instance;

/**
* @var MetricsAggregator
*/
private $aggregator;

public function __construct()
{
$this->aggregator = new MetricsAggregator();
}

public static function getInstance(): self
Expand All @@ -46,7 +41,7 @@ public function count(
array $attributes = [],
?Unit $unit = null
): void {
$this->aggregator->add(
$this->aggregator()->add(
CounterMetric::TYPE,
$name,
$value,
Expand All @@ -65,7 +60,7 @@ public function distribution(
array $attributes = [],
?Unit $unit = null
): void {
$this->aggregator->add(
$this->aggregator()->add(
DistributionMetric::TYPE,
$name,
$value,
Expand All @@ -84,7 +79,7 @@ public function gauge(
array $attributes = [],
?Unit $unit = null
): void {
$this->aggregator->add(
$this->aggregator()->add(
GaugeMetric::TYPE,
$name,
$value,
Expand All @@ -95,6 +90,11 @@ public function gauge(

public function flush(): ?EventId
{
return $this->aggregator->flush();
return $this->aggregator()->flush();
}

private function aggregator(): MetricsAggregator
{
return SentrySdk::getCurrentRuntimeContext()->getMetricsAggregator();
}
}
Loading