From 1e05b69bbb636d76cab2f34a5238a516391f4074 Mon Sep 17 00:00:00 2001 From: "Gabriele N. Tornetta" Date: Thu, 14 Nov 2024 10:46:33 +0000 Subject: [PATCH] chore(symdb): upload compressed symbol payloads We add support for compressed symbol database payloads. --- ddtrace/internal/symbol_db/symbols.py | 8 +++++--- ddtrace/internal/utils/http.py | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ddtrace/internal/symbol_db/symbols.py b/ddtrace/internal/symbol_db/symbols.py index e252e22c0bf..2f1c7607ba9 100644 --- a/ddtrace/internal/symbol_db/symbols.py +++ b/ddtrace/internal/symbol_db/symbols.py @@ -3,6 +3,7 @@ from dataclasses import field import dis from enum import Enum +import gzip from http.client import HTTPResponse from inspect import CO_VARARGS from inspect import CO_VARKEYWORDS @@ -484,9 +485,10 @@ def upload(self) -> HTTPResponse: ), FormData( name="file", - filename="symdb_export.json", - data=json.dumps(self.to_json()), + filename="symdb_export.gz", + data=gzip.compress(json.dumps(self.to_json()).encode()), content_type="json", + content_encoding="gzip", ), ] ) @@ -527,7 +529,7 @@ def is_module_included(module: ModuleType) -> bool: class SymbolDatabaseUploader(BaseModuleWatchdog): - __scope_limit__ = 100 + __scope_limit__ = 400 def __init__(self) -> None: super().__init__() diff --git a/ddtrace/internal/utils/http.py b/ddtrace/internal/utils/http.py index cba605a1527..7c55abab169 100644 --- a/ddtrace/internal/utils/http.py +++ b/ddtrace/internal/utils/http.py @@ -418,8 +418,9 @@ def parse_message(msg): class FormData: name: str filename: str - data: str + data: Union[str, bytes] content_type: str + content_encoding: Optional[str] = None def multipart(parts: List[FormData]) -> Tuple[bytes, dict]: @@ -433,6 +434,8 @@ def multipart(parts: List[FormData]) -> Tuple[bytes, dict]: for part in parts: app = MIMEApplication(part.data, part.content_type, lambda _: _) app.add_header("Content-Disposition", "form-data", name=part.name, filename=part.filename) + if part.content_encoding: + app.add_header("Content-Encoding", part.content_encoding) del app["MIME-Version"] msg.attach(app)