Skip to content

Commit

Permalink
fix(Builder): remove some methods that triggers error for dynamic pro…
Browse files Browse the repository at this point in the history
…perty declaration (#6)

* fix(Builder): remove some methods that triggers error for dynamic property declaration

A long as this methods should not be called and there are other methods that
are equivalent and they are the ones that should be used, this change won't be
considered a BC

* docs(examples/example-1.php): add long text as attribute on usage examples

Works better than gTrace!! gTrace has a native restriction on attribute length, 256 is the max length for them. Jaegger or Zipkin has not.
  • Loading branch information
Muriano authored Oct 17, 2023
1 parent 6927008 commit e351723
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 30 deletions.
4 changes: 3 additions & 1 deletion examples/example-1.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ function recursiveFunction(Telephponic $tracer, int $number = 10): int
];
});

$tracer->start('search-engine');
$longText = str_repeat('a', 1000);

$tracer->start('search-engine', ['long.text' => $longText]);
{
$tracer->addEvent('search-engine-started', ['search-engine' => 'started']);
sleep(1);
Expand Down
39 changes: 10 additions & 29 deletions src/Trace/Builder/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace GR\Telephponic\Trace\Builder;

use Exception;
use GR\Telephponic\Trace\Integration\Curl;
use GR\Telephponic\Trace\Integration\Grpc;
use GR\Telephponic\Trace\Integration\Integration;
Expand All @@ -21,7 +20,7 @@
use OpenTelemetry\Contrib\Grpc\GrpcTransportFactory;
use OpenTelemetry\Contrib\Otlp\OtlpUtil;
use OpenTelemetry\Contrib\Otlp\SpanExporter;
use OpenTelemetry\Contrib\Zipkin\Exporter;
use OpenTelemetry\Contrib\Zipkin\Exporter as ZipkinExporter;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Common\Export\Http\PsrTransportFactory;
use OpenTelemetry\SDK\Common\Export\TransportInterface;
Expand All @@ -41,6 +40,7 @@
use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\SDK\Trace\TracerProvider;
use OpenTelemetry\SemConv\ResourceAttributes;
use RuntimeException;

class Builder
{
Expand All @@ -51,9 +51,10 @@ class Builder
private ?SpanExporterInterface $exporter = null;
private bool $batchMode = false;
private array $defaultAttributes = [];
private $registerShutdown = true;
private bool $registerShutdown = true;
private ?StacktraceProvider $stacktraceProvider = null;
private array $integrations = [];
private TextMapPropagatorInterface $propagator;

public function __construct(
private readonly string $appName,
Expand Down Expand Up @@ -140,43 +141,23 @@ public function forZipkinExportation(string $url, string $name = 'telephponic'):
{
return $this
->withTransport(PsrTransportFactory::discover()->create($url, 'application/json'))
->withExporter(new Exporter($name, $this->transport))
->withExporter(new ZipkinExporter($name, $this->transport))
;
}

public function enableShutdownHandler(): self
{
$this->enableShutdownHandler = true;

return $this;
}

public function disableShutdownHandler(): self
{
$this->enableShutdownHandler = false;

return $this;
}

/** @throws RuntimeException */
public function withDefaultSpanExporter(): self
{
if ($this->transport === null) {
throw new Exception('Transport not set'); // fixme Use a custom exception
throw new RuntimeException('Transport not set'); // fixme Use a custom exception
}

return $this->withSpanExporter(new SpanExporter($this->transport));
}

private function withSpanExporter(SpanExporterInterface $spanExporter): self
{
$this->spanExporter = $spanExporter;

return $this;
return $this->withExporter(new SpanExporter($this->transport));
}

public function withInMemoryExporter(): self
{
return $this->withSpanExporter(new InMemoryExporter());
return $this->withExporter(new InMemoryExporter());
}

public function withTraceContextPropagator(): self
Expand Down Expand Up @@ -206,7 +187,7 @@ public function withClock(ClockInterface $clock): self
public function build(): Telephponic
{
if ($this->exporter === null) {
throw new Exception('Exporter is not set'); // fixme Use a custom exception
throw new RuntimeException('Exporter is not set'); // fixme Use a custom exception
}

if ($this->resourceInfo === null) {
Expand Down

0 comments on commit e351723

Please sign in to comment.