-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "ref(rust): Remove Python processors in favor of Rust ones (#5327
)" This reverts commit 98b9810. Co-authored-by: phacops <336345+phacops@users.noreply.github.com>
- Loading branch information
1 parent
e3bf2f3
commit dd479de
Showing
17 changed files
with
735 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,72 @@ | ||
from snuba.datasets.processors.rust_compat_processor import RustCompatProcessor | ||
import uuid | ||
from datetime import datetime | ||
from typing import Any, Mapping, Optional | ||
|
||
from sentry_relay.consts import SPAN_STATUS_NAME_TO_CODE | ||
|
||
class FunctionsMessageProcessor(RustCompatProcessor): | ||
def __init__(self) -> None: | ||
super().__init__("FunctionsMessageProcessor") | ||
from snuba import environment | ||
from snuba.consumers.types import KafkaMessageMetadata | ||
from snuba.datasets.processors import DatasetMessageProcessor | ||
from snuba.processor import InsertBatch, ProcessedMessage | ||
from snuba.utils.metrics.wrapper import MetricsWrapper | ||
|
||
metrics = MetricsWrapper(environment.metrics, "functions.processor") | ||
|
||
UNKNOWN_SPAN_STATUS = 2 | ||
MAX_DEPTH = 1024 | ||
|
||
|
||
class FunctionsMessageProcessor(DatasetMessageProcessor): | ||
def process_message( | ||
self, message: Mapping[str, Any], metadata: KafkaMessageMetadata | ||
) -> Optional[ProcessedMessage]: | ||
status = message.get("transaction_status") | ||
if status: | ||
int_status = SPAN_STATUS_NAME_TO_CODE.get( | ||
status, | ||
UNKNOWN_SPAN_STATUS, | ||
) | ||
else: | ||
int_status = UNKNOWN_SPAN_STATUS | ||
functions_list = [ | ||
{ | ||
"project_id": message["project_id"], | ||
"transaction_name": message["transaction_name"], | ||
"timestamp": int( | ||
message.get("timestamp", datetime.utcnow().timestamp()) | ||
), | ||
"depth": 0, # deprecated | ||
"parent_fingerprint": 0, # deprecated | ||
"fingerprint": function["fingerprint"], | ||
"name": function["function"], # to be removed | ||
"function": function["function"], | ||
"package": function.get("package", ""), | ||
"module": function.get("module", ""), | ||
"path": "", # deprecated | ||
"is_application": 1 if function.get("in_app", True) else 0, | ||
"platform": message["platform"], | ||
"environment": message.get("environment"), | ||
"release": message.get("release"), | ||
"dist": message.get("dist"), | ||
"transaction_op": message.get("transaction_op", ""), | ||
"transaction_status": int_status, | ||
"http_method": message.get("http_method"), | ||
"browser_name": message.get("browser_name"), | ||
"device_classification": message.get("device_class", 0), | ||
"os_name": "", # deprecated | ||
"os_version": "", # deprecated | ||
"retention_days": message["retention_days"], | ||
"durations": function["self_times_ns"], | ||
"profile_id": str(uuid.UUID(message["profile_id"])), | ||
"materialization_version": 0, | ||
} | ||
for function in message["functions"] | ||
if function.get("function") and function.get("self_times_ns") | ||
] | ||
|
||
received = message.get("received") | ||
|
||
return InsertBatch( | ||
functions_list, | ||
datetime.utcfromtimestamp(received) if received else None, | ||
) |
Oops, something went wrong.