• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FriendsOfOpenTelemetry / opentelemetry-bundle / 7752972926

02 Feb 2024 07:53AM UTC coverage: 35.071% (-29.5%) from 64.527%
7752972926

Pull #38

github

gaelreyrol
wip
Pull Request #38: Refactor services injection

99 of 459 new or added lines in 44 files covered. (21.57%)

314 existing lines in 33 files now uncovered.

740 of 2110 relevant lines covered (35.07%)

2.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.09
/src/OpenTelemetry/Exporter/OtlpExporterOptions.php
1
<?php
2

3
namespace FriendsOfOpenTelemetry\OpenTelemetryBundle\OpenTelemetry\Exporter;
4

5
use FriendsOfOpenTelemetry\OpenTelemetryBundle\OpenTelemetry\Transport\TransportParams;
6
use OpenTelemetry\Contrib\Otlp\OtlpUtil;
7

8
final class OtlpExporterOptions implements ExporterOptionsInterface
9
{
10
    /** @var float */
11
    public const DEFAULT_TIMEOUT = .10;
12

13
    /** @var int */
14
    public const DEFAULT_RETRY_DELAY = 100;
15

16
    /** @var int */
17
    public const DEFAULT_MAX_RETRIES = 3;
18

19
    /**
20
     * @param array<string, mixed> $headers
21
     */
22
    public function __construct(
23
        private OtlpExporterFormatEnum $format = OtlpExporterFormatEnum::Json,
24
        private array $headers = [],
25
        private OtlpExporterCompressionEnum $compression = OtlpExporterCompressionEnum::None,
26
        private float $timeout = self::DEFAULT_TIMEOUT,
27
        private int $retryDelay = self::DEFAULT_RETRY_DELAY,
28
        private int $maxRetries = self::DEFAULT_MAX_RETRIES,
29
        private ?string $caCertificate = null,
30
        private ?string $certificate = null,
31
        private ?string $key = null,
32
    ) {
33
    }
20✔
34

35
    public static function fromConfiguration(array $configuration): self
36
    {
37
        $options = new self();
18✔
38

39
        if (isset($configuration['format']) && null !== OtlpExporterFormatEnum::tryFrom($configuration['format'])) {
18✔
40
            $options->format = OtlpExporterFormatEnum::from($configuration['format']);
2✔
41
        }
42

43
        if (isset($configuration['headers'])) {
18✔
44
            $options->headers = $configuration['headers'];
2✔
45
        }
46

47
        $otlpHeaders = OtlpUtil::getUserAgentHeader();
18✔
48
        $otlpHeaders['User-Agent'] .= ', Symfony OTEL Bundle';
18✔
49
        $options->headers += $otlpHeaders;
18✔
50

51
        if (isset($configuration['compression']) && null !== OtlpExporterCompressionEnum::tryFrom($configuration['compression'])) {
18✔
52
            $options->compression = OtlpExporterCompressionEnum::from($configuration['compression']);
2✔
53
        }
54

55
        if (isset($configuration['timeout'])) {
18✔
56
            $options->timeout = $configuration['timeout'];
2✔
57
        }
58

59
        if (isset($configuration['retry'])) {
18✔
60
            $options->retryDelay = $configuration['retry'];
2✔
61
        }
62

63
        if (isset($configuration['max'])) {
18✔
64
            $options->maxRetries = $configuration['max'];
2✔
65
        }
66

67
        if (isset($configuration['ca'])) {
18✔
68
            $options->caCertificate = $configuration['ca'];
2✔
69
        }
70

71
        if (isset($configuration['cert'])) {
18✔
72
            $options->certificate = $configuration['cert'];
2✔
73
        }
74

75
        if (isset($configuration['key'])) {
18✔
76
            $options->key = $configuration['key'];
2✔
77
        }
78

79
        return $options;
18✔
80
    }
81

82
    public function toTransportParams(): TransportParams
83
    {
UNCOV
84
        return new TransportParams(
×
UNCOV
85
            $this->getFormat()->toContentType(),
×
UNCOV
86
            $this->getHeaders(),
×
UNCOV
87
            $this->getCompression()->toKnownValue(),
×
UNCOV
88
            $this->getTimeout(),
×
UNCOV
89
            $this->getRetryDelay(),
×
UNCOV
90
            $this->getMaxRetries(),
×
UNCOV
91
            $this->getCaCertificate(),
×
UNCOV
92
            $this->getCertificate(),
×
UNCOV
93
            $this->getKey(),
×
UNCOV
94
        );
×
95
    }
96

97
    public function getFormat(): OtlpExporterFormatEnum
98
    {
99
        return $this->format;
4✔
100
    }
101

102
    /**
103
     * @return array<string, mixed>
104
     */
105
    public function getHeaders(): array
106
    {
107
        $otlpHeaders = OtlpUtil::getUserAgentHeader();
4✔
108
        $otlpHeaders['User-Agent'] .= ', Symfony OTEL Bundle';
4✔
109

110
        return $this->headers + $otlpHeaders;
4✔
111
    }
112

113
    public function getCompression(): OtlpExporterCompressionEnum
114
    {
115
        return $this->compression;
4✔
116
    }
117

118
    public function getTimeout(): float
119
    {
120
        return $this->timeout;
4✔
121
    }
122

123
    public function getRetryDelay(): int
124
    {
125
        return $this->retryDelay;
4✔
126
    }
127

128
    public function getMaxRetries(): int
129
    {
130
        return $this->maxRetries;
4✔
131
    }
132

133
    public function getCaCertificate(): ?string
134
    {
135
        return $this->caCertificate;
4✔
136
    }
137

138
    public function getCertificate(): ?string
139
    {
140
        return $this->certificate;
4✔
141
    }
142

143
    public function getKey(): ?string
144
    {
145
        return $this->key;
4✔
146
    }
147
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc