-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add configuration model * Add metrics and logs configuration model * Remove accidentally added package dependency * Fix `$properties` typehint to match config Default value available -> cannot be null. * Add configuration example that utilizes env substitution * Fix/suppress config psalm issues * Fix/suppress config phpstan issues * Suppress config phan issues * Apply cs-fixer * Change config package version to development version 0.x * Add README * Add basic test * Fix psalm and cs * Fix composer requirement for PRs * gitsplit, copy spi config to root composer.json
- Loading branch information
Showing
41 changed files
with
2,298 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use OpenTelemetry\API\Logs\EventLogger; | ||
use OpenTelemetry\API\Logs\LogRecord; | ||
use OpenTelemetry\Config\SDK\Configuration; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
echo 'load config SDK example starting...' . PHP_EOL; | ||
|
||
$config = Configuration::parseFile(__DIR__ . '/load_config.yaml'); | ||
$sdk = $config | ||
->create() | ||
->setAutoShutdown(true) | ||
->build(); | ||
|
||
$tracer = $sdk->getTracerProvider()->getTracer('demo'); | ||
$meter = $sdk->getMeterProvider()->getMeter('demo'); | ||
$logger = $sdk->getLoggerProvider()->getLogger('demo'); | ||
|
||
$tracer->spanBuilder('root')->startSpan()->end(); | ||
$meter->createCounter('cnt')->add(1); | ||
|
||
$eventLogger = new EventLogger($logger, 'my-domain'); | ||
$eventLogger->logEvent('foo', new LogRecord('hello, otel')); | ||
|
||
echo 'Finished!' . PHP_EOL; |
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,44 @@ | ||
file_format: '0.1' | ||
|
||
resource: | ||
attributes: | ||
service.name: opentelemetry-demo | ||
|
||
propagators: | ||
composite: [ tracecontext, baggage ] | ||
|
||
exporters: | ||
otlp: &otlp-exporter | ||
protocol: http/protobuf | ||
endpoint: http://collector:4318 | ||
|
||
tracer_provider: | ||
sampler: | ||
parent_based: | ||
root: | ||
always_on: {} | ||
processors: | ||
- simple: | ||
exporter: | ||
console: {} | ||
- batch: | ||
exporter: | ||
otlp: *otlp-exporter | ||
meter_provider: | ||
readers: | ||
- periodic: | ||
exporter: | ||
console: {} | ||
- periodic: | ||
exporter: | ||
otlp: | ||
<<: *otlp-exporter | ||
temporality_preference: lowmemory | ||
logger_provider: | ||
processors: | ||
- simple: | ||
exporter: | ||
console: {} | ||
- batch: | ||
exporter: | ||
otlp: *otlp-exporter |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use OpenTelemetry\API\Logs\EventLogger; | ||
use OpenTelemetry\API\Logs\LogRecord; | ||
use OpenTelemetry\Config\SDK\Configuration; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
echo 'load config SDK example starting...' . PHP_EOL; | ||
|
||
$_SERVER['OTEL_SERVICE_NAME'] = 'opentelemetry-demo'; | ||
$_SERVER['OTEL_EXPORTER_OTLP_PROTOCOL'] = 'http/protobuf'; | ||
$_SERVER['OTEL_EXPORTER_OTLP_ENDPOINT'] = 'http://collector:4318'; | ||
$_SERVER['OTEL_TRACES_SAMPLER_ARG'] = '0.5'; | ||
|
||
$config = Configuration::parseFile(__DIR__ . '/load_config_env.yaml'); | ||
$sdk = $config | ||
->create() | ||
->setAutoShutdown(true) | ||
->build(); | ||
|
||
$tracer = $sdk->getTracerProvider()->getTracer('demo'); | ||
$meter = $sdk->getMeterProvider()->getMeter('demo'); | ||
$logger = $sdk->getLoggerProvider()->getLogger('demo'); | ||
|
||
$tracer->spanBuilder('root')->startSpan()->end(); | ||
$meter->createCounter('cnt')->add(1); | ||
|
||
$eventLogger = new EventLogger($logger, 'my-domain'); | ||
$eventLogger->logEvent('foo', new LogRecord('hello, otel')); | ||
|
||
echo 'Finished!' . PHP_EOL; |
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,49 @@ | ||
file_format: '0.1' | ||
|
||
disabled: ${OTEL_SDK_DISABLED} | ||
|
||
resource: | ||
attributes: | ||
service.name: ${OTEL_SERVICE_NAME} | ||
|
||
propagators: | ||
composite: [ tracecontext, baggage ] | ||
|
||
attribute_limits: | ||
attribute_value_length_limit: ${OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT} | ||
attribute_count_limit: ${OTEL_ATTRIBUTE_COUNT_LIMIT} | ||
|
||
exporters: | ||
otlp: &otlp-exporter | ||
protocol: ${OTEL_EXPORTER_OTLP_PROTOCOL} | ||
endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT} | ||
certificate: ${OTEL_EXPORTER_OTLP_CERTIFICATE} | ||
client_key: ${OTEL_EXPORTER_OTLP_CLIENT_KEY} | ||
client_certificate: ${OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE} | ||
compression: ${OTEL_EXPORTER_OTLP_COMPRESSION} | ||
timeout: ${OTEL_EXPORTER_OTLP_TIMEOUT} | ||
|
||
tracer_provider: | ||
sampler: | ||
parent_based: | ||
root: | ||
trace_id_ratio_based: | ||
ratio: ${OTEL_TRACES_SAMPLER_ARG} | ||
limits: | ||
attribute_value_length_limit: ${OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT} | ||
attribute_count_limit: ${OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT} | ||
event_count_limit: ${OTEL_SPAN_EVENT_COUNT_LIMIT} | ||
link_count_limit: ${OTEL_SPAN_LINK_COUNT_LIMIT} | ||
event_attribute_count_limit: ${OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT} | ||
link_attribute_count_limit: ${OTEL_LINK_ATTRIBUTE_COUNT_LIMIT} | ||
processors: | ||
- simple: | ||
exporter: | ||
console: {} | ||
- batch: | ||
schedule_delay: ${OTEL_BSP_SCHEDULE_DELAY} | ||
export_timeout: ${OTEL_BSP_EXPORT_TIMEOUT} | ||
max_queue_size: ${OTEL_BSP_MAX_QUEUE_SIZE} | ||
max_export_batch_size: ${OTEL_BSP_MAX_EXPORT_BATCH_SIZE} | ||
exporter: | ||
otlp: *otlp-exporter |
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
36 changes: 36 additions & 0 deletions
36
src/Config/SDK/ComponentProvider/Logs/LogRecordExporterConsole.php
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\Config\SDK\ComponentProvider\Logs; | ||
|
||
use Nevay\OTelSDK\Configuration\ComponentProvider; | ||
use Nevay\OTelSDK\Configuration\ComponentProviderRegistry; | ||
use Nevay\OTelSDK\Configuration\Context; | ||
use OpenTelemetry\SDK\Logs\Exporter\ConsoleExporter; | ||
use OpenTelemetry\SDK\Logs\LogRecordExporterInterface; | ||
use OpenTelemetry\SDK\Registry; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
|
||
/** | ||
* @implements ComponentProvider<LogRecordExporterInterface> | ||
*/ | ||
final class LogRecordExporterConsole implements ComponentProvider | ||
{ | ||
|
||
/** | ||
* @param array{} $properties | ||
*/ | ||
public function createPlugin(array $properties, Context $context): LogRecordExporterInterface | ||
{ | ||
return new ConsoleExporter(Registry::transportFactory('stream')->create( | ||
endpoint: 'php://stdout', | ||
contentType: 'application/json', | ||
)); | ||
} | ||
|
||
public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition | ||
{ | ||
return new ArrayNodeDefinition('console'); | ||
} | ||
} |
Oops, something went wrong.