From 4b0da35c6dade9dbf074ca4d858590dd985084b6 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Wed, 14 Sep 2022 15:23:40 +0100 Subject: [PATCH] feat(chalice): sourcemaps reader refactoring --- api/app.py | 5 ++++- api/chalicelib/core/sourcemaps.py | 3 +++ api/chalicelib/core/sourcemaps_parser.py | 9 +++++---- api/chalicelib/utils/s3.py | 5 +---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/api/app.py b/api/app.py index cf00c747b..974d7d8d9 100644 --- a/api/app.py +++ b/api/app.py @@ -17,6 +17,7 @@ from routers.subs import dashboard, insights, metrics, v1_api app = FastAPI(root_path="/api", docs_url=config("docs_url", default=""), redoc_url=config("redoc_url", default="")) app.add_middleware(GZipMiddleware, minimum_size=1000) + @app.middleware('http') async def or_middleware(request: Request, call_next): global OR_SESSION_TOKEN @@ -28,7 +29,9 @@ async def or_middleware(request: Request, call_next): now = int(time.time() * 1000) response: StreamingResponse = await call_next(request) if helper.TRACK_TIME: - print(f"Execution time: {int(time.time() * 1000) - now} ms") + now = int(time.time() * 1000) - now + if now > 500: + print(f"Execution time: {now} ms") except Exception as e: pg_client.close() raise e diff --git a/api/chalicelib/core/sourcemaps.py b/api/chalicelib/core/sourcemaps.py index 4bd0606b7..8714b9ee2 100644 --- a/api/chalicelib/core/sourcemaps.py +++ b/api/chalicelib/core/sourcemaps.py @@ -99,6 +99,9 @@ def get_traces_group(project_id, payload): if payloads[key] is None: continue key_results = sourcemaps_parser.get_original_trace(key=key, positions=[o["position"] for o in payloads[key]]) + if key_results is None: + all_exists = False + continue for i, r in enumerate(key_results): res_index = payloads[key][i]["resultIndex"] # function name search by frontend lib is better than sourcemaps' one in most cases diff --git a/api/chalicelib/core/sourcemaps_parser.py b/api/chalicelib/core/sourcemaps_parser.py index 018441ae6..4cc6ae1df 100644 --- a/api/chalicelib/core/sourcemaps_parser.py +++ b/api/chalicelib/core/sourcemaps_parser.py @@ -19,11 +19,12 @@ def get_original_trace(key, positions): r = requests.post(config("sourcemaps_reader"), json=payload, timeout=config("sourcemapTimeout", cast=int, default=5)) if r.status_code != 200: - return {} + print(f"Issue getting sourcemap status_code:{r.status_code}") + return None return r.json() except requests.exceptions.Timeout: print("Timeout getting sourcemap") - return {} + return None except Exception as e: - print("issue getting sourcemap") - return {} + print("Issue getting sourcemap") + return None diff --git a/api/chalicelib/utils/s3.py b/api/chalicelib/utils/s3.py index efcb09226..f3c580e90 100644 --- a/api/chalicelib/utils/s3.py +++ b/api/chalicelib/utils/s3.py @@ -63,9 +63,6 @@ def get_presigned_url_for_upload(bucket, expires_in, key): def get_file(source_bucket, source_key): - print("******************************") - print(f"looking for: {source_key} in {source_bucket}") - print("******************************") try: result = client.get_object( Bucket=source_bucket, @@ -73,7 +70,7 @@ def get_file(source_bucket, source_key): ) except ClientError as ex: if ex.response['Error']['Code'] == 'NoSuchKey': - print(f'======> No object found - returning None for {source_bucket}/{source_key}') + print(f'======> No object found - returning None for \nbucket:{source_bucket}\nkey:{source_key}') return None else: raise ex