Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

ERROR:aws_xray_sdk.core.context:cannot find the current segment/subsegment, please make sure you have a segment open

Đang mở
#452 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
aws, python
Lĩnh vực
cloud, observability-sre

Hướng nghiên cứu

Bắt đầu với bản tái hiện generate_and_upload được cung cấp, đặc biệt là xray_recorder.configure và ngữ cảnh in_segment xung quanh s3_client.upload_file. Chạy nó với Python 3.11.1 và aws-xray-sdk 2.14.0, sau đó kiểm tra cách segment hoạt động trong quá trình upload và dọn dẹp. Được xem là hoàn tất khi upload vẫn thành công, lỗi ngữ cảnh đã biến mất và segment hiển thị trong AWS X-Ray console.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

``Hi,

I am experiencing an issue with the AWS X-Ray SDK for Python where segments are not being properly created or propagated, resulting in the following exception:

ERROR:aws_xray_sdk.core.context:cannot find the current segment/subsegment, please make sure you have a segment open

The file is being successfully being uploaded in my s3 bucket but the segment is not being traced.

Steps to Reproduce:


import json
import os
import boto3
from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core import patch_all
import logging
from botocore.exceptions import NoCredentialsError, PartialCredentialsError
from aws_xray_sdk import global_sdk_config
from boto3.s3.transfer import TransferConfig

patch_all()

logging.basicConfig(level='ERROR')
logging.getLogger('aws_xray_sdk.core').setLevel(logging.ERROR)

.
.
.
.
def generate_and_upload(init, count):
    session = boto3.Session(profile_name=aws_profile_name)
    s3_client = session.client("s3")

    # Create file path
    file_path = os.path.join("generated", "data.json")

    # Write data to the file
    with open(file_path, "w") as file:
        json.dump(
            generate_json_document(init, count),
            file,
            separators=(",", ":"),
            ensure_ascii=False,
        )
        
    xray_recorder.configure(service='data-generator')
    with xray_recorder.in_segment('generate_and_upload') as segment:
        trace_header = segment.trace_id
        print(f"Trace Header: {trace_header}")
        try:
            trnasver_config = TransferConfig(max_concurrency=1)
            s3_client.upload_file(
                file_path,
                f"{bucket}",
                f"{path}",
                ExtraArgs={"Metadata": {"X-Amzn-Trace-Id": trace_header}},
                Config=trnasver_config,
            )
            print(
                f"Uploaded"
            )
        finally:
            xray_recorder.end_segment()

I tried to set os.environ['AWS_XRAY_SDK_ENABLED'] = 'false' and a dummy segment was created, but I am not able to see it in the AWS X-ray console.
I am using Python 3.11.1 and aws-xray-sdk is Version: 2.14.0

I have also tried to set off threading and also have 1 thread. The issue still exist,

@chanchiem
@luzfcb
@heitorlessa

Ngôn ngữ chính
Python
Star
340
Fork
148
Merge trung bình
7 ngày 8 giờ
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của aws/aws-xray-sdk-python

Tất cả issue của aws/aws-xray-sdk-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.