Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove event logger #1480

Draft
wants to merge 4 commits into
base: 2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 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
10 changes: 4 additions & 6 deletions examples/autoload_sdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
namespace OpenTelemetry\Example;

putenv('OTEL_PHP_AUTOLOAD_ENABLED=true');
putenv('OTEL_TRACES_EXPORTER=otlp');
putenv('OTEL_METRICS_EXPORTER=otlp');
putenv('OTEL_LOGS_EXPORTER=otlp');
putenv('OTEL_EXPORTER_OTLP_PROTOCOL=grpc');
putenv('OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4317');
putenv('OTEL_TRACES_EXPORTER=none');
putenv('OTEL_METRICS_EXPORTER=none');
putenv('OTEL_LOGS_EXPORTER=console');
putenv('OTEL_PROPAGATORS=b3,baggage,tracecontext');

echo 'autoloading SDK example starting...' . PHP_EOL;
Expand All @@ -21,6 +19,6 @@

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

echo 'Finished!' . PHP_EOL;
4 changes: 2 additions & 2 deletions examples/load_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

$tracer = $sdk->getTracerProvider()->getTracer('demo');
$meter = $sdk->getMeterProvider()->getMeter('demo');
$eventLogger = $sdk->getEventLoggerProvider()->getEventLogger('demo');
$logger = $sdk->getLoggerProvider()->getLogger('demo');

$span = $tracer->spanBuilder('root')->startSpan();
$scope = $span->activate();
$meter->createCounter('cnt')->add(1);

$eventLogger->emit('foo', 'hello, otel');
$logger->emitEvent(name: 'foo', body: 'hello, otel');
$scope->detach();
$span->end();

Expand Down
4 changes: 2 additions & 2 deletions examples/load_config_env.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

$tracer = $sdk->getTracerProvider()->getTracer('demo');
$meter = $sdk->getMeterProvider()->getMeter('demo');
$eventLogger = $sdk->getEventLoggerProvider()->getEventLogger('demo');
$logger = $sdk->getLoggerProvider()->getLogger('demo');

$tracer->spanBuilder('root')->startSpan()->end();
$meter->createCounter('cnt')->add(1);
$eventLogger->emit('foo', 'hello, otel');
$logger->emitEvent(name: 'foo', body: 'hello, otel');

echo 'Finished!' . PHP_EOL;
16 changes: 7 additions & 9 deletions examples/logs/exporters/otlp_grpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use OpenTelemetry\Contrib\Otlp\LogsExporter;
use OpenTelemetry\Contrib\Otlp\OtlpUtil;
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeFactory;
use OpenTelemetry\SDK\Logs\EventLoggerProvider;
use OpenTelemetry\SDK\Logs\LoggerProvider;
use OpenTelemetry\SDK\Logs\LogRecordLimitsBuilder;
use OpenTelemetry\SDK\Logs\Processor\BatchLogRecordProcessor;
Expand All @@ -29,18 +28,17 @@
(new LogRecordLimitsBuilder())->build()->getAttributeFactory()
)
);
$eventLoggerProvider = new EventLoggerProvider($loggerProvider);
$eventLogger = $eventLoggerProvider->getEventLogger('demo', '1.0', 'http://schema.url', ['foo' => 'bar']);
$logger = $loggerProvider->getLogger('demo', '1.0', 'http://schema.url', ['foo' => 'bar']);

$eventLogger->emit(
$logger->emitEvent(
name: 'foo',
body: ['foo' => 'bar', 'baz' => 'bat', 'msg' => 'hello world'],
severityNumber: Severity::INFO
severityNumber: Severity::INFO,
body: ['foo' => 'bar', 'baz' => 'bat', 'msg' => 'hello world']
);

$eventLogger->emit(
'bar',
'otel is great'
$logger->emitEvent(
name: 'bar',
body: 'otel is great'
);

$loggerProvider->shutdown();
8 changes: 3 additions & 5 deletions examples/logs/exporters/otlp_http.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use OpenTelemetry\Contrib\Otlp\LogsExporter;
use OpenTelemetry\Contrib\Otlp\OtlpHttpTransportFactory;
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeFactory;
use OpenTelemetry\SDK\Logs\EventLoggerProvider;
use OpenTelemetry\SDK\Logs\LoggerProvider;
use OpenTelemetry\SDK\Logs\LogRecordLimitsBuilder;
use OpenTelemetry\SDK\Logs\Processor\SimpleLogRecordProcessor;
Expand All @@ -27,12 +26,11 @@
(new LogRecordLimitsBuilder())->build()->getAttributeFactory()
)
);
$eventLoggerProvider = new EventLoggerProvider($loggerProvider);
$eventLogger = $eventLoggerProvider->getEventLogger('demo', '1.0', 'https://opentelemetry.io/schemas/1.7.1', ['foo' => 'bar']);
$logger = $loggerProvider->getLogger('demo', '1.0', 'https://opentelemetry.io/schemas/1.7.1', ['foo' => 'bar']);

$eventLogger->emit(
$logger->emitEvent(
name: 'foo',
body: ['foo' => 'bar', 'baz' => 'bat', 'msg' => 'hello world'],
timestamp: (new \DateTime())->getTimestamp() * LogRecord::NANOS_PER_SECOND,
severityNumber: Severity::INFO,
body: ['foo' => 'bar', 'baz' => 'bat', 'msg' => 'hello world'],
);
15 changes: 6 additions & 9 deletions examples/logs/features/batch_exporting.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use OpenTelemetry\API\Logs\Severity;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeFactory;
use OpenTelemetry\SDK\Logs\EventLogger;
use OpenTelemetry\SDK\Logs\EventLoggerProvider;
use OpenTelemetry\SDK\Logs\Exporter\ConsoleExporterFactory;
use OpenTelemetry\SDK\Logs\LoggerProvider;
use OpenTelemetry\SDK\Logs\Processor\BatchLogRecordProcessor;
Expand All @@ -23,16 +21,15 @@
),
new InstrumentationScopeFactory(Attributes::factory())
);
$eventLoggerProvider = new EventLoggerProvider($loggerProvider);
//get a logger, and emit a log record from an EventLogger.
$eventLoggerOne = $eventLoggerProvider->getEventLogger('demo', '1.0');
$eventLoggerTwo = $eventLoggerProvider->getEventLogger('demo', '2.0');
//get a logger, and emit an event.
$loggerOne = $loggerProvider->getLogger('demo', '1.0');
$loggerTwo = $loggerProvider->getLogger('demo', '2.0');

$payload = ['foo' => 'bar', 'baz' => 'bat', 'msg' => 'hello world'];

$eventLoggerOne->emit(name: 'foo', body: $payload, severityNumber: Severity::INFO);
$eventLoggerOne->emit('bar', 'hello world');
$eventLoggerTwo->emit(name: 'foo', body: $payload, severityNumber: Severity::INFO);
$loggerOne->emitEvent(name: 'foo', severityNumber: Severity::INFO, body: $payload);
$loggerOne->emitEvent('bar', body: 'hello world');
$loggerTwo->emitEvent(name: 'foo', severityNumber: Severity::INFO, body: $payload);

//shut down logger provider
$loggerProvider->shutdown();
8 changes: 3 additions & 5 deletions examples/logs/getting_started.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use OpenTelemetry\API\Logs\Severity;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeFactory;
use OpenTelemetry\SDK\Logs\EventLoggerProvider;
use OpenTelemetry\SDK\Logs\Exporter\ConsoleExporterFactory;
use OpenTelemetry\SDK\Logs\LoggerProvider;
use OpenTelemetry\SDK\Logs\Processor\SimpleLogRecordProcessor;
Expand All @@ -26,7 +25,6 @@
),
new InstrumentationScopeFactory(Attributes::factory())
);
$eventLoggerProvider = new EventLoggerProvider($loggerProvider);
$tracerProvider = new TracerProvider();
$tracer = $tracerProvider->getTracer('demo-tracer');

Expand All @@ -36,12 +34,12 @@
echo 'Trace id: ' . $span->getContext()->getTraceId() . PHP_EOL;
echo 'Span id: ' . $span->getContext()->getSpanId() . PHP_EOL;

//get an event logger, and emit an event. The active context (trace id + span id) will be
//get a logger, and emit an event. The active context (trace id + span id) will be
//attached to the log record
$eventLogger = $eventLoggerProvider->getEventLogger('demo', '1.0', 'http://schema.url', ['foo' => 'bar']);
$logger = $loggerProvider->getLogger('demo', '1.0', 'http://schema.url', ['foo' => 'bar']);
$payload = ['foo' => 'bar', 'baz' => 'bat', 'msg' => 'hello world'];

$eventLogger->emit(name: 'foo', body: $payload, severityNumber: Severity::INFO);
$logger->emitEvent(name: 'foo', severityNumber: Severity::INFO, body: $payload);

//end span
$span->end();
Expand Down
2 changes: 1 addition & 1 deletion examples/traces/exporters/otlp_file_autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

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

echo PHP_EOL . 'OTLP/stdout autoload example complete!';
echo PHP_EOL;
16 changes: 2 additions & 14 deletions src/API/Globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use OpenTelemetry\API\Behavior\LogsMessagesTrait;
use OpenTelemetry\API\Instrumentation\Configurator;
use OpenTelemetry\API\Instrumentation\ContextKeys;
use OpenTelemetry\API\Logs\EventLoggerProviderInterface;
use OpenTelemetry\API\Logs\LoggerProviderInterface;
use OpenTelemetry\API\Metrics\MeterProviderInterface;
use OpenTelemetry\API\Trace\TracerProviderInterface;
Expand All @@ -33,7 +32,6 @@ public function __construct(
private readonly TracerProviderInterface $tracerProvider,
private readonly MeterProviderInterface $meterProvider,
private readonly LoggerProviderInterface $loggerProvider,
private readonly EventLoggerProviderInterface $eventLoggerProvider,
private readonly TextMapPropagatorInterface $propagator,
) {
}
Expand All @@ -58,15 +56,6 @@ 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;
}

/**
* @param Closure(Configurator): Configurator $initializer
*
Expand Down Expand Up @@ -108,11 +97,10 @@ private static function globals(): self
$meterProvider = $context->get(ContextKeys::meterProvider());
$propagator = $context->get(ContextKeys::propagator());
$loggerProvider = $context->get(ContextKeys::loggerProvider());
$eventLoggerProvider = $context->get(ContextKeys::eventLoggerProvider());

assert(isset($tracerProvider, $meterProvider, $loggerProvider, $eventLoggerProvider, $propagator));
assert(isset($tracerProvider, $meterProvider, $loggerProvider, $propagator));

return self::$globals = new self($tracerProvider, $meterProvider, $loggerProvider, $eventLoggerProvider, $propagator);
return self::$globals = new self($tracerProvider, $meterProvider, $loggerProvider, $propagator);
}

/**
Expand Down
16 changes: 0 additions & 16 deletions src/API/Instrumentation/CachedInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
namespace OpenTelemetry\API\Instrumentation;

use OpenTelemetry\API\Globals;
use OpenTelemetry\API\Logs\EventLoggerInterface;
use OpenTelemetry\API\Logs\EventLoggerProviderInterface;
use OpenTelemetry\API\Logs\LoggerInterface;
use OpenTelemetry\API\Logs\LoggerProviderInterface;
use OpenTelemetry\API\Metrics\MeterInterface;
Expand All @@ -31,8 +29,6 @@ final class CachedInstrumentation
private WeakMap $meters;
/** @var WeakMap<LoggerProviderInterface, LoggerInterface> */
private WeakMap $loggers;
/** @var WeakMap<EventLoggerProviderInterface, EventLoggerInterface> */
private WeakMap $eventLoggers;

/**
* @psalm-suppress PropertyTypeCoercion
Expand All @@ -46,7 +42,6 @@ public function __construct(
$this->tracers = new \WeakMap();
$this->meters = new \WeakMap();
$this->loggers = new \WeakMap();
$this->eventLoggers = new \WeakMap();
}

public function tracer(): TracerInterface
Expand All @@ -68,15 +63,4 @@ 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();

return $this->eventLoggers[$eventLoggerProvider] ??= $eventLoggerProvider->getEventLogger($this->name, $this->version, $this->schemaUrl, $this->attributes);
}
}
18 changes: 0 additions & 18 deletions src/API/Instrumentation/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace OpenTelemetry\API\Instrumentation;

use OpenTelemetry\API\Logs\EventLoggerProviderInterface;
use OpenTelemetry\API\Logs\LoggerProviderInterface;
use OpenTelemetry\API\Logs\NoopEventLoggerProvider;
use OpenTelemetry\API\Logs\NoopLoggerProvider;
use OpenTelemetry\API\Metrics\MeterProviderInterface;
use OpenTelemetry\API\Metrics\Noop\NoopMeterProvider;
Expand All @@ -30,7 +28,6 @@ final class Configurator implements ImplicitContextKeyedInterface
private ?MeterProviderInterface $meterProvider = null;
private ?TextMapPropagatorInterface $propagator = null;
private ?LoggerProviderInterface $loggerProvider = null;
private ?EventLoggerProviderInterface $eventLoggerProvider = null;

private function __construct()
{
Expand All @@ -55,7 +52,6 @@ public static function createNoop(): Configurator
->withMeterProvider(new NoopMeterProvider())
->withPropagator(new NoopTextMapPropagator())
->withLoggerProvider(NoopLoggerProvider::getInstance())
->withEventLoggerProvider(new NoopEventLoggerProvider())
;
}

Expand Down Expand Up @@ -83,9 +79,6 @@ public function storeInContext(?ContextInterface $context = null): ContextInterf
if ($this->loggerProvider !== null) {
$context = $context->with(ContextKeys::loggerProvider(), $this->loggerProvider);
}
if ($this->eventLoggerProvider !== null) {
$context = $context->with(ContextKeys::eventLoggerProvider(), $this->eventLoggerProvider);
}

return $context;
}
Expand Down Expand Up @@ -121,15 +114,4 @@ public function withLoggerProvider(?LoggerProviderInterface $loggerProvider): Co

return $self;
}

/**
* @deprecated
*/
public function withEventLoggerProvider(?EventLoggerProviderInterface $eventLoggerProvider): Configurator
{
$self = clone $this;
$self->eventLoggerProvider = $eventLoggerProvider;

return $self;
}
}
12 changes: 0 additions & 12 deletions src/API/Instrumentation/ContextKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace OpenTelemetry\API\Instrumentation;

use OpenTelemetry\API\Logs\EventLoggerProviderInterface;
use OpenTelemetry\API\Logs\LoggerProviderInterface;
use OpenTelemetry\API\Metrics\MeterProviderInterface;
use OpenTelemetry\API\Trace\TracerProviderInterface;
Expand Down Expand Up @@ -56,15 +55,4 @@ public static function loggerProvider(): ContextKeyInterface

return $instance ??= Context::createKey(LoggerProviderInterface::class);
}

/**
* @deprecated
* @return ContextKeyInterface<EventLoggerProviderInterface>
*/
public static function eventLoggerProvider(): ContextKeyInterface
{
static $instance;

return $instance ??= Context::createKey(EventLoggerProviderInterface::class);
}
}
23 changes: 0 additions & 23 deletions src/API/Logs/EventLoggerInterface.php

This file was deleted.

19 changes: 0 additions & 19 deletions src/API/Logs/EventLoggerProviderInterface.php

This file was deleted.

Loading
Loading