Skip to content

Commit ed4ff11

Browse files
author
Maxim Usenko
committed
Added the Kafka Transport implementation
1 parent 8127daa commit ed4ff11

16 files changed

Lines changed: 293 additions & 7 deletions

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"ext-grpc": "*",
4444
"ext-mbstring": "*",
4545
"ext-opentelemetry": "*",
46+
"ext-rdkafka": "*",
4647
"ext-pdo": "*",
4748
"ext-pdo_sqlite": "*",
4849
"ext-xdebug": "*",

docs/src/instrumentation/traces.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ A DSN starts with a transport and an exporter separated by a `+` character. The
4242

4343
Here is table list of the available transport and exporter for traces:
4444

45-
| Transport | Exporter | Description | Example | Default |
46-
|-----------|-----------|--------------------------------------------------------------|-------------------------------------------|--------------|
47-
| http(s) | otlp | OpenTelemetry exporter using HTTP protocol (over TLS) | http+otlp://localhost:4318/v1/traces | N/A |
48-
| grpc(s) | otlp | OpenTelemetry exporter using gRPC protocol (over TLS) | grpc+otlp://localhost:4317 | N/A |
49-
| http(s) | zipkin | Zipkin exporter using HTTP protocol (over TLS) | http+zipkin://localhost:9411/api/v2/spans | N/A |
50-
| empty | in-memory | In-memory exporter for testing purpose | in-memory://default | N/A |
51-
| stream | console | Console exporter for testing purpose using a stream resource | stream+console://default | php://stdout |
45+
| Transport | Exporter | Description | Example | Default |
46+
|-----------|-----------|---------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|--------------|
47+
| http(s) | otlp | OpenTelemetry exporter using HTTP protocol (over TLS) | http+otlp://localhost:4318/v1/traces | N/A |
48+
| grpc(s) | otlp | OpenTelemetry exporter using gRPC protocol (over TLS) | grpc+otlp://localhost:4317 | N/A |
49+
| kafka | otlp | OpenTelemetry exporter using the Kafka message broker. Add query parameters for configuring the message broker. | kafka+otlp://open_telemetry_local_alpha_traces?metadata.broker.list=kafka:9092 | N/A |
50+
| http(s) | zipkin | Zipkin exporter using HTTP protocol (over TLS) | http+zipkin://localhost:9411/api/v2/spans | N/A |
51+
| empty | in-memory | In-memory exporter for testing purpose | in-memory://default | N/A |
52+
| stream | console | Console exporter for testing purpose using a stream resource | stream+console://default | php://stdout |
5253

5354
Note: The `stream+console` DSN is the only DSN than can refer to a stream resource using the `path` block. For example: `stream+console://default/file.log`.
5455

src/OpenTelemetry/Exporter/ConsoleExporterEndpoint.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,9 @@ public function getExporter(): string
3030
{
3131
return $this->dsn->getExporter();
3232
}
33+
34+
public function getDsn(): ExporterDsn
35+
{
36+
return $this->dsn;
37+
}
3338
}

src/OpenTelemetry/Exporter/ExporterDsn.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Zenstruck\Dsn;
66
use Zenstruck\Uri;
7+
use Zenstruck\Uri\Part\Query;
78

89
final class ExporterDsn
910
{
@@ -60,6 +61,11 @@ public function getPort(?int $default = null): ?int
6061
return $this->uri->port() ?? $default;
6162
}
6263

64+
public function getQuery(): Query
65+
{
66+
return $this->uri->query();
67+
}
68+
6369
/**
6470
* @return string[]
6571
*/

src/OpenTelemetry/Exporter/ExporterEndpointInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ public function getExporter(): string;
99
public function getTransport(): ?string;
1010

1111
public static function fromDsn(ExporterDsn $dsn): self;
12+
13+
public function getDsn(): ExporterDsn;
1214
}

src/OpenTelemetry/Exporter/OtlpExporterEndpoint.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public function withSignal(string $signal): self
4242

4343
public function __toString()
4444
{
45+
if (TransportEnum::Kafka === $this->transport) {
46+
return \sprintf('kafka://%s?%s', $this->dsn->getHost(), $this->dsn->getQuery()->toString());
47+
}
48+
4549
$uri = $this->uriFactory->createUri();
4650
$uri = $uri
4751
->withScheme($this->transport->getScheme())
@@ -78,4 +82,9 @@ public function getExporter(): string
7882
{
7983
return 'otlp';
8084
}
85+
86+
public function getDsn(): ExporterDsn
87+
{
88+
return $this->dsn;
89+
}
8190
}

src/OpenTelemetry/Log/LogExporterEndpoint.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,9 @@ public function getExporter(): string
5050
{
5151
return $this->exporter->value;
5252
}
53+
54+
public function getDsn(): ExporterDsn
55+
{
56+
return $this->dsn;
57+
}
5358
}

src/OpenTelemetry/Metric/MetricExporterEndpoint.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ public function getExporter(): string
4848
{
4949
return $this->exporter->value;
5050
}
51+
52+
public function getDsn(): ExporterDsn
53+
{
54+
return $this->dsn;
55+
}
5156
}

src/OpenTelemetry/Trace/TraceExporterEndpoint.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,9 @@ public function getTransport(): ?string
5252
{
5353
return $this->transport?->value;
5454
}
55+
56+
public function getDsn(): ExporterDsn
57+
{
58+
return $this->dsn;
59+
}
5560
}

src/OpenTelemetry/Trace/ZipkinExporterEndpoint.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,9 @@ public function getExporter(): string
5353
{
5454
return 'zipkin';
5555
}
56+
57+
public function getDsn(): ExporterDsn
58+
{
59+
return $this->dsn;
60+
}
5661
}

0 commit comments

Comments
 (0)