Skip to content

Commit 6668a76

Browse files
committed
log_data needs to be cleared inside async function
1 parent 64ba980 commit 6668a76

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fastapi_elasticsearch_middleware/elasticsearch_middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ async def intercept_send(response):
7474
log_data["response"]["body"] = str(response.get('body')) if 'body' in response.keys() else None
7575

7676
self.log_to_elasticsearch(log_data)
77+
log_data.clear()
7778

7879
if response['type'] == 'http.response.start': # Request part
7980

@@ -134,7 +135,6 @@ async def intercept_receive():
134135
def log_to_elasticsearch(self, log_data) -> None:
135136
try:
136137
self.elasticsearch_client.index(index=self.index, body=log_data)
137-
log_data["response"] = {}
138138
except Exception as e:
139139
logging.error(f"Failed to log to Elasticsearch: {str(e)}")
140140

0 commit comments

Comments
 (0)