Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instrumentation scope attributes #735

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Remove SDK ::getTracer() default name
Instrumentation should use API `TracerProvider` which requires providing a name.
  • Loading branch information
Nevay committed Jun 29, 2022
commit d250781eef3003f4fe9f88c04622c1cb24beff3d
2 changes: 1 addition & 1 deletion examples/AirGappedTraceDebugging.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
new SimpleSpanProcessor($exporter),
new AlwaysOnSampler()
);
$tracer = $tracerProvider->getTracer();
$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');
/**
* Create some tracing data
*/
Expand Down
2 changes: 1 addition & 1 deletion examples/AlwaysOnJaegerExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

echo 'Starting AlwaysOnJaegerExample';

$tracer = $tracerProvider->getTracer();
$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');

$rootSpan = $tracer->spanBuilder('root')->startSpan();
$rootSpan->activate();
Expand Down
2 changes: 1 addition & 1 deletion examples/AlwaysOnJaegerThriftExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

echo 'Starting JaegerThriftExample';

$tracer = $tracerProvider->getTracer();
$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');

$rootSpan = $tracer->spanBuilder('root')->startSpan();
$rootSpan->activate();
Expand Down
2 changes: 1 addition & 1 deletion examples/AlwaysOnOTLPExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
$exporter
)
);
$tracer = $tracerProvider->getTracer();
$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');

$root = $span = $tracer->spanBuilder('root')->startSpan();
$span->activate();
Expand Down
2 changes: 1 addition & 1 deletion examples/AlwaysOnOTLPGrpcExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
$exporter
)
);
$tracer = $tracerProvider->getTracer();
$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');

$root = $span = $tracer->spanBuilder('root')->startSpan();
$span->activate();
Expand Down
2 changes: 1 addition & 1 deletion examples/AlwaysOnZipkinExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
$zipkinExporter
)
);
$tracer = $tracerProvider->getTracer();
$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');

echo 'Starting AlwaysOnZipkinExample';

Expand Down
2 changes: 1 addition & 1 deletion examples/BatchExporting.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)
);

$tracer = $tracerProvider->getTracer();
$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');

$rootSpan = $tracer->spanBuilder('root')->startSpan();
$scope = $rootSpan->activate();
Expand Down
2 changes: 1 addition & 1 deletion examples/ConcurrentSpans.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
);

$tracer = $tracerProvider->getTracer();
$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');

$rootSpan = $tracer->spanBuilder('root')->startSpan();
$scope = $rootSpan->activate();
Expand Down
2 changes: 1 addition & 1 deletion examples/ConfigurationFromEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

$tracerProvider = (new TracerProviderFactory('example'))->create();

$tracer = $tracerProvider->getTracer();
$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');

echo 'Starting Tracer' . PHP_EOL;

Expand Down
2 changes: 1 addition & 1 deletion examples/CreatingANewTraceInTheSameProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
new SimpleSpanProcessor(
new ConsoleSpanExporter()
)
))->getTracer();
))->getTracer('io.opentelemetry.contrib.php');

// This creates a span and sets it as the current parent (and root) span
$rootSpan = $tracer->spanBuilder('foo')->startSpan();
Expand Down
2 changes: 1 addition & 1 deletion examples/GettingStarted.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
);

$tracer = $tracerProvider->getTracer();
$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');

//start a root span
$rootSpan = $tracer->spanBuilder('root')->startSpan();
Expand Down
2 changes: 1 addition & 1 deletion examples/LoggingOfSpanData.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
new BatchSpanProcessor($decorator),
new AlwaysOnSampler()
);
$tracer = $tracerProvider->getTracer();
$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');
/**
* Create some tracing data
*/
Expand Down
2 changes: 1 addition & 1 deletion examples/ResourceDetectors.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

$tracerProvider = (new TracerProviderFactory('example'))->create();

$tracer = $tracerProvider->getTracer();
$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');

echo 'Starting Tracer' . PHP_EOL;

Expand Down
2 changes: 1 addition & 1 deletion examples/SettingUpLogging.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
new OtlpGrpcExporter(), //default endpoint unavailable, so exporting will fail
)
);
$tracer = $tracerProvider->getTracer();
$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');
$span = $tracer->spanBuilder('root-span')->startSpan();
$span->end();
2 changes: 1 addition & 1 deletion examples/SpanResources.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
$resource
);

$tracer = $tracerProvider->getTracer();
$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');

$span = $tracer->spanBuilder('root')->startSpan();
$span->end();
2 changes: 1 addition & 1 deletion examples/distributed-tracing/src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use Slim\Routing\RouteContext;

//create default tracer from environment variables, now available as TracerProvider::getDefaultTracer
$tracer = (new TracerProviderFactory('example'))->create()->getTracer();
$tracer = (new TracerProviderFactory('example'))->create()->getTracer('io.opentelemetry.contrib.php');

$cb = new ContainerBuilder();
$container = $cb->addDefinitions([
Expand Down
4 changes: 1 addition & 3 deletions src/SDK/Trace/TracerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

final class TracerProvider implements API\TracerProviderInterface
{
public const DEFAULT_TRACER_NAME = 'io.opentelemetry.contrib.php';

/** @var array<int, WeakReference<self>>|null */
private static ?array $tracerProviders = null;

Expand Down Expand Up @@ -67,7 +65,7 @@ public function forceFlush(): ?bool

/** @inheritDoc */
public function getTracer(
string $name = self::DEFAULT_TRACER_NAME,
string $name,
?string $version = null,
?string $schemaUrl = null,
iterable $attributes = []
Expand Down
6 changes: 3 additions & 3 deletions tests/Benchmark/OtlpBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function setUpNoExporter(): void
{
$processor = new SimpleSpanProcessor();
$provider = new TracerProvider($processor, $this->sampler, $this->resource);
$this->tracer = $provider->getTracer();
$this->tracer = $provider->getTracer('io.opentelemetry.contrib.php');
}

public function setUpGrpc(): void
Expand All @@ -55,7 +55,7 @@ public function setUpGrpc(): void
$exporter = new GrpcExporter('foo:4317', true, '', '', false, 10, $client);
$processor = new SimpleSpanProcessor($exporter);
$provider = new TracerProvider($processor, $this->sampler, $this->resource);
$this->tracer = $provider->getTracer();
$this->tracer = $provider->getTracer('io.opentelemetry.contrib.php');
}

/**
Expand All @@ -81,7 +81,7 @@ public function setUpGrpcHttp(): void
$exporter = new HttpExporter($client, $requestFactory, $streamFactory);
$processor = new SimpleSpanProcessor($exporter);
$provider = new TracerProvider($processor, $this->sampler, $this->resource);
$this->tracer = $provider->getTracer();
$this->tracer = $provider->getTracer('io.opentelemetry.contrib.php');
}

/**
Expand Down
30 changes: 0 additions & 30 deletions tests/Unit/SDK/Trace/TracerProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

namespace OpenTelemetry\Tests\Unit\SDK\Trace;

use OpenTelemetry\API\Trace as API;
use OpenTelemetry\API\Trace\NoopTracer;
use OpenTelemetry\SDK\Trace\SamplerInterface;
use OpenTelemetry\SDK\Trace\Tracer;
use OpenTelemetry\SDK\Trace\TracerProvider;
use PHPUnit\Framework\TestCase;
use WeakReference;
Expand All @@ -33,20 +31,6 @@ public function test_equal_for_same_name_without_version(): void
$this->assertNotEquals($t1, $t3);
}

/**
* @covers ::getTracer
* @covers ::__construct
* @group trace-compliance
*/
public function test_get_tracer_default(): void
{
$provider = new TracerProvider(null);

$t1 = $provider->getTracer();

$this->assertInstanceOf(Tracer::class, $t1);
}

/**
* @covers ::getTracer
* @covers ::__construct
Expand Down Expand Up @@ -80,20 +64,6 @@ public function test_equal_for_same_name_with_schema_and_version(): void
$this->assertNotEquals($t1, $t3);
}

/**
* @covers ::getTracer
* @group trace-compliance
*/
public function test_get_tracer_with_default_name(): void
{
$provider = new TracerProvider(null);

$t1 = $provider->getTracer();
$t2 = $provider->getTracer();

$this->assertSame($t1, $t2);
}

/**
* @covers ::shutdown
* @group trace-compliance
Expand Down