Skip to content

Commit

Permalink
Merge branch 'main' into 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
brettmc committed Jan 10, 2025
2 parents 81288cd + 4b575e6 commit 78f445b
Show file tree
Hide file tree
Showing 141 changed files with 189 additions and 119 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'include' => true,
'lowercase_cast' => true,
'new_with_parentheses' => true,
'no_blank_lines_after_class_opening' => true,
'no_extra_blank_lines' => true,
'no_leading_import_slash' => true,
'no_trailing_whitespace' => true,
Expand Down
1 change: 0 additions & 1 deletion examples/src/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

final class Example
{

public function test(): int
{
return 42;
Expand Down
1 change: 0 additions & 1 deletion examples/src/ExampleConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

final class ExampleConfig implements InstrumentationConfiguration
{

public function __construct(
public readonly string $spanName,
public readonly bool $enabled = true,
Expand Down
1 change: 0 additions & 1 deletion examples/src/ExampleConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
final class ExampleConfigProvider implements ComponentProvider
{

/**
* @psalm-suppress MoreSpecificImplementedParamType
* @param array{
Expand Down
1 change: 0 additions & 1 deletion examples/src/ExampleInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

final class ExampleInstrumentation implements Instrumentation
{

public function register(HookManagerInterface $hookManager, ConfigProperties $configuration, InstrumentationContext $context): void
{
$config = $configuration->get(ExampleConfig::class) ?? throw new Exception('example instrumentation must be configured');
Expand Down
23 changes: 23 additions & 0 deletions examples/traces/exporters/otlp_file_autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Example;

use OpenTelemetry\API\Instrumentation\CachedInstrumentation;

putenv('OTEL_PHP_AUTOLOAD_ENABLED=true');
putenv('OTEL_TRACES_EXPORTER=otlp/stdout');
putenv('OTEL_LOGS_EXPORTER=otlp/stdout');
putenv('OTEL_METRICS_EXPORTER=otlp/stdout');

require __DIR__ . '/../../../vendor/autoload.php';

$instrumentation = new CachedInstrumentation('demo');

$instrumentation->tracer()->spanBuilder('root')->startSpan()->end();
$instrumentation->meter()->createCounter('cnt')->add(1);
$instrumentation->eventLogger()->emit('foo', 'hello, otel');

echo PHP_EOL . 'OTLP/stdout autoload example complete!';
echo PHP_EOL;
42 changes: 42 additions & 0 deletions examples/traces/exporters/otlp_file_from_factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Example;

require __DIR__ . '/../../../vendor/autoload.php';

use OpenTelemetry\SDK\Trace\TracerProviderFactory;

putenv('OTEL_TRACES_EXPORTER=otlp/stdout');
$factory = new TracerProviderFactory();
$tracerProvider = $factory->create();

$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');

$root = $span = $tracer->spanBuilder('root')->startSpan();
$scope = $span->activate();

for ($i = 0; $i < 3; $i++) {
// start a span, register some events
$span = $tracer->spanBuilder('loop-' . $i)->startSpan();

$span->setAttribute('remote_ip', '1.2.3.4')
->setAttribute('country', 'USA');

$span->addEvent('found_login' . $i, [
'id' => $i,
'username' => 'otuser' . $i,
]);
$span->addEvent('generated_session', [
'id' => md5((string) microtime(true)),
]);

$span->end();
}
$root->end();
$scope->detach();
echo PHP_EOL . 'OTLP/stdout example complete!';

echo PHP_EOL;
$tracerProvider->shutdown();
6 changes: 5 additions & 1 deletion src/API/Globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public static function loggerProvider(): LoggerProviderInterface
return Context::getCurrent()->get(ContextKeys::loggerProvider()) ?? self::globals()->loggerProvider;
}

/**
* @deprecated
* @phan-suppress PhanDeprecatedFunction
*/
public static function eventLoggerProvider(): EventLoggerProviderInterface
{
return Context::getCurrent()->get(ContextKeys::eventLoggerProvider()) ?? self::globals()->eventLoggerProvider;
Expand All @@ -76,7 +80,7 @@ public static function registerInitializer(Closure $initializer): void
}

/**
* @phan-suppress PhanTypeMismatchReturnNullable
* @phan-suppress PhanTypeMismatchReturnNullable,PhanDeprecatedFunction
*/
private static function globals(): self
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

final class ConfigurationRegistry implements ConfigProperties
{

private array $configurations = [];

public function add(InstrumentationConfiguration $configuration): self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

interface InstrumentationConfiguration
{

}
5 changes: 5 additions & 0 deletions src/API/Instrumentation/CachedInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public function logger(): LoggerInterface

return $this->loggers[$loggerProvider] ??= $loggerProvider->getLogger($this->name, $this->version, $this->schemaUrl, $this->attributes);
}

/**
* @deprecated
* @phan-suppress PhanDeprecatedFunction
*/
public function eventLogger(): EventLoggerInterface
{
$eventLoggerProvider = Globals::eventLoggerProvider();
Expand Down
7 changes: 7 additions & 0 deletions src/API/Instrumentation/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public static function create(): Configurator

/**
* Creates a configurator that uses noop instances for not configured values.
* @phan-suppress PhanDeprecatedFunction
*/
public static function createNoop(): Configurator
{
Expand All @@ -63,6 +64,9 @@ public function activate(): ScopeInterface
return $this->storeInContext()->activate();
}

/**
* @phan-suppress PhanDeprecatedFunction
*/
public function storeInContext(?ContextInterface $context = null): ContextInterface
{
$context ??= Context::getCurrent();
Expand Down Expand Up @@ -118,6 +122,9 @@ public function withLoggerProvider(?LoggerProviderInterface $loggerProvider): Co
return $self;
}

/**
* @deprecated
*/
public function withEventLoggerProvider(?EventLoggerProviderInterface $eventLoggerProvider): Configurator
{
$self = clone $this;
Expand Down
1 change: 1 addition & 0 deletions src/API/Instrumentation/ContextKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public static function loggerProvider(): ContextKeyInterface
}

/**
* @deprecated
* @return ContextKeyInterface<EventLoggerProviderInterface>
*/
public static function eventLoggerProvider(): ContextKeyInterface
Expand Down
1 change: 1 addition & 0 deletions src/API/Logs/EventLoggerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OpenTelemetry\Context\ContextInterface;

/**
* @deprecated
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/event-api.md#events-api-interface
*/
interface EventLoggerInterface
Expand Down
1 change: 1 addition & 0 deletions src/API/Logs/EventLoggerProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace OpenTelemetry\API\Logs;

/**
* @deprecated
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.32.0/specification/logs/event-api.md#get-an-eventlogger
*/
interface EventLoggerProviderInterface
Expand Down
3 changes: 3 additions & 0 deletions src/API/Logs/NoopEventLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use OpenTelemetry\Context\ContextInterface;

/**
* @phan-suppress PhanDeprecatedInterface
*/
class NoopEventLogger implements EventLoggerInterface
{
public static function instance(): self
Expand Down
3 changes: 3 additions & 0 deletions src/API/Logs/NoopEventLoggerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace OpenTelemetry\API\Logs;

/**
* @phan-suppress PhanDeprecatedInterface
*/
class NoopEventLoggerProvider implements EventLoggerProviderInterface
{
public static function getInstance(): self
Expand Down
1 change: 0 additions & 1 deletion src/API/Metrics/CounterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

interface CounterInterface extends SynchronousInstrument
{

/**
* @param float|int $amount non-negative amount to increment by
* @param iterable<non-empty-string, string|bool|float|int|array|null> $attributes
Expand Down
1 change: 0 additions & 1 deletion src/API/Metrics/GaugeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
interface GaugeInterface extends SynchronousInstrument
{

/**
* @param float|int $amount current absolute value
* @param iterable<non-empty-string, string|bool|float|int|array|null> $attributes
Expand Down
1 change: 0 additions & 1 deletion src/API/Metrics/HistogramInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

interface HistogramInterface extends SynchronousInstrument
{

/**
* @param float|int $amount non-negative amount to record
* @param iterable<non-empty-string, string|bool|float|int|array|null> $attributes
Expand Down
1 change: 0 additions & 1 deletion src/API/Metrics/MeterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

interface MeterInterface
{

/**
* Reports measurements for multiple asynchronous instrument from a single callback.
*
Expand Down
1 change: 0 additions & 1 deletion src/API/Metrics/MeterProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

interface MeterProviderInterface
{

/**
* Returns a `Meter` for the given instrumentation scope.
*
Expand Down
1 change: 0 additions & 1 deletion src/API/Metrics/ObservableCallbackInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
*/
interface ObservableCallbackInterface
{

/**
* Detaches the associated callback from the instrument.
*/
Expand Down
1 change: 0 additions & 1 deletion src/API/Metrics/ObservableCounterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

interface ObservableCounterInterface extends AsynchronousInstrument
{

/**
* @param callable(ObserverInterface): void $callback function responsible for
* reporting the measurements (as absolute values)
Expand Down
1 change: 0 additions & 1 deletion src/API/Metrics/ObservableGaugeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

interface ObservableGaugeInterface extends AsynchronousInstrument
{

/**
* @param callable(ObserverInterface): void $callback function responsible for
* reporting the measurements
Expand Down
1 change: 0 additions & 1 deletion src/API/Metrics/ObservableUpDownCounterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

interface ObservableUpDownCounterInterface extends AsynchronousInstrument
{

/**
* @param callable(ObserverInterface): void $callback function responsible for
* reporting the measurements (as absolute values)
Expand Down
1 change: 0 additions & 1 deletion src/API/Metrics/ObserverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

interface ObserverInterface
{

/**
* Records the given absolute datapoint.
*
Expand Down
1 change: 0 additions & 1 deletion src/API/Metrics/UpDownCounterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

interface UpDownCounterInterface extends SynchronousInstrument
{

/**
* @param float|int $amount amount to increment / decrement by
* @param iterable<non-empty-string, string|bool|float|int|array|null> $attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
class HttpConfigProvider implements ComponentProvider
{

public function createPlugin(array $properties, Context $context): GeneralInstrumentationConfiguration
{
return new HttpConfig($properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
final class LogRecordExporterConsole implements ComponentProvider
{

/**
* @param array{} $properties
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#[PackageDependency('open-telemetry/exporter-otlp', '^1.0.5')]
final class LogRecordExporterOtlp implements ComponentProvider
{

/**
* @param array{
* protocol: 'http/protobuf'|'http/json'|'grpc',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
final class LogRecordProcessorBatch implements ComponentProvider
{

/**
* @param array{
* schedule_delay: int<0, max>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
final class LogRecordProcessorSimple implements ComponentProvider
{

/**
* @param array{
* exporter: ComponentPlugin<LogRecordExporterInterface>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
final class AggregationResolverDefault implements ComponentProvider
{

/**
* @param array{} $properties
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
final class MetricExporterConsole implements ComponentProvider
{

/**
* @param array{} $properties
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#[PackageDependency('open-telemetry/exporter-otlp', '^1.0.5')]
final class MetricExporterOtlp implements ComponentProvider
{

/**
* @param array{
* protocol: 'http/protobuf'|'http/json'|'grpc',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
final class MetricReaderPeriodic implements ComponentProvider
{

/**
* @param array{
* interval: int<0, max>,
Expand Down
1 change: 0 additions & 1 deletion src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
*/
final class OpenTelemetrySdk implements ComponentProvider
{

/**
* @param array{
* file_format: '0.3',
Expand Down
Loading

0 comments on commit 78f445b

Please sign in to comment.