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

Document how to create new subsegments inside a ThreadPoolExecutor thread

Aperta
#341 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
aws, python
Ambito
documentation

Direzione di ricerca

Inizia dalla documentazione sul threading collegata nell’issue e rivedi i punti di ingresso capture e in_segment dopo set_trace_entity. Chiarisci il pattern supportato per creare sottosegmenti nei thread di lavoro, inclusa la pulizia, e aggiorna l’esempio in modo che il lettore possa distinguere gli approcci validi.

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

Descrizione

documentation

The current documentation shows how to set the parent thread's X-ray entity in the worker thread:

def load_url(url, trace_entity):
    # Set the parent X-Ray entity for the worker thread.
    xray_recorder.set_trace_entity(trace_entity)
    # Subsegment captured from the following HTTP GET will be
    # a child of parent entity passed from the main thread.
    resp = requests.get(url)
    # prevent thread pollution
    xray_recorder.clear_trace_entities()
    return resp

However it's not clear how this interacts with capture/in_segment. For example, I assume this isn't correct, as the capture starts before we call set_trace_entity:

@xray_recorder.capture('subsegment_name')
def load_url(url, trace_entity):
    # Set the parent X-Ray entity for the worker thread.
    xray_recorder.set_trace_entity(trace_entity)
    # Subsegment captured from the following HTTP GET will be
    # a child of parent entity passed from the main thread.
    resp = requests.get(url)
    # prevent thread pollution
    xray_recorder.clear_trace_entities()
    return resp

However, are these two OK?

def load_url(url, trace_entity):
    # Set the parent X-Ray entity for the worker thread.
    xray_recorder.set_trace_entity(trace_entity)
    with xray_recorder.capture('subsegment_name'):
        # Subsegment captured from the following HTTP GET will be
        # a child of parent entity passed from the main thread.
        resp = requests.get(url)
    # prevent thread pollution
    xray_recorder.clear_trace_entities()
    return resp
def load_url(url, trace_entity):
    # Set the parent X-Ray entity for the worker thread.
    xray_recorder.set_trace_entity(trace_entity)
    with xray_recorder.in_segment('segment_name') as segment:
        segment.put_metadata('key', dict, 'namespace')
        # Subsegment captured from the following HTTP GET will be
        # a child of parent entity passed from the main thread.
        resp = requests.get(url)
    # prevent thread pollution
    xray_recorder.clear_trace_entities()
    return resp

It would be great if the docs on threading had a more complete example.

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.