Skip to content

Commit 0dd326c

Browse files
committed
Restructure
1 parent a2bc945 commit 0dd326c

3 files changed

Lines changed: 32 additions & 32 deletions

File tree

src/Telemetry/Adapter/OpenTelemetry/Swoole/Transport.php renamed to src/Telemetry/Adapter/OpenTelemetry/Transport/Swoole.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Utopia\Telemetry\Adapter\OpenTelemetry\Swoole;
3+
namespace Utopia\Telemetry\Adapter\OpenTelemetry\Transport;
44

55
use OpenTelemetry\Contrib\Otlp\ContentTypes;
66
use OpenTelemetry\SDK\Common\Export\TransportInterface;
@@ -19,7 +19,7 @@
1919
* Uses connection pooling with keep-alive for maximum throughput.
2020
* Designed for Swoole's coroutine scheduler without cURL multi-handle conflicts.
2121
*/
22-
class Transport implements TransportInterface
22+
class Swoole implements TransportInterface
2323
{
2424
private string $host;
2525
private int $port;

tests/Telemetry/Adapter/OpenTelemetry/Swoole/TransportIntegrationTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use OpenTelemetry\Contrib\Otlp\ContentTypes;
66
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
77
use PHPUnit\Framework\TestCase;
8-
use Utopia\Telemetry\Adapter\OpenTelemetry\Swoole\Transport;
8+
use Utopia\Telemetry\Adapter\OpenTelemetry\Transport\Swoole;
99
use Utopia\Telemetry\Exception;
1010

1111
use function Swoole\Coroutine\go;
@@ -25,7 +25,7 @@ public function testSendPayloadToServer(): void
2525
MockOtlpServer::run(function (MockOtlpServer $server) {
2626
$server->respondWith(200, 'OK');
2727

28-
$transport = new Transport($server->getEndpoint());
28+
$transport = new Swoole($server->getEndpoint());
2929
$testPayload = 'test-metric-payload-data';
3030

3131
$result = $transport->send($testPayload)->await();
@@ -44,7 +44,7 @@ public function testSendPayloadToServer(): void
4444
public function testSendWithCustomHeaders(): void
4545
{
4646
MockOtlpServer::run(function (MockOtlpServer $server) {
47-
$transport = new Transport(
47+
$transport = new Swoole(
4848
endpoint: $server->getEndpoint(),
4949
headers: [
5050
'Authorization' => 'Bearer test-token',
@@ -67,7 +67,7 @@ public function testSendHandlesServerError(): void
6767
MockOtlpServer::run(function (MockOtlpServer $server) {
6868
$server->respondWith(500, 'Internal Server Error');
6969

70-
$transport = new Transport($server->getEndpoint());
70+
$transport = new Swoole($server->getEndpoint());
7171

7272
$this->expectException(Exception::class);
7373
$this->expectExceptionMessage('500');
@@ -83,7 +83,7 @@ public function testSendHandlesServerError(): void
8383
public function testMultipleSequentialSends(): void
8484
{
8585
MockOtlpServer::run(function (MockOtlpServer $server) {
86-
$transport = new Transport(
86+
$transport = new Swoole(
8787
endpoint: $server->getEndpoint(),
8888
poolSize: 2,
8989
);
@@ -103,7 +103,7 @@ public function testConcurrentSends(): void
103103
MockOtlpServer::run(function (MockOtlpServer $server) {
104104
$server->withDelay(0.01);
105105

106-
$transport = new Transport(
106+
$transport = new Swoole(
107107
endpoint: $server->getEndpoint(),
108108
poolSize: 4,
109109
);
@@ -130,7 +130,7 @@ public function testConcurrentSends(): void
130130
public function testJsonContentType(): void
131131
{
132132
MockOtlpServer::run(function (MockOtlpServer $server) {
133-
$transport = new Transport(
133+
$transport = new Swoole(
134134
endpoint: $server->getEndpoint(),
135135
contentType: ContentTypes::JSON,
136136
);
@@ -149,7 +149,7 @@ public function testConnectionTimeout(): void
149149
$exception = null;
150150

151151
run(function () use (&$exception) {
152-
$transport = new Transport(
152+
$transport = new Swoole(
153153
endpoint: 'http://127.0.0.1:19999/v1/metrics',
154154
timeout: 0.5,
155155
);
@@ -174,7 +174,7 @@ public function testConnectionTimeout(): void
174174
public function testKeepAliveConnectionReuse(): void
175175
{
176176
MockOtlpServer::run(function (MockOtlpServer $server) {
177-
$transport = new Transport(
177+
$transport = new Swoole(
178178
endpoint: $server->getEndpoint(),
179179
poolSize: 1,
180180
);
@@ -193,7 +193,7 @@ public function testKeepAliveConnectionReuse(): void
193193
public function testLargePayload(): void
194194
{
195195
MockOtlpServer::run(function (MockOtlpServer $server) {
196-
$transport = new Transport($server->getEndpoint());
196+
$transport = new Swoole($server->getEndpoint());
197197

198198
// 1MB payload
199199
$largePayload = str_repeat('x', 1024 * 1024);
@@ -210,7 +210,7 @@ public function testLargePayload(): void
210210
public function testServerResetsRequestTracking(): void
211211
{
212212
MockOtlpServer::run(function (MockOtlpServer $server) {
213-
$transport = new Transport($server->getEndpoint());
213+
$transport = new Swoole($server->getEndpoint());
214214

215215
$transport->send('first')->await();
216216
$this->assertEquals(1, $server->getRequestCount());

tests/Telemetry/Adapter/OpenTelemetry/Swoole/TransportTest.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use OpenTelemetry\Contrib\Otlp\ContentTypes;
66
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
77
use PHPUnit\Framework\TestCase;
8-
use Utopia\Telemetry\Adapter\OpenTelemetry\Swoole\Transport;
8+
use Utopia\Telemetry\Adapter\OpenTelemetry\Transport\Swoole;
99
use Utopia\Telemetry\Exception;
1010

1111
use function Swoole\Coroutine\run;
@@ -44,21 +44,21 @@ private function runInCoroutine(callable $callback): mixed
4444

4545
public function testConstructorParsesEndpointCorrectly(): void
4646
{
47-
$transport = new Transport('https://otel.example.com:4318/v1/metrics?foo=bar');
47+
$transport = new Swoole('https://otel.example.com:4318/v1/metrics?foo=bar');
4848

4949
$this->assertEquals(ContentTypes::PROTOBUF, $transport->contentType());
5050
}
5151

5252
public function testConstructorWithHttpEndpoint(): void
5353
{
54-
$transport = new Transport('http://localhost:4318/v1/metrics');
54+
$transport = new Swoole('http://localhost:4318/v1/metrics');
5555

5656
$this->assertEquals(ContentTypes::PROTOBUF, $transport->contentType());
5757
}
5858

5959
public function testConstructorWithCustomContentType(): void
6060
{
61-
$transport = new Transport(
61+
$transport = new Swoole(
6262
'http://localhost:4318/v1/metrics',
6363
ContentTypes::JSON
6464
);
@@ -68,7 +68,7 @@ public function testConstructorWithCustomContentType(): void
6868

6969
public function testConstructorWithCustomHeaders(): void
7070
{
71-
$transport = new Transport(
71+
$transport = new Swoole(
7272
'http://localhost:4318/v1/metrics',
7373
ContentTypes::PROTOBUF,
7474
['Authorization' => 'Bearer token123']
@@ -79,7 +79,7 @@ public function testConstructorWithCustomHeaders(): void
7979

8080
public function testConstructorWithCustomTimeout(): void
8181
{
82-
$transport = new Transport(
82+
$transport = new Swoole(
8383
'http://localhost:4318/v1/metrics',
8484
ContentTypes::PROTOBUF,
8585
[],
@@ -91,7 +91,7 @@ public function testConstructorWithCustomTimeout(): void
9191

9292
public function testConstructorWithCustomPoolSize(): void
9393
{
94-
$transport = new Transport(
94+
$transport = new Swoole(
9595
'http://localhost:4318/v1/metrics',
9696
ContentTypes::PROTOBUF,
9797
[],
@@ -104,7 +104,7 @@ public function testConstructorWithCustomPoolSize(): void
104104

105105
public function testConstructorWithCustomSocketBufferSize(): void
106106
{
107-
$transport = new Transport(
107+
$transport = new Swoole(
108108
'http://localhost:4318/v1/metrics',
109109
ContentTypes::PROTOBUF,
110110
[],
@@ -119,7 +119,7 @@ public function testConstructorWithCustomSocketBufferSize(): void
119119
public function testShutdownReturnsTrue(): void
120120
{
121121
$this->runInCoroutine(function () {
122-
$transport = new Transport('http://localhost:4318/v1/metrics');
122+
$transport = new Swoole('http://localhost:4318/v1/metrics');
123123

124124
$result = $transport->shutdown();
125125

@@ -130,7 +130,7 @@ public function testShutdownReturnsTrue(): void
130130
public function testForceFlushReturnsTrue(): void
131131
{
132132
$this->runInCoroutine(function () {
133-
$transport = new Transport('http://localhost:4318/v1/metrics');
133+
$transport = new Swoole('http://localhost:4318/v1/metrics');
134134

135135
$result = $transport->forceFlush();
136136

@@ -141,22 +141,22 @@ public function testForceFlushReturnsTrue(): void
141141
public function testSendAfterShutdownReturnsError(): void
142142
{
143143
$this->runInCoroutine(function () {
144-
$transport = new Transport('http://localhost:4318/v1/metrics');
144+
$transport = new Swoole('http://localhost:4318/v1/metrics');
145145

146146
$transport->shutdown();
147147

148148
$future = $transport->send('test payload');
149149

150150
$this->expectException(Exception::class);
151-
$this->expectExceptionMessage('Transport has been shut down');
151+
$this->expectExceptionMessage('Swoole has been shut down');
152152
$future->await();
153153
});
154154
}
155155

156156
public function testMultipleShutdownsAreSafe(): void
157157
{
158158
$this->runInCoroutine(function () {
159-
$transport = new Transport('http://localhost:4318/v1/metrics');
159+
$transport = new Swoole('http://localhost:4318/v1/metrics');
160160

161161
$result1 = $transport->shutdown();
162162
$result2 = $transport->shutdown();
@@ -168,37 +168,37 @@ public function testMultipleShutdownsAreSafe(): void
168168

169169
public function testEndpointWithQueryString(): void
170170
{
171-
$transport = new Transport('http://localhost:4318/v1/metrics?api_key=secret&env=test');
171+
$transport = new Swoole('http://localhost:4318/v1/metrics?api_key=secret&env=test');
172172

173173
$this->assertEquals(ContentTypes::PROTOBUF, $transport->contentType());
174174
}
175175

176176
public function testEndpointDefaultsToLocalhost(): void
177177
{
178178
// Malformed URL should still create transport (defaults to localhost)
179-
$transport = new Transport('http:///v1/metrics');
179+
$transport = new Swoole('http:///v1/metrics');
180180

181181
$this->assertEquals(ContentTypes::PROTOBUF, $transport->contentType());
182182
}
183183

184184
public function testDefaultPortForHttp(): void
185185
{
186-
$transport = new Transport('http://example.com/v1/metrics');
186+
$transport = new Swoole('http://example.com/v1/metrics');
187187

188188
$this->assertEquals(ContentTypes::PROTOBUF, $transport->contentType());
189189
}
190190

191191
public function testDefaultPortForHttps(): void
192192
{
193-
$transport = new Transport('https://example.com/v1/metrics');
193+
$transport = new Swoole('https://example.com/v1/metrics');
194194

195195
$this->assertEquals(ContentTypes::PROTOBUF, $transport->contentType());
196196
}
197197

198198
public function testContentTypeMatchesConstructor(): void
199199
{
200-
$jsonTransport = new Transport('http://localhost:4318', ContentTypes::JSON);
201-
$protobufTransport = new Transport('http://localhost:4318', ContentTypes::PROTOBUF);
200+
$jsonTransport = new Swoole('http://localhost:4318', ContentTypes::JSON);
201+
$protobufTransport = new Swoole('http://localhost:4318', ContentTypes::PROTOBUF);
202202

203203
$this->assertEquals(ContentTypes::JSON, $jsonTransport->contentType());
204204
$this->assertEquals(ContentTypes::PROTOBUF, $protobufTransport->contentType());

0 commit comments

Comments
 (0)