Skip to content

Commit

Permalink
add sentry integration
Browse files Browse the repository at this point in the history
  • Loading branch information
rasoro committed Nov 14, 2023
1 parent c04d873 commit fd37de1
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ def __init__(self):
"HUGGINGFACE_API_TOKEN", "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"
),
}
self.sentry_dsn = os.environ.get("SENTRY_DSN", "")
5 changes: 0 additions & 5 deletions app/handlers/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def index(self, request: ProductIndexRequest):
docs = self.product_indexer.index(request.catalog_id, request.product)
return ProductIndexResponse(catalog_id=request.catalog_id, documents=docs)
except Exception as e:
logger.error(msg=str(e))
raise HTTPException(status_code=500, detail=[{"msg": str(e)}])

def batch_index(self, request: ProductBatchIndexRequest):
Expand All @@ -91,7 +90,6 @@ def batch_index(self, request: ProductBatchIndexRequest):
)
return ProductIndexResponse(catalog_id=request.catalog_id, documents=docs)
except Exception as e:
logger.error(msg=str(e))
raise HTTPException(status_code=500, detail=[{"msg": str(e)}])

def search(self, request: ProductSearchRequest):
Expand All @@ -101,7 +99,6 @@ def search(self, request: ProductSearchRequest):
)
return ProductSearchResponse(products=matched_products)
except Exception as e:
logger.error(msg=str(e))
raise HTTPException(status_code=500, detail=[{"msg": str(e)}])

def delete(
Expand All @@ -117,7 +114,6 @@ def delete(
docs = self.product_indexer.delete(catalog_id, product_retailer_id)
return ProductIndexResponse(catalog_id=catalog_id, documents=docs)
except Exception as e:
logger.error(msg=str(e))
raise HTTPException(status_code=500, detail=[{"msg": str(e)}])

def delete_batch(self, request: ProductDeleteRequest):
Expand All @@ -127,5 +123,4 @@ def delete_batch(self, request: ProductDeleteRequest):
)
return ProductIndexResponse(catalog_id=request.catalog_id, documents=docs)
except Exception as e:
logger.error(msg=str(e))
raise HTTPException(status_code=500, detail=[{"msg": str(e)}])
6 changes: 6 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sentry_sdk
from fastapi import FastAPI
from langchain.embeddings import SagemakerEndpointEmbeddings, HuggingFaceHubEmbeddings
from langchain.embeddings.base import Embeddings
Expand Down Expand Up @@ -38,6 +39,11 @@ def __init__(self, config: AppConfig):
content_handler=content_handler,
)

if config.sentry_dsn != "":
sentry_sdk.init(
dsn=config.sentry_dsn,
)

self.api = FastAPI()
self.vectorstore = ElasticVectorSearch(
elasticsearch_url=config.es_url,
Expand Down
50 changes: 48 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ boto3 = "^1.28.41"
fastapi = "^0.103.1"
uvicorn = "^0.23.2"
huggingface-hub = "^0.16.4"
sentry-sdk = {extras = ["fastapi"], version = "^1.35.0"}


[tool.poetry.group.dev.dependencies]
Expand Down

0 comments on commit fd37de1

Please sign in to comment.