Skip to content

Commit 8d27d73

Browse files
authored
adding LogRecordProcessor.enabled (#1637)
* adding LogRecordProcessor.enabled * apply review feedback
1 parent 176b10a commit 8d27d73

File tree

12 files changed

+53
-13
lines changed

12 files changed

+53
-13
lines changed

examples/src/_register.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
declare(strict_types=1);
44

55
use Nevay\SPI\ServiceLoader;
6-
use OpenTelemetry\API\Instrumentation\AutoInstrumentation\Instrumentation;
76
use OpenTelemetry\API\Configuration\Config\ComponentProvider;
7+
use OpenTelemetry\API\Instrumentation\AutoInstrumentation\Instrumentation;
88
use OpenTelemetry\Example\ExampleConfigProvider;
99
use OpenTelemetry\Example\ExampleInstrumentation;
1010
use OpenTelemetry\Example\TestResourceDetectorFactory;

phpstan.neon.dist

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ parameters:
5151
message: "#.*return with type T is not subtype.*#"
5252
paths:
5353
- src/SDK/Common/InstrumentationScope
54-
-
55-
message: "#.*assertCount\\(\\) expects Countable\\|iterable.*#"
56-
paths:
57-
- tests/Unit/Contrib/Otlp/
5854
-
5955
message: "#.*expects Google\\\\Protobuf\\\\RepeatedField.*#"
6056
paths:

src/Config/SDK/ComponentProvider/Propagator/TextMapPropagatorCloudTrace.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace OpenTelemetry\Config\SDK\ComponentProvider\Propagator;
66

77
use Nevay\SPI\ServiceProviderDependency\PackageDependency;
8-
use OpenTelemetry\Config\SDK\Configuration\ComponentProvider;
9-
use OpenTelemetry\Config\SDK\Configuration\ComponentProviderRegistry;
10-
use OpenTelemetry\Config\SDK\Configuration\Context;
8+
use OpenTelemetry\API\Configuration\Config\ComponentProvider;
9+
use OpenTelemetry\API\Configuration\Config\ComponentProviderRegistry;
10+
use OpenTelemetry\API\Configuration\Context;
1111
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;
1212
use OpenTelemetry\Extension\Propagator\CloudTrace\CloudTracePropagator;
1313
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;

src/Config/SDK/_register.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(strict_types=1);
44

55
use Nevay\SPI\ServiceLoader;
6+
use OpenTelemetry\API\Configuration\Config\ComponentProvider;
67
use OpenTelemetry\Config\SDK\ComponentProvider\Instrumentation\General\HttpConfigProvider;
78
use OpenTelemetry\Config\SDK\ComponentProvider\Instrumentation\General\PeerConfigProvider;
89
use OpenTelemetry\Config\SDK\ComponentProvider\Logs\LogRecordExporterConsole;
@@ -35,7 +36,6 @@
3536
use OpenTelemetry\Config\SDK\ComponentProvider\Trace\SpanExporterZipkin;
3637
use OpenTelemetry\Config\SDK\ComponentProvider\Trace\SpanProcessorBatch;
3738
use OpenTelemetry\Config\SDK\ComponentProvider\Trace\SpanProcessorSimple;
38-
use OpenTelemetry\API\Configuration\Config\ComponentProvider;
3939

4040
ServiceLoader::register(ComponentProvider::class, TextMapPropagatorB3::class);
4141
ServiceLoader::register(ComponentProvider::class, TextMapPropagatorB3Multi::class);

src/SDK/Logs/LogRecordProcessorInterface.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66

77
use OpenTelemetry\Context\ContextInterface;
88
use OpenTelemetry\SDK\Common\Future\CancellationInterface;
9+
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface;
910

10-
/**
11-
* @todo implement (optional) isEnabled: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.45.0/specification/logs/sdk.md#enabled-1
12-
*/
1311
interface LogRecordProcessorInterface
1412
{
1513
public function onEmit(ReadWriteLogRecord $record, ?ContextInterface $context = null): void;
1614
public function shutdown(?CancellationInterface $cancellation = null): bool;
1715
public function forceFlush(?CancellationInterface $cancellation = null): bool;
16+
17+
/**
18+
* @experimental
19+
*/
20+
public function isEnabled(ContextInterface $context, InstrumentationScopeInterface $scope, ?int $severityNumber, ?string $eventName): bool;
1821
}

src/SDK/Logs/Logger.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use OpenTelemetry\API\Behavior\LogsMessagesTrait;
88
use OpenTelemetry\API\Logs\LoggerInterface;
99
use OpenTelemetry\API\Logs\LogRecord;
10+
use OpenTelemetry\Context\Context;
1011
use OpenTelemetry\Context\ContextInterface;
1112
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface;
1213
use OpenTelemetry\SDK\Common\InstrumentationScope\Configurator;
@@ -55,7 +56,10 @@ public function emit(LogRecord $logRecord): void
5556
*/
5657
public function isEnabled(?ContextInterface $context = null, ?int $severityNumber = null, ?string $eventName = null): bool
5758
{
58-
return $this->config->isEnabled();
59+
$context ??= Context::getCurrent();
60+
61+
return $this->loggerSharedState->getProcessor()->isEnabled($context, $this->scope, $severityNumber, $eventName)
62+
&& $this->config->isEnabled();
5963
}
6064

6165
/**

src/SDK/Logs/Processor/BatchLogRecordProcessor.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OpenTelemetry\Context\Context;
1313
use OpenTelemetry\Context\ContextInterface;
1414
use OpenTelemetry\SDK\Common\Future\CancellationInterface;
15+
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface;
1516
use OpenTelemetry\SDK\Logs\LogRecordExporterInterface;
1617
use OpenTelemetry\SDK\Logs\LogRecordProcessorInterface;
1718
use OpenTelemetry\SDK\Logs\ReadWriteLogRecord;
@@ -178,6 +179,11 @@ public function shutdown(?CancellationInterface $cancellation = null): bool
178179
return $this->flush(__FUNCTION__, $cancellation);
179180
}
180181

182+
public function isEnabled(ContextInterface $context, InstrumentationScopeInterface $scope, ?int $severityNumber, ?string $eventName): bool
183+
{
184+
return true;
185+
}
186+
181187
private function flush(?string $flushMethod = null, ?CancellationInterface $cancellation = null): bool
182188
{
183189
if ($flushMethod !== null) {

src/SDK/Logs/Processor/MultiLogRecordProcessor.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use OpenTelemetry\Context\ContextInterface;
88
use OpenTelemetry\SDK\Common\Future\CancellationInterface;
9+
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface;
910
use OpenTelemetry\SDK\Logs\LogRecordProcessorInterface;
1011
use OpenTelemetry\SDK\Logs\ReadWriteLogRecord;
1112

@@ -59,4 +60,15 @@ public function forceFlush(?CancellationInterface $cancellation = null): bool
5960

6061
return $result;
6162
}
63+
64+
public function isEnabled(ContextInterface $context, InstrumentationScopeInterface $scope, ?int $severityNumber, ?string $eventName): bool
65+
{
66+
foreach ($this->processors as $processor) {
67+
if ($processor->isEnabled($context, $scope, $severityNumber, $eventName)) {
68+
return true;
69+
}
70+
}
71+
72+
return false;
73+
}
6274
}

src/SDK/Logs/Processor/NoopLogRecordProcessor.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use OpenTelemetry\Context\ContextInterface;
88
use OpenTelemetry\SDK\Common\Future\CancellationInterface;
9+
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface;
910
use OpenTelemetry\SDK\Logs\LogRecordProcessorInterface;
1011
use OpenTelemetry\SDK\Logs\ReadWriteLogRecord;
1112

@@ -34,4 +35,9 @@ public function forceFlush(?CancellationInterface $cancellation = null): bool
3435
{
3536
return true;
3637
}
38+
39+
public function isEnabled(ContextInterface $context, InstrumentationScopeInterface $scope, ?int $severityNumber, ?string $eventName): bool
40+
{
41+
return true;
42+
}
3743
}

src/SDK/Logs/Processor/SimpleLogRecordProcessor.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use OpenTelemetry\Context\ContextInterface;
88
use OpenTelemetry\SDK\Common\Future\CancellationInterface;
9+
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface;
910
use OpenTelemetry\SDK\Logs\LogRecordExporterInterface;
1011
use OpenTelemetry\SDK\Logs\LogRecordProcessorInterface;
1112
use OpenTelemetry\SDK\Logs\ReadWriteLogRecord;
@@ -33,4 +34,9 @@ public function forceFlush(?CancellationInterface $cancellation = null): bool
3334
{
3435
return $this->exporter->forceFlush($cancellation);
3536
}
37+
38+
public function isEnabled(ContextInterface $context, InstrumentationScopeInterface $scope, ?int $severityNumber, ?string $eventName): bool
39+
{
40+
return true;
41+
}
3642
}

0 commit comments

Comments
 (0)