|
19 | 19 |
|
20 | 20 |
|
21 | 21 | def otel_attributes_to_dict(otel_attrs): |
22 | | - # type: (List[Mapping[str, Any]]) -> Mapping[str, Any] |
| 22 | + # type: (Mapping[str, Any]) -> Mapping[str, Any] |
23 | 23 | def _convert_attr(attr): |
24 | 24 | # type: (Mapping[str, Union[str, float, bool]]) -> Any |
25 | | - if "boolValue" in attr: |
26 | | - return bool(attr["boolValue"]) |
27 | | - if "doubleValue" in attr: |
28 | | - return float(attr["doubleValue"]) |
29 | | - if "intValue" in attr: |
30 | | - return int(attr["intValue"]) |
31 | | - if attr["stringValue"].startswith("{"): |
| 25 | + if attr["type"] == "boolean": |
| 26 | + return bool(attr["value"]) |
| 27 | + if attr["type"] == "double": |
| 28 | + return float(attr["value"]) |
| 29 | + if attr["type"] == "integer": |
| 30 | + return int(attr["value"]) |
| 31 | + if attr["value"].startswith("{"): |
32 | 32 | try: |
33 | 33 | return json.loads(attr["stringValue"]) |
34 | 34 | except ValueError: |
35 | 35 | pass |
36 | | - return str(attr["stringValue"]) |
| 36 | + return str(attr["value"]) |
37 | 37 |
|
38 | | - return {item["key"]: _convert_attr(item["value"]) for item in otel_attrs} |
| 38 | + return {k: _convert_attr(v) for (k, v) in otel_attrs.items()} |
39 | 39 |
|
40 | 40 |
|
41 | 41 | def envelopes_to_logs(envelopes: List[Envelope]) -> List[Log]: |
42 | 42 | res = [] # type: List[Log] |
43 | 43 | for envelope in envelopes: |
44 | 44 | for item in envelope.items: |
45 | | - if item.type == "otel_log": |
46 | | - log_json = item.payload.json |
47 | | - log = { |
48 | | - "severity_text": log_json["severityText"], |
49 | | - "severity_number": log_json["severityNumber"], |
50 | | - "body": log_json["body"]["stringValue"], |
51 | | - "attributes": otel_attributes_to_dict(log_json["attributes"]), |
52 | | - "time_unix_nano": int(log_json["timeUnixNano"]), |
53 | | - "trace_id": None, |
54 | | - } # type: Log |
55 | | - if "traceId" in log_json: |
56 | | - log["trace_id"] = log_json["traceId"] |
57 | | - res.append(log) |
| 45 | + if item.type == "log": |
| 46 | + for log_json in item.payload.json["items"]: |
| 47 | + log = { |
| 48 | + "severity_text": log_json["attributes"]["sentry.severity_text"][ |
| 49 | + "value" |
| 50 | + ], |
| 51 | + "severity_number": int( |
| 52 | + log_json["attributes"]["sentry.severity_number"]["value"] |
| 53 | + ), |
| 54 | + "body": log_json["body"], |
| 55 | + "attributes": otel_attributes_to_dict(log_json["attributes"]), |
| 56 | + "time_unix_nano": int(float(log_json["timestamp"]) * 1e9), |
| 57 | + "trace_id": log_json["trace_id"], |
| 58 | + } # type: Log |
| 59 | + res.append(log) |
58 | 60 | return res |
59 | 61 |
|
60 | 62 |
|
|
0 commit comments