Collection of functions to convert to protobuf version of types.
We do not use the protobuf types throughout the project as they do not autocomplete or
have type definitions that work in IDE. It also makes it easier to deal with agent functionality by
having local types we can modify.
convert_snapshot(snapshot)
Convert a snapshot from internal model to protobuf model.
:param (EventSnapshot) snapshot: the internal snapshot model
:return (Snapshot): the protobuf model of the snapshot
Source code in deep/push/__init__.py
| def convert_snapshot(snapshot: EventSnapshot) -> Snapshot:
"""
Convert a snapshot from internal model to protobuf model.
:param (EventSnapshot) snapshot: the internal snapshot model
:return (Snapshot): the protobuf model of the snapshot
"""
try:
return Snapshot(ID=snapshot.id.to_bytes(16, "big"), tracepoint=__convert_tracepoint(snapshot.tracepoint),
var_lookup=__convert_lookup(snapshot.var_lookup),
ts_nanos=snapshot.ts_nanos, frames=[__convert_frame(f) for f in snapshot.frames],
watches=[__convert_watch(w) for w in snapshot.watches],
attributes=[KeyValue(key=k, value=convert_value(v)) for k, v in snapshot.attributes.items()],
duration_nanos=snapshot.duration_nanos,
resource=[KeyValue(key=k, value=convert_value(v)) for k, v in
snapshot.resource.attributes.items()],
log_msg=snapshot.log_msg)
except Exception:
# todo should this return None?
logging.exception("Error converting to protobuf")
return None
|