Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

trace simple websocket messages - python

Aperta
#439 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
32/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Riproduci il fallimento della connessione da websocket.py, in particolare echo e le chiamate a begin_segment/begin_subsegment mostrate nell’issue. Leggi aws_xray_sdk.core.async_context.AsyncContext e i metodi di contesto del recorder relativi a current_segment e get_trace_entity. Il lavoro è completato quando un client può scambiare messaggi websocket senza SegmentNotFoundException e i messaggi vengono tracciati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Hello XRay Team,

im having a project in python which uses websockets library. now we want to use xray to get some insights and i have to instrument it. as a starting point, i decided to set up a sample project to get to know xray, but it seems i cannot make it work.

when a client connects, im getting an error:

connection handler failed
Traceback (most recent call last):
File "/home/ec2-user/environment/projects/xray/websocket.py", line 25, in echo
subsegment = xray_recorder.begin_subsegment('process_message')
File "/home/ec2-user/.local/lib/python3.9/site-packages/aws_xray_sdk/core/recorder.py", line 313, in begin_subsegment
return self._begin_subsegment_helper(name, namespace)
File "/home/ec2-user/.local/lib/python3.9/site-packages/aws_xray_sdk/core/recorder.py", line 287, in _begin_subsegment_helper
segment = self.current_segment()
File "/home/ec2-user/.local/lib/python3.9/site-packages/aws_xray_sdk/core/recorder.py", line 271, in current_segment
entity = self.get_trace_entity()
File "/home/ec2-user/.local/lib/python3.9/site-packages/aws_xray_sdk/core/recorder.py", line 411, in get_trace_entity
return self.context.get_trace_entity()
File "/home/ec2-user/.local/lib/python3.9/site-packages/aws_xray_sdk/core/context.py", line 101, in get_trace_entity
return self.handle_context_missing()
File "/home/ec2-user/.local/lib/python3.9/site-packages/aws_xray_sdk/core/context.py", line 125, in handle_context_missing
raise SegmentNotFoundException(MISSING_SEGMENT_MSG)
aws_xray_sdk.core.exceptions.exceptions.SegmentNotFoundException: cannot find the current segment/subsegment, please make sure you have a segment open

#!/usr/bin/env python

import asyncio
from websockets.server import serve

from aws_xray_sdk.core.async_context import AsyncContext
from aws_xray_sdk.core import xray_recorder

# Configure the X-Ray recorder
xray_recorder.configure(
    service='websocket', 
    context=AsyncContext(), 
    context_missing='RUNTIME_ERROR', 
    daemon_address='localhost:2000'
)

async def echo(websocket):
    segment = xray_recorder.begin_segment('echo')

    try:
        async for message in websocket:
            subsegment = xray_recorder.begin_subsegment('process_message')

            try:
                await websocket.send(message)
            except Exception as e:
                subsegment.add_exception(e)
            finally:
                xray_recorder.end_subsegment()

    except Exception as e:
        segment.add_exception(e)
    finally:
        xray_recorder.end_segment()

async def main():
    async with serve(echo, "localhost", 8765):
        await asyncio.Future()  # run forever

asyncio.run(main())

what am i doing wrong?

Lingua principale
Python
Stelle
339
Fork
147
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di aws/aws-xray-sdk-python

Tutte le issue di aws/aws-xray-sdk-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.