Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ pymongo==3.11.0
redispy==3.0.0
sqlalchemy==1.3.20
moto==1.3.16

13 changes: 13 additions & 0 deletions src/lumigo_tracer/lumigo_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import decimal
import base64
import hashlib
import json
import logging
Expand Down Expand Up @@ -61,6 +62,7 @@
LUMIGO_SECRET_MASKING_REGEX_BACKWARD_COMP = "LUMIGO_BLACKLIST_REGEX"
LUMIGO_SECRET_MASKING_REGEX = "LUMIGO_SECRET_MASKING_REGEX"
WARN_CLIENT_PREFIX = "Lumigo Warning"
INTERNAL_ANALYTICS_PREFIX = "Lumigo Analytic Log"
TRUNCATE_SUFFIX = "...[too long]"
NUMBER_OF_SPANS_IN_REPORT_OPTIMIZATION = 200
DEFAULT_KEY_DEPTH = 4
Expand All @@ -76,6 +78,7 @@

edge_kinesis_boto_client = None
edge_connection = None
internal_error_already_logged = False


def get_region() -> str:
Expand Down Expand Up @@ -330,6 +333,7 @@ def report_json(region: Optional[str], msgs: List[dict], should_retry: bool = Tr
report_json(region, msgs, should_retry=False)
else:
get_logger().exception("Could not report: A span was lost.", exc_info=e)
internal_analytics_message(f"report: {type(e)}")
return duration


Expand Down Expand Up @@ -503,6 +507,15 @@ def warn_client(msg: str) -> None:
print(f"{WARN_CLIENT_PREFIX}: {msg}")


def internal_analytics_message(msg: str, force: bool = False) -> None:
global internal_error_already_logged
if os.environ.get("LUMIGO_ANALYTICS") != "off":
if force or not internal_error_already_logged:
b64_message = base64.b64encode(msg.encode()).decode()
print(f"{INTERNAL_ANALYTICS_PREFIX}: {b64_message}")
internal_error_already_logged = True


def is_api_gw_event(event: dict) -> bool:
return bool(
isinstance(event, Dict)
Expand Down
9 changes: 9 additions & 0 deletions src/test/unit/test_lumigo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
get_size_upper_bound,
is_aws_arn,
CHINA_REGION,
internal_analytics_message,
INTERNAL_ANALYTICS_PREFIX,
)
import json

Expand Down Expand Up @@ -574,3 +576,10 @@ def test_is_error_code(status_code, is_error):
)
def test_is_aws_arn(arn, is_arn_result):
assert is_aws_arn(arn) is is_arn_result


def test_internal_analytics_message(capsys):
internal_analytics_message("Message", force=True)
assert capsys.readouterr().out.startswith(INTERNAL_ANALYTICS_PREFIX)
internal_analytics_message("Message")
assert capsys.readouterr().out == ""