Skip to content

Commit 2842d7c

Browse files
authored
Fix: use add_trace_field() over add_context() for tracer (#21)
This way all events are marked with the command they operate under, instead of only the root event. This makes sampling a lot easier, as we know the command we are doing it for.
1 parent b51fee5 commit 2842d7c

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

openttd_protocol/tracer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def wrapper(func):
1010

1111
tracer = beeline.tracer
1212
untraced = beeline.untraced
13-
add_context = beeline.add_context
13+
add_trace_field = beeline.add_trace_field
1414

1515
except ImportError:
1616
# Honeycomb Beeline package is not installed. Mock the tracer functions.
@@ -34,5 +34,5 @@ def __exit__(self, type, value, traceback):
3434
def untraced(func):
3535
return func
3636

37-
def add_context(payload):
37+
def add_trace_field(key, value):
3838
pass

openttd_protocol/wire/tcp.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ async def _process_queue(self):
181181
log.info("Dropping invalid packet from %s:%d: %r", self.source.ip, self.source.port, err)
182182
raise SocketClosed
183183

184-
tracer.add_context({"command": f"receive.{packet_type.name}"})
185-
186184
with tracer.tracer("tcp.packet-handler"):
187185
await getattr(self._callback, f"receive_{packet_type.name}")(self.source, **kwargs)
188186

@@ -194,19 +192,21 @@ def receive_packet(self, source, data):
194192
raise PacketInvalidSize(len(data) + 2, length)
195193

196194
# Check if type is in range
197-
type, data = read_uint8(data)
198-
if type >= self.PACKET_END:
199-
raise PacketInvalidType(type)
195+
packet_type, data = read_uint8(data)
196+
if packet_type >= self.PACKET_END:
197+
raise PacketInvalidType(packet_type)
200198

201199
# Check if we expect this packet
202-
type = self.PacketType(type)
203-
func = getattr(self, f"receive_{type.name}", None)
200+
packet_type = self.PacketType(packet_type)
201+
func = getattr(self, f"receive_{packet_type.name}", None)
204202
if func is None:
205-
raise PacketInvalidType(type)
203+
raise PacketInvalidType(packet_type)
204+
205+
tracer.add_trace_field("command", f"receive.{packet_type.name}")
206206

207207
# Process this packet
208208
kwargs = func(source, data)
209-
return type, kwargs
209+
return packet_type, kwargs
210210

211211
@tracer.traced("tcp")
212212
async def send_packet(self, data):

0 commit comments

Comments
 (0)