Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 60f31a4

Browse files
authored
Remove sampler factory (#72)
* Remove SamplerFactory * Remove documentation mentioning the SamplerFactory
1 parent b9d248e commit 60f31a4

4 files changed

Lines changed: 11 additions & 188 deletions

File tree

src/Trace/Sampler/SamplerFactory.php

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/Trace/Tracer.php

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
use OpenCensus\Core\Scope;
2121
use OpenCensus\Trace\Span;
22-
use OpenCensus\Trace\Sampler\SamplerFactory;
22+
use OpenCensus\Trace\Sampler\AlwaysSampleSampler;
2323
use OpenCensus\Trace\Sampler\SamplerInterface;
2424
use OpenCensus\Trace\Exporter\ExporterInterface;
2525
use OpenCensus\Trace\Propagator\PropagatorInterface;
@@ -57,19 +57,7 @@
5757
* The above uses a query-per-second sampler at 0.1 requests/second. The implementation
5858
* requires a PSR-6 cache. See {@see OpenCensus\Trace\Sampler\QpsSampler} for more information.
5959
* You may provide your own implementation of {@see OpenCensus\Trace\Sampler\SamplerInterface}
60-
* or use one of the provided. You may provide a configuration array for the sampler instead. See
61-
* {@see OpenCensus\Trace\Sampler\SamplerFactory::build()} for builder options:
62-
*
63-
* ```
64-
* // $cache is a PSR-6 cache implementation
65-
* Tracer::start($reporter, [
66-
* 'sampler' => [
67-
* 'type' => 'qps',
68-
* 'rate' => 0.1,
69-
* 'cache' => $cache
70-
* ]
71-
* ]);
72-
* ```
60+
* or use one of the provided.
7361
*
7462
* To trace code, you can use static {@see OpenCensus\Trace\Tracer::inSpan()} helper function:
7563
*
@@ -120,8 +108,8 @@ class Tracer
120108
* Configuration options. See
121109
* {@see OpenCensus\Trace\Span::__construct()} for the other available options.
122110
*
123-
* @type SamplerInterface|array $sampler Sampler or sampler factory build arguments. See
124-
* {@see OpenCensus\Trace\Sampler\SamplerFactory::build()} for the available options.
111+
* @type SamplerInterface $sampler Sampler that defines the sampling rules.
112+
* **Defaults to** a new `AlwaysSampleSampler`.
125113
* @type PropagatorInterface $propagator SpanContext propagator. **Defaults to**
126114
* a new `HttpHeaderPropagator` instance
127115
* @type array $headers Optional array of headers to use in place of $_SERVER
@@ -130,13 +118,11 @@ class Tracer
130118
*/
131119
public static function start(ExporterInterface $reporter, array $options = [])
132120
{
133-
$samplerOptions = array_key_exists('sampler', $options) ? $options['sampler'] : [];
121+
$sampler = array_key_exists('sampler', $options)
122+
? $options['sampler']
123+
: new AlwaysSampleSampler();
134124
unset($options['sampler']);
135125

136-
$sampler = ($samplerOptions instanceof SamplerInterface)
137-
? $samplerOptions
138-
: SamplerFactory::build($samplerOptions);
139-
140126
$propagator = array_key_exists('propagator', $options)
141127
? $options['propagator']
142128
: new HttpHeaderPropagator();

tests/unit/Trace/Sampler/SamplerFactoryTest.php

Lines changed: 0 additions & 94 deletions
This file was deleted.

tests/unit/Trace/TracerTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
namespace OpenCensus\Tests\Unit\Trace;
1919

2020
use OpenCensus\Trace\Exporter\ExporterInterface;
21+
use OpenCensus\Trace\Sampler\AlwaysSampleSampler;
22+
use OpenCensus\Trace\Sampler\NeverSampleSampler;
2123
use OpenCensus\Trace\Tracer;
2224
use OpenCensus\Trace\Tracer\NullTracer;
2325

@@ -36,7 +38,7 @@ public function setUp()
3638
public function testForceDisabled()
3739
{
3840
$rt = Tracer::start($this->reporter->reveal(), [
39-
'sampler' => ['type' => 'disabled']
41+
'sampler' => new NeverSampleSampler()
4042
]);
4143
$tracer = $rt->tracer();
4244

@@ -47,7 +49,7 @@ public function testForceDisabled()
4749
public function testForceEnabled()
4850
{
4951
$rt = Tracer::start($this->reporter->reveal(), [
50-
'sampler' => ['type' => 'enabled']
52+
'sampler' => new AlwaysSampleSampler()
5153
]);
5254
$tracer = $rt->tracer();
5355

0 commit comments

Comments
 (0)