-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathOpenTelemetryConfigBuilder.php
More file actions
100 lines (88 loc) · 2.59 KB
/
OpenTelemetryConfigBuilder.php
File metadata and controls
100 lines (88 loc) · 2.59 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
declare(strict_types=1);
namespace ValkeyGlide\OpenTelemetry;
use ValkeyGlideException;
/**
* Builder for OpenTelemetryConfig.
*/
class OpenTelemetryConfigBuilder
{
private ?TracesConfig $traces = null;
private ?MetricsConfig $metrics = null;
private int $flushIntervalMs = 5000; // Default value
/**
* Sets the traces configuration.
*
* @param TracesConfig|null $traces The traces configuration, or null to disable traces.
* @return self This builder instance for method chaining.
*/
public function traces(?TracesConfig $traces): self
{
$this->traces = $traces;
return $this;
}
/**
* Sets the metrics configuration.
*
* @param MetricsConfig|null $metrics The metrics configuration, or null to disable metrics.
* @return self This builder instance for method chaining.
*/
public function metrics(?MetricsConfig $metrics): self
{
$this->metrics = $metrics;
return $this;
}
/**
* Sets the flush interval in milliseconds.
*
* @param int $flushIntervalMs The flush interval in milliseconds (must be positive).
* @return self This builder instance for method chaining.
*/
public function flushIntervalMs(int $flushIntervalMs): self
{
if ($flushIntervalMs <= 0) {
throw new ValkeyGlideException("Flush interval must be a positive integer");
}
$this->flushIntervalMs = $flushIntervalMs;
return $this;
}
/**
* Gets the traces configuration.
*
* @return TracesConfig|null The traces configuration, or null if not configured.
*/
public function getTraces(): ?TracesConfig
{
return $this->traces;
}
/**
* Gets the metrics configuration.
*
* @return MetricsConfig|null The metrics configuration, or null if not configured.
*/
public function getMetrics(): ?MetricsConfig
{
return $this->metrics;
}
/**
* Gets the flush interval in milliseconds.
*
* @return int The flush interval in milliseconds.
*/
public function getFlushIntervalMs(): int
{
return $this->flushIntervalMs;
}
/**
* Builds the OpenTelemetryConfig.
*
* @return OpenTelemetryConfig The immutable OpenTelemetry configuration.
*/
public function build(): OpenTelemetryConfig
{
if ($this->traces === null && $this->metrics === null) {
throw new ValkeyGlideException("At least one of traces or metrics must be configured");
}
return new OpenTelemetryConfig($this);
}
}