if message.trace:
print("- Event Trace:")
for event in message.trace:
- ev = self.getEventAsString(event.event) + '(' + str(event.ts)
+ ev = self.getEventAsString(event.event)
+ if event.event == dnsmessage_pb2.PBDNSMessage.CustomEvent and event.HasField('custom'):
+ ev += ":" + event.custom
+ ev += '(' + str(event.ts)
valstr = ''
if event.HasField('boolVal'):
valstr = str(event.boolVal)
// The well known EventTrace event numbers
enum EventType {
+ CustomEvent = 0; // A custom event
RecRecv = 1; // A request was received by the recursor process
PCacheCheck = 2; // A packet cache check was initiated or completed; value: bool cacheHit
SyncRes = 3; // Syncres main function has started or completed; value: int rcode
optional int64 intVal = 5;
optional string stringVal = 6;
optional bytes bytesVal = 7;
+ optional string custom = 8; // The name of the event for custom events
}
repeated Event trace = 23;
}
enum class MetaValueField : protozero::pbf_tag_type { stringVal = 1, intVal = 2 };
enum class MetaField : protozero::pbf_tag_type { key = 1, value = 2 };
- enum class Event : protozero::pbf_tag_type { ts = 1, event = 2, start = 3, boolVal = 4, intVal = 5, stringVal = 6, bytesVal = 7 };
+ enum class Event : protozero::pbf_tag_type { ts = 1, event = 2, start = 3, boolVal = 4, intVal = 5, stringVal = 6, bytesVal = 7, custom = 8 };
enum class MessageType : int32_t { DNSQueryType = 1, DNSResponseType = 2, DNSOutgoingQueryType = 3, DNSIncomingResponseType = 4 };
enum class Field : protozero::pbf_tag_type { type = 1, messageId = 2, serverIdentity = 3, socketFamily = 4, socketProtocol = 5, from = 6, to = 7, inBytes = 8, timeSec = 9, timeUsec = 10, id = 11, question = 12, response = 13, originalRequestorSubnet = 14, requestorId = 15, initialRequestId = 16, deviceId = 17, newlyObservedDomain = 18, deviceName = 19, fromPort = 20, toPort = 21, meta = 22, trace = 23 };
enum class QuestionField : protozero::pbf_tag_type { qName = 1, qType = 2, qClass = 3 };
}
const std::unordered_map<RecEventTrace::EventType, std::string> RecEventTrace::s_eventNames = {
+ NameEntry(CustomEvent),
NameEntry(RecRecv),
NameEntry(PCacheCheck),
NameEntry(SyncRes),
enum EventType : uint8_t
{
// Don't forget to add a new entry to the table in the .cc file!
+ CustomEvent = 0,
RecRecv = 1,
PCacheCheck = 2,
SyncRes = 3,
d_value(v), d_ts(ts), d_event(e), d_start(start)
{
}
+ Entry(Value_t& v, const std::string& custom, bool start, int64_t ts) :
+ d_value(v), d_custom(custom), d_ts(ts), d_event(CustomEvent), d_start(start)
+ {
+ }
Value_t d_value;
+ std::string d_custom;
int64_t d_ts;
EventType d_event;
bool d_start;
if (!v.empty()) {
v = "," + v;
}
- return RecEventTrace::toString(d_event) + "(" + std::to_string(d_ts) + v + (d_start ? ")" : ",done)");
+ std::string name = RecEventTrace::toString(d_event);
+ if (d_event == EventType::CustomEvent) {
+ name += ":" + d_custom;
+ }
+
+ return name + "(" + std::to_string(d_ts) + v + (d_start ? ")" : ",done)");
}
};
return d_status == Enabled;
}
- void add(EventType e, Value_t v, bool start)
+ template <class E>
+ void add(E e, Value_t v, bool start)
{
assert(d_status != Invalid);
if (d_status == Disabled) {
d_events.emplace_back(v, e, start, stamp);
}
- void add(EventType e)
+ template <class E>
+ void add(E e)
{
add(e, Value_t(std::nullopt), true);
}
// We store uint32 in an int64_t
- void add(EventType e, uint32_t v, bool start)
+ template <class E>
+ void add(E e, uint32_t v, bool start)
{
add(e, static_cast<int64_t>(v), start);
}
// We store int32 in an int64_t
- void add(EventType e, int32_t v, bool start)
+ template <class E>
+ void add(E e, int32_t v, bool start)
{
add(e, static_cast<int64_t>(v), start);
}
- template <class T>
- void add(EventType e, T v, bool start)
+ template <class E, class T>
+ void add(E e, T v, bool start)
{
add(e, Value_t(v), start);
}
const PacketBuffer& p = std::get<PacketBuffer>(v);
pbf_trace.add_bytes(static_cast<protozero::pbf_tag_type>(Event::bytesVal), reinterpret_cast<const char*>(p.data()), p.size());
}
+ if (!t.d_custom.empty()) {
+ pbf_trace.add_string(static_cast<protozero::pbf_tag_type>(Event::custom), t.d_custom);
+ }
}
}