Skip to content

Commit

Permalink
fixing broken logging example
Browse files Browse the repository at this point in the history
  • Loading branch information
brettmc committed Nov 9, 2022
1 parent 56d0892 commit e3c2ee0
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions examples/traces/troubleshooting/setting_up_logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@

use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use OpenTelemetry\Contrib\Otlp\SpanExporter;
use OpenTelemetry\SDK\Common\Log\LoggerHolder;
use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\SDK\Trace\TracerProvider;
use OpenTelemetry\SDK\Trace\TracerProviderFactory;
use Psr\Log\LogLevel;

echo 'Starting SettingUpLogging example' . PHP_EOL;
Expand All @@ -18,13 +16,11 @@
LoggerHolder::set(
new Logger('otel-php', [new StreamHandler(STDOUT, LogLevel::DEBUG)])
);
$transport = (new \OpenTelemetry\Contrib\Grpc\GrpcTransportFactory())->create();
putenv('OTEL_EXPORTER_OTLP_ENDPOINT=http://does-not-exist/endpoint'); //invalid endpoint, export will fail
putenv('OTEL_EXPORTER_OTLP_PROTOCOL=grpc');
$factory = new TracerProviderFactory('otlp-logging-demo');
$tracerProvider = $factory->create();

$tracerProvider = new TracerProvider(
new SimpleSpanProcessor(
new SpanExporter($transport) //default endpoint unavailable, so exporting will fail
)
);
$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');
$span = $tracer->spanBuilder('root-span')->startSpan();
$span->end();
Expand Down

0 comments on commit e3c2ee0

Please sign in to comment.