-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathTracesConfigBuilder.php
More file actions
83 lines (73 loc) · 2.05 KB
/
TracesConfigBuilder.php
File metadata and controls
83 lines (73 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
declare(strict_types=1);
namespace ValkeyGlide\OpenTelemetry;
use ValkeyGlideException;
/**
* Builder for TracesConfig.
*/
class TracesConfigBuilder
{
private ?string $endpoint = null;
private int $samplePercentage = 1; // Default value
/**
* Sets the endpoint.
*
* @param string $endpoint The traces endpoint URL.
* @return self This builder instance for method chaining.
*/
public function endpoint(string $endpoint): self
{
if (empty($endpoint)) {
throw new ValkeyGlideException("Traces endpoint cannot be empty");
}
$this->endpoint = $endpoint;
return $this;
}
/**
* Sets the sample percentage.
*
* @param int $samplePercentage The sample percentage (0-100).
* @return self This builder instance for method chaining.
*/
public function samplePercentage(int $samplePercentage): self
{
if ($samplePercentage < 0 || $samplePercentage > 100) {
throw new ValkeyGlideException("Sample percentage must be between 0 and 100");
}
$this->samplePercentage = $samplePercentage;
return $this;
}
/**
* Gets the endpoint.
*
* @return string The traces endpoint URL.
*/
public function getEndpoint(): string
{
if ($this->endpoint === null) {
throw new ValkeyGlideException("Traces endpoint is required when traces config is provided");
}
return $this->endpoint;
}
/**
* Gets the sample percentage.
*
* @return int The sample percentage (0-100).
*/
public function getSamplePercentage(): int
{
return $this->samplePercentage;
}
/**
* Builds the TracesConfig.
*
* @return TracesConfig The immutable traces configuration.
*/
public function build(): TracesConfig
{
if ($this->endpoint === null) {
throw new ValkeyGlideException("Traces endpoint is required when traces config is provided");
}
return new TracesConfig($this);
}
}