2025-12-01
This commit is contained in:
@@ -57,39 +57,49 @@ class Envelope:
|
||||
)
|
||||
|
||||
def add_event(
|
||||
self, event # type: Event
|
||||
self,
|
||||
event, # type: Event
|
||||
):
|
||||
# type: (...) -> None
|
||||
self.add_item(Item(payload=PayloadRef(json=event), type="event"))
|
||||
|
||||
def add_transaction(
|
||||
self, transaction # type: Event
|
||||
self,
|
||||
transaction, # type: Event
|
||||
):
|
||||
# type: (...) -> None
|
||||
self.add_item(Item(payload=PayloadRef(json=transaction), type="transaction"))
|
||||
|
||||
def add_profile(
|
||||
self, profile # type: Any
|
||||
self,
|
||||
profile, # type: Any
|
||||
):
|
||||
# type: (...) -> None
|
||||
self.add_item(Item(payload=PayloadRef(json=profile), type="profile"))
|
||||
|
||||
def add_profile_chunk(
|
||||
self, profile_chunk # type: Any
|
||||
self,
|
||||
profile_chunk, # type: Any
|
||||
):
|
||||
# type: (...) -> None
|
||||
self.add_item(
|
||||
Item(payload=PayloadRef(json=profile_chunk), type="profile_chunk")
|
||||
Item(
|
||||
payload=PayloadRef(json=profile_chunk),
|
||||
type="profile_chunk",
|
||||
headers={"platform": profile_chunk.get("platform", "python")},
|
||||
)
|
||||
)
|
||||
|
||||
def add_checkin(
|
||||
self, checkin # type: Any
|
||||
self,
|
||||
checkin, # type: Any
|
||||
):
|
||||
# type: (...) -> None
|
||||
self.add_item(Item(payload=PayloadRef(json=checkin), type="check_in"))
|
||||
|
||||
def add_session(
|
||||
self, session # type: Union[Session, Any]
|
||||
self,
|
||||
session, # type: Union[Session, Any]
|
||||
):
|
||||
# type: (...) -> None
|
||||
if isinstance(session, Session):
|
||||
@@ -97,13 +107,15 @@ class Envelope:
|
||||
self.add_item(Item(payload=PayloadRef(json=session), type="session"))
|
||||
|
||||
def add_sessions(
|
||||
self, sessions # type: Any
|
||||
self,
|
||||
sessions, # type: Any
|
||||
):
|
||||
# type: (...) -> None
|
||||
self.add_item(Item(payload=PayloadRef(json=sessions), type="sessions"))
|
||||
|
||||
def add_item(
|
||||
self, item # type: Item
|
||||
self,
|
||||
item, # type: Item
|
||||
):
|
||||
# type: (...) -> None
|
||||
self.items.append(item)
|
||||
@@ -129,7 +141,8 @@ class Envelope:
|
||||
return iter(self.items)
|
||||
|
||||
def serialize_into(
|
||||
self, f # type: Any
|
||||
self,
|
||||
f, # type: Any
|
||||
):
|
||||
# type: (...) -> None
|
||||
f.write(json_dumps(self.headers))
|
||||
@@ -145,7 +158,8 @@ class Envelope:
|
||||
|
||||
@classmethod
|
||||
def deserialize_from(
|
||||
cls, f # type: Any
|
||||
cls,
|
||||
f, # type: Any
|
||||
):
|
||||
# type: (...) -> Envelope
|
||||
headers = parse_json(f.readline())
|
||||
@@ -159,7 +173,8 @@ class Envelope:
|
||||
|
||||
@classmethod
|
||||
def deserialize(
|
||||
cls, bytes # type: bytes
|
||||
cls,
|
||||
bytes, # type: bytes
|
||||
):
|
||||
# type: (...) -> Envelope
|
||||
return cls.deserialize_from(io.BytesIO(bytes))
|
||||
@@ -268,14 +283,16 @@ class Item:
|
||||
return "transaction"
|
||||
elif ty == "event":
|
||||
return "error"
|
||||
elif ty == "log":
|
||||
return "log_item"
|
||||
elif ty == "trace_metric":
|
||||
return "trace_metric"
|
||||
elif ty == "client_report":
|
||||
return "internal"
|
||||
elif ty == "profile":
|
||||
return "profile"
|
||||
elif ty == "profile_chunk":
|
||||
return "profile_chunk"
|
||||
elif ty == "statsd":
|
||||
return "metric_bucket"
|
||||
elif ty == "check_in":
|
||||
return "monitor"
|
||||
else:
|
||||
@@ -301,7 +318,8 @@ class Item:
|
||||
return None
|
||||
|
||||
def serialize_into(
|
||||
self, f # type: Any
|
||||
self,
|
||||
f, # type: Any
|
||||
):
|
||||
# type: (...) -> None
|
||||
headers = dict(self.headers)
|
||||
@@ -320,7 +338,8 @@ class Item:
|
||||
|
||||
@classmethod
|
||||
def deserialize_from(
|
||||
cls, f # type: Any
|
||||
cls,
|
||||
f, # type: Any
|
||||
):
|
||||
# type: (...) -> Optional[Item]
|
||||
line = f.readline().rstrip()
|
||||
@@ -335,7 +354,7 @@ class Item:
|
||||
# if no length was specified we need to read up to the end of line
|
||||
# and remove it (if it is present, i.e. not the very last char in an eof terminated envelope)
|
||||
payload = f.readline().rstrip(b"\n")
|
||||
if headers.get("type") in ("event", "transaction", "metric_buckets"):
|
||||
if headers.get("type") in ("event", "transaction"):
|
||||
rv = cls(headers=headers, payload=PayloadRef(json=parse_json(payload)))
|
||||
else:
|
||||
rv = cls(headers=headers, payload=payload)
|
||||
@@ -343,7 +362,8 @@ class Item:
|
||||
|
||||
@classmethod
|
||||
def deserialize(
|
||||
cls, bytes # type: bytes
|
||||
cls,
|
||||
bytes, # type: bytes
|
||||
):
|
||||
# type: (...) -> Optional[Item]
|
||||
return cls.deserialize_from(io.BytesIO(bytes))
|
||||
|
||||
Reference in New Issue
Block a user