Skip to content
This repository has been archived by the owner on Sep 4, 2022. It is now read-only.

Commit

Permalink
Merge pull request #110 from cisco-open/fix/aiohttp-decode
Browse files Browse the repository at this point in the history
fix(aiohttp): fixed decode error
  • Loading branch information
osherv authored Jul 24, 2022
2 parents c719db0 + 1650be6 commit c7c76c7
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 396 deletions.
16 changes: 12 additions & 4 deletions cisco_telescope/instrumentations/aiohttp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
limitations under the License.
"""
import asyncio
import logging
import types
from collections import deque

Expand Down Expand Up @@ -176,17 +177,24 @@ async def on_request_chunk_sent(
params: aiohttp.TraceRequestChunkSentParams,
):
if getattr(params, "chunk"):
decoded_chunk = params.chunk.decode()
trace_config_ctx.request_body += decoded_chunk
trace_config_ctx.request_body += _decode_chunk(params.chunk)

async def on_responde_chunk_received(
unused_session: aiohttp.ClientSession,
trace_config_ctx: types.SimpleNamespace,
params: aiohttp.TraceRequestChunkSentParams,
):
if getattr(params, "chunk"):
decoded_chunk = params.chunk.decode()
trace_config_ctx.response_body += decoded_chunk
trace_config_ctx.response_body += _decode_chunk(params.chunk)

def _decode_chunk(chunk):
try:
decoded_chunk = chunk.decode()
except UnicodeDecodeError as e:
decoded_chunk = str(chunk)
logging.info(f"Could not decode body chunk: {decoded_chunk}, {e}")

return decoded_chunk

def _trace_config_ctx_factory(**kwargs):
kwargs.setdefault("trace_request_ctx", {})
Expand Down
Loading

0 comments on commit c7c76c7

Please sign in to comment.