Skip to content

Commit adc8f06

Browse files
authoredFeb 6, 2025
Add dev docs on how to add TCP based tracers (#1618)
1 parent 62aad1f commit adc8f06

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
 

‎devdocs/new-tracer.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Add new TCP based BPF tracer
2+
3+
This document the steps required to add a new TCP protocol based BPF tracer to Beyla.
4+
5+
## Investigate the protocol
6+
7+
First, you need to understand the protocol used by the application you want to trace. Beyla captures TCP packets and you need to add the logic to identify the packets that belong to the protocol you want to trace. The are basically two cases:
8+
9+
- The package comes in plain text, like SQL. In this case, you can just search for the SQL keywords in the packets.
10+
- The package comes in binary format, like Kafka. In this case, you need to figure out how to identify the start and end of the packets and where the relevant information is.
11+
12+
13+
## Add the new protocol to the BPF program
14+
15+
In [pkg/internal/ebpf/common/tcp_detect_transform.go](https://github.com/grafana/beyla/blob/main/pkg/internal/ebpf/common/tcp_detect_transform.go) any TCP packet captured from BPF passes through the `ReadTCPRequestIntoSpan` function, and depending what's in the bytes, you can identify if the packet is SQL, Redis, etc. You need to add a new case to this function to identify the new protocol.
16+
17+
Once you have this done (the hard part!), you have to create a new `EventType` in [pkg/internal/request/span.go](https://github.com/grafana/beyla/blob/main/pkg/internal/request/span.go#L4). Look how other `EventTypes` are handled, and you probably need to edit every single file where the data is flowing. For example, to add a new OTEL trace you have to edit `traceAttributes` in [pkg/export/otel/traces.go](https://github.com/grafana/beyla/blob/main/pkg/export/otel/traces.go#L4)
18+
19+
Take a look at this PR for an example of how to add a new Kafka protocol: https://github.com/grafana/beyla/pull/890
20+
21+
## Other considerations
22+
23+
- Add always definitions for Prometheus metrics and OpenTelemetry traces and metrics.
24+
- Look for already defined semantic conventions defined in OpenTelemetry spec for those attributes.
25+
- If there's nothing defined, you can create your own attributes, and if they are useful, propose them to the OpenTelemetry community.
26+
- Add always tests, both unit and OATS integration tests.
27+
- Add always documentation of the newly introduced metrics and traces for this protocol.

0 commit comments

Comments
 (0)