-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revert pass-by-reference to LogRecordProcessor::onEmit
add a test to demonstrate that mutations are still seen by later processors without by-reference
- Loading branch information
Showing
7 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
tests/Integration/SDK/Logs/test_mutate_log_record_in_onemit.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
--TEST-- | ||
Test mutating a LogRecord during SpanProcessor::onEmit | ||
--FILE-- | ||
<?php | ||
require_once 'vendor/autoload.php'; | ||
|
||
use OpenTelemetry\SDK\Trace\TracerProviderBuilder; | ||
use OpenTelemetry\SDK\Trace\ReadWriteSpanInterface; | ||
use OpenTelemetry\SDK\Trace\ReadableSpanInterface; | ||
use OpenTelemetry\SDK\Common\Future\CancellationInterface; | ||
use OpenTelemetry\SDK\Trace\SpanProcessorInterface; | ||
use OpenTelemetry\Context\ContextInterface; | ||
|
||
$exporter = (new \OpenTelemetry\SDK\Logs\Exporter\ConsoleExporterFactory())->create(); | ||
|
||
$one = new class implements \OpenTelemetry\SDK\Logs\LogRecordProcessorInterface { | ||
public function onEmit(\OpenTelemetry\SDK\Logs\ReadWriteLogRecord $record, ?ContextInterface $context = null): void | ||
{ | ||
$record->setBody('updated'); | ||
$record->setAttribute('new-key', 'new-value'); | ||
} | ||
|
||
public function shutdown(?CancellationInterface $cancellation = null): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function forceFlush(?CancellationInterface $cancellation = null): bool | ||
{ | ||
return true; | ||
} | ||
}; | ||
$two = new \OpenTelemetry\SDK\Logs\Processor\SimpleLogRecordProcessor($exporter); | ||
|
||
$loggerProvider = (new \OpenTelemetry\SDK\Logs\LoggerProviderBuilder()) | ||
->addLogRecordProcessor(new \OpenTelemetry\SDK\Logs\Processor\MultiLogRecordProcessor([$one, $two])) | ||
->build(); | ||
|
||
$logger = $loggerProvider->getLogger('test'); | ||
$logger->emit(new \OpenTelemetry\API\Logs\LogRecord('body')); | ||
?> | ||
--EXPECTF-- | ||
{ | ||
"resource": { | ||
"attributes": { | ||
"telemetry.sdk.name": "opentelemetry", | ||
"telemetry.sdk.language": "php", | ||
"telemetry.sdk.version": "%s", | ||
"telemetry.distro.name": "%s", | ||
"telemetry.distro.version": "%s", | ||
"service.name": "%s" | ||
}, | ||
"dropped_attributes_count": 0 | ||
}, | ||
"scopes": [ | ||
{ | ||
"name": "test", | ||
"version": null, | ||
"attributes": [], | ||
"dropped_attributes_count": 0, | ||
"schema_url": null, | ||
"logs": [ | ||
{ | ||
"timestamp": null, | ||
"observed_timestamp": %d, | ||
"severity_number": 0, | ||
"severity_text": null, | ||
"body": "updated", | ||
"trace_id": "%s", | ||
"span_id": "%s", | ||
"trace_flags": 0, | ||
"attributes": { | ||
"new-key": "new-value" | ||
}, | ||
"dropped_attributes_count": 0 | ||
} | ||
] | ||
} | ||
] | ||
} |