Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
36 changes: 25 additions & 11 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,57 +87,71 @@ jobs:
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-${{ matrix.php-version }}-php-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-${{ matrix.php-version }}-vendor-${{ hashFiles('composer.json') }}
restore-keys: |
${{ runner.os }}-${{ matrix.php-version }}-php-
${{ runner.os }}-${{ matrix.php-version }}-vendor-
- name: Cache test tools
id: test-tools-cache
uses: actions/cache@v4
with:
path: vendor-bin
key: ${{ runner.os }}-${{ matrix.php-version }}-php-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-${{ matrix.php-version }}-vendor-bin-${{ hashFiles('vendor-bin/*/composer.json') }}
restore-keys: |
${{ runner.os }}-${{ matrix.php-version }}-php-
${{ runner.os }}-${{ matrix.php-version }}-vendor-bin-

- name: Install dependencies
id: composer
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress ${{ matrix.composer_args }}
run: |
composer --version
composer install --prefer-dist --no-progress ${{ matrix.composer_args }}

- name: Check Style
id: style
continue-on-error: ${{ matrix.experimental }}
env:
PHP_CS_FIXER_IGNORE_ENV: 1
run: vendor-bin/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --dry-run --stop-on-violation --using-cache=no -vvv
run: |
vendor-bin/php-cs-fixer/vendor/bin/php-cs-fixer --version
vendor-bin/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --dry-run --stop-on-violation --using-cache=no -vvv

- name: Check Dependencies
id: deps
continue-on-error: ${{ matrix.experimental }}
run: vendor-bin/deptrac/vendor/bin/deptrac --formatter=github-actions --report-uncovered
run: |
vendor-bin/deptrac/vendor/bin/deptrac --version
vendor-bin/deptrac/vendor/bin/deptrac --formatter=github-actions --report-uncovered

- name: Run Phan
id: phan
continue-on-error: ${{ matrix.experimental }}
env:
XDEBUG_MODE: off
PHAN_DISABLE_XDEBUG_WARN: 1
run: vendor-bin/phan/vendor/bin/phan
run: |
vendor-bin/phan/vendor/bin/phan --version
vendor-bin/phan/vendor/bin/phan

- name: Run Psalm
id: psalm
continue-on-error: ${{ matrix.experimental }}
run: vendor-bin/psalm/vendor/bin/psalm --output-format=github
run: |
vendor-bin/psalm/vendor/bin/psalm --version
vendor-bin/psalm/vendor/bin/psalm --output-format=github

- name: Run Phpstan
id: phpstan
continue-on-error: ${{ matrix.experimental }}
run: vendor/bin/phpstan analyse --error-format=github
run: |
vendor/bin/phpstan --version
vendor/bin/phpstan analyse --error-format=github

- name: Run PHPUnit (unit tests)
id: unit
continue-on-error: ${{ matrix.experimental }}
run: php -dzend.assertions=1 vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover --testsuite unit
run: |
vendor/bin/phpunit --version
php -dzend.assertions=1 vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover --testsuite unit

- name: Run PHPUnit (integration tests)
id: integration
Expand Down
1 change: 1 addition & 0 deletions .phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
'PhanAccessPropertyInternal',
'PhanTypeMismatchPropertyReal',
'PhanTemplateTypeNotUsedInFunctionReturn',
'PhanUndeclaredClassAttribute',
],

// A regular expression to match files to be excluded
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ DOCKER_COMPOSE ?= docker compose
DC_RUN_PHP = $(DOCKER_COMPOSE) run --rm php

.DEFAULT_GOAL : help
.PHONY: deptrac

help: ## Show this help
@printf "\033[33m%s:\033[0m\n" 'Available commands'
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"symfony/config": "^5.4 || ^6.4 || ^7.0",
"symfony/polyfill-mbstring": "^1.23",
"symfony/polyfill-php82": "^1.26",
"symfony/polyfill-php83": "^1.32",
"symfony/polyfill-php84": "^1.32",
"tbachert/spi": "^1.0.1"
},
"config": {
Expand Down Expand Up @@ -98,7 +100,7 @@
"open-telemetry/dev-tools": "dev-main",
"php-http/mock-client": "^1.5",
"phpdocumentor/reflection-docblock": "^5.3",
"phpspec/prophecy": "^1.17.0",
"phpspec/prophecy": "^1.22",
"phpspec/prophecy-phpunit": "^2",
"phpstan/phpstan": "^1.10.13",
"phpstan/phpstan-mockery": "^1.1",
Expand Down
8 changes: 8 additions & 0 deletions deptrac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ deptrac:
- ./src
- ./proto
- ./tests
- ./deptrac/stubs
exclude_files:
- '#.*test.*#'
layers:
Expand Down Expand Up @@ -109,10 +110,15 @@ deptrac:
collectors:
- type: className
regex: ^Nyholm\\Psr7Server\\*
- name: Stubs
collectors:
- type: directory
value: deptrac/stubs/.*

ruleset:
Context:
- FFI
- Stubs
SemConv: ~
ConfigSDK:
- SymfonyConfig
Expand All @@ -124,10 +130,12 @@ deptrac:
- Context
- Contrib
- Extension
- Stubs
API:
- Context
- PsrLog
- SPI
- Stubs
SDK:
- +API
- ConfigSDK
Expand Down
5 changes: 5 additions & 0 deletions deptrac/stubs/ComponentPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace OpenTelemetry\Config\SDK\Configuration;

class ComponentPlugin {}
5 changes: 5 additions & 0 deletions deptrac/stubs/ComponentProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace OpenTelemetry\Config\SDK\Configuration;

class ComponentProvider {}
5 changes: 5 additions & 0 deletions deptrac/stubs/ComponentProviderRegistry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace OpenTelemetry\Config\SDK\Configuration;

class ComponentProviderRegistry {}
5 changes: 5 additions & 0 deletions deptrac/stubs/Context.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace OpenTelemetry\Config\SDK\Configuration;

class Context {}
10 changes: 10 additions & 0 deletions deptrac/stubs/Override.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

//stub Override attribute for PHP <8.3

namespace {
if (!class_exists('Override')) {
#[\Attribute(\Attribute::TARGET_METHOD)]
final class Override {}
}
}
2 changes: 2 additions & 0 deletions deptrac/stubs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Stubs for deptrac, which represent classes missing from some PHP versions, or classes
that deptrac does not understand.
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM composer:2 AS composer
FROM composer:2.8 AS composer
FROM debian:bullseye
WORKDIR /usr/src/myapp

Expand Down Expand Up @@ -38,7 +38,7 @@ RUN apt-get install -y \

COPY --from=composer /usr/bin/composer /usr/local/bin/composer

RUN echo ";grpc.enable_fork_support = 1" > $(php-config --ini-dir)/40-otel-dev.ini \
RUN echo "grpc.enable_fork_support = 1" > $(php-config --ini-dir)/40-otel-dev.ini \
&& echo "grpc.poll_strategy = epoll1" >> $(php-config --ini-dir)/40-otel-dev.ini \
&& echo "zend.assertions = 1" >> $(php-config --ini-dir)/40-otel-dev.ini

Expand Down
5 changes: 5 additions & 0 deletions examples/autoload_sdk_with_custom_transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,26 @@
* @psalm-suppress MissingTemplateParam
*/
$factory = new class() implements \OpenTelemetry\SDK\Common\Export\TransportFactoryInterface {
#[\Override]
public function create(string $endpoint, string $contentType, array $headers = [], $compression = null, float $timeout = 10., int $retryDelay = 100, int $maxRetries = 3, ?string $cacert = null, ?string $cert = null, ?string $key = null): \OpenTelemetry\SDK\Common\Export\TransportInterface
{
return new class() implements \OpenTelemetry\SDK\Common\Export\TransportInterface {
#[\Override]
public function contentType(): string
{
return 'application/x-protobuf';
}
#[\Override]
public function send(string $payload, ?\OpenTelemetry\SDK\Common\Future\CancellationInterface $cancellation = null): \OpenTelemetry\SDK\Common\Future\FutureInterface
{
return new \OpenTelemetry\SDK\Common\Future\CompletedFuture(null);
}
#[\Override]
public function shutdown(?\OpenTelemetry\SDK\Common\Future\CancellationInterface $cancellation = null): bool
{
return true;
}
#[\Override]
public function forceFlush(?\OpenTelemetry\SDK\Common\Future\CancellationInterface $cancellation = null): bool
{
return true;
Expand Down
3 changes: 2 additions & 1 deletion examples/logs/features/monolog-otel-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function __construct(string $level, bool $bubble = true, ?LoggerProviderI
$this->logger = $provider->getLogger('monolog-demo', null, null, ['logging.library' => 'monolog']);
}

#[\Override]
protected function write(MonologLogRecord $record): void
{
$this->logger->emit($this->convert($record));
Expand All @@ -59,7 +60,7 @@ private function convert(MonologLogRecord $record): LogRecord
{
return (new LogRecord($record['message']))
->setSeverityText($record->level->toPsrLogLevel())
->setTimestamp((int) (microtime(true) * LogRecord::NANOS_PER_SECOND))
->setTimestamp((int) (microtime(true) * (float) LogRecord::NANOS_PER_SECOND))
->setObservedTimestamp((int) $record->datetime->format('U') * LogRecord::NANOS_PER_SECOND)
->setSeverityNumber(Severity::fromPsr3($record->level->toPsrLogLevel()))
->setAttributes($record->context + $record->extra);
Expand Down
2 changes: 2 additions & 0 deletions examples/src/ExampleConfigLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
*/
final class ExampleConfigLoader implements EnvComponentLoader
{
#[\Override]
public function load(EnvResolver $env, EnvComponentLoaderRegistry $registry, Context $context): InstrumentationConfiguration
{
return new ExampleConfig(
spanName: $env->string('OTEL_PHP_EXAMPLE_INSTRUMENTATION_SPAN_NAME') ?? 'example',
);
}

#[\Override]
public function name(): string
{
return ExampleConfig::class;
Expand Down
2 changes: 2 additions & 0 deletions examples/src/ExampleConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class ExampleConfigProvider implements ComponentProvider
* enabled: bool,
* } $properties
*/
#[\Override]
public function createPlugin(array $properties, Context $context): InstrumentationConfiguration
{
return new ExampleConfig(
Expand All @@ -35,6 +36,7 @@ public function createPlugin(array $properties, Context $context): Instrumentati
/**
* @psalm-suppress UndefinedInterfaceMethod,PossiblyNullReference
*/
#[\Override]
public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition
{
$node = $builder->arrayNode('example_instrumentation');
Expand Down
1 change: 1 addition & 0 deletions examples/src/ExampleInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

final class ExampleInstrumentation implements Instrumentation
{
#[\Override]
public function register(HookManagerInterface $hookManager, ConfigProperties $configuration, InstrumentationContext $context): void
{
$config = $configuration->get(ExampleConfig::class) ?? new ExampleConfig();
Expand Down
3 changes: 3 additions & 0 deletions examples/traces/exporters/otlp_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

$filename = sys_get_temp_dir() . '/traces.jsonl';
$file = fopen($filename, 'a');
if ($file === false) {
throw new \RuntimeException('Failed to open file for writing: ' . $filename);
}
$transport = (new StreamTransportFactory())->create($file, ContentTypes::NDJSON);
$exporter = new SpanExporter($transport);

Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ parameters:
-
message: "#.*expects Google\\\\Protobuf\\\\RepeatedField.*#"
paths:
- src/Contrib/Otlp
- src/Contrib/Otlp
Loading
Loading