Skip to content

Commit b78f5bb

Browse files
dougqhclaude
andcommitted
Treat a custom tag's zero id as unslotted
hasSlot(0L) decoded slot 0, so the id keyOf gives a custom tag looked like the known tag in slot 0. It now returns false for 0L. The slot-count test also allows the full 63 slots the generator permits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 3a309ee commit b78f5bb

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎internal-api/src/main/java/datadog/trace/api/KnownTagCodec.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,12 @@ public static int slotOf(long tagId) {
8181
return (int) (tagId >>> SLOT_SHIFT) & 0xFFFF;
8282
}
8383

84-
/** True if the tag has a slot, below {@link #slotCount()}. */
84+
/**
85+
* True if the tag has a slot, below {@link #slotCount()}. False for {@code 0L}, the id {@link
86+
* #keyOf} gives a custom tag, which would otherwise decode as slot 0.
87+
*/
8588
public static boolean hasSlot(long tagId) {
86-
return slotOf(tagId) != NO_SLOT;
89+
return tagId != 0L && slotOf(tagId) != NO_SLOT;
8790
}
8891

8992
/** Slots in use: every slotted tag's slot is below this. */

‎internal-api/src/test/java/datadog/trace/api/KnownTagCodecSlotTest.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,18 @@ void theSlotDoesNotChangeTheSerialOrFlags() {
6767
assertFalse(KnownTagCodec.isTraceLevel(tagId));
6868
}
6969

70+
@Test
71+
void aCustomTagHasNoSlot() {
72+
// keyOf gives a custom tag the id 0L, whose slot bits decode as slot 0
73+
assertEquals(0L, KnownTagCodec.keyOf("my.custom.tag"));
74+
assertFalse(KnownTagCodec.hasSlot(0L));
75+
}
76+
7077
@Test
7178
void anUnslottedTagSharesTheReservedTopBit() {
7279
// An occupancy bit of 1L << slotOf(id) needs no branch for NO_SLOT: a long shift uses only the
7380
// low 6 bits of its count, so 0xFFFF lands on bit 63, which no real slot uses
7481
assertEquals(1L << 63, 1L << KnownTagCodec.slotOf(KnownTags.RESOURCE_NAME_ID));
75-
assertTrue(KnownTagCodec.slotCount() < 63, "real slots must stay below the shared bit 63");
82+
assertTrue(KnownTagCodec.slotCount() <= 63, "real slots must stay below the shared bit 63");
7683
}
7784
}

0 commit comments

Comments
 (0)