Skip to content

Commit 10dc6b5

Browse files
committed
updated README
1 parent 8035f6f commit 10dc6b5

File tree

2 files changed

+35
-70
lines changed

2 files changed

+35
-70
lines changed

.github/workflows/php.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ jobs:
6060
'ResourceDetectors/Container',
6161
'ResourceDetectors/DigitalOcean',
6262
'Sampler/RuleBased',
63+
'Sampler/Xray',
6364
'Shims/OpenTracing',
6465
'Symfony',
6566
'Utils/Test'

src/Sampler/Xray/README.md

Lines changed: 34 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,51 @@
1-
# Contrib Sampler
1+
# AWS X-Ray Sampler
22

3-
Provides additional samplers that are not part of the official specification.
3+
Provides a sampler which can get sampling configurations from AWS X-Ray to make sampling decisions. See: [AWS X-Ray Sampling](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-sampling)
44

55
## Installation
66

77
```shell
8-
composer require open-telemetry/sampler-rule-based
8+
composer require open-telemetry/contrib-aws-xray-sampler
99
```
1010

11-
## RuleBasedSampler
12-
13-
Allows sampling based on a list of rule sets. The first matching rule set will decide the sampling result.
11+
## Configuration
12+
You can configure the `AWSXRayRemoteSampler` as per the following example.
13+
Note that you will need to configure your [OpenTelemetry Collector for
14+
X-Ray remote sampling](https://aws-otel.github.io/docs/getting-started/remote-sampling).
1415

1516
```php
16-
$sampler = new RuleBasedSampler(
17-
[
18-
new RuleSet(
19-
[
20-
new SpanKindRule(Kind::Server),
21-
new AttributeRule('url.path', '~^/health$~'),
22-
],
23-
new AlwaysOffSampler(),
24-
),
25-
],
26-
new AlwaysOnSampler(),
27-
);
28-
```
29-
30-
### Configuration
31-
32-
###### Example: drop spans for the /health endpoint
33-
34-
```yaml
35-
contrib_rule_based:
36-
rule_sets:
37-
- rules:
38-
- span_kind: { kind: SERVER }
39-
- attribute: { key: url.path, pattern: ~^/health$~ }
40-
delegate:
41-
always_off: {}
42-
fallback: # ...
43-
```
17+
<?php
4418

45-
###### Example: sample spans with at least one sampled link
19+
declare(strict_types=1);
4620

47-
```yaml
48-
contrib_rule_based:
49-
rule_sets:
50-
- rules: [ link: { sampled: true } ]
51-
delegate:
52-
always_on: {}
53-
fallback: # ...
54-
```
55-
56-
###### Example: modeling parent based sampler as rule based sampler
57-
58-
```yaml
59-
rule_based:
60-
rule_sets:
61-
- rules: [ parent: { sampled: true, remote: true } ]
62-
delegate: # remote_parent_sampled
63-
- rules: [ parent: { sampled: false, remote: true } ]
64-
delegate: # remote_parent_not_sampled
65-
- rules: [ parent: { sampled: true, remote: false } ]
66-
delegate: # local_parent_sampled
67-
- rules: [ parent: { sampled: false, remote: false } ]
68-
delegate: # local_parent_not_sampled
69-
fallback: # root
70-
```
21+
require __DIR__ . '/vendor/autoload.php';
7122

72-
## AlwaysRecordingSampler
23+
use OpenTelemetry\SDK\Trace\TracerProvider;
24+
use OpenTelemetry\SDK\Common\Attribute\Attributes;
25+
use OpenTelemetry\SDK\Trace\SpanExporter\ConsoleSpanExporterFactory;
26+
use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor;
27+
use OpenTelemetry\SDK\Resource\ResourceInfo;
28+
use OpenTelemetry\Contrib\Sampler\Xray\AWSXRayRemoteSampler;
7329

74-
Records all spans to allow the usage of span processors that generate metrics from spans.
30+
$resource = ResourceInfo::create(Attributes::create([
31+
'service.name' => 'MyServiceName',
32+
'service.version'=> '1.0.0',
33+
'cloud.provider' => 'aws',
34+
]));
7535

76-
```php
77-
$sampler = new AlwaysRecordingSampler(
78-
new ParentBasedSampler(new AlwaysOnSampler()),
36+
$xraySampler = new AWSXRayRemoteSampler(
37+
$resource,
38+
'http://localhost:2000',
39+
2
7940
);
80-
```
81-
82-
### Configuration
8341

84-
```yaml
85-
always_recording:
86-
sampler: # ...
42+
$tracerProvider = TracerProvider::builder()
43+
->setResource($resource)
44+
->setSampler($xraySampler)
45+
->addSpanProcessor(
46+
new SimpleSpanProcessor(
47+
(new ConsoleSpanExporterFactory())->create()
48+
)
49+
)
50+
->build();
8751
```

0 commit comments

Comments
 (0)