openllmetry icon indicating copy to clipboard operation
openllmetry copied to clipboard

fix: open() calls missing encoding='utf-8' may crash on non-UTF-8 systems

Open nandithasalim opened this issue 5 months ago • 2 comments

Several open() calls in the codebase don't specify encoding='utf-8', which can cause UnicodeDecodeError on Windows systems with non-UTF-8 locales (e.g. GBK).

Affected files:

  • packages/opentelemetry-instrumentation-qdrant/init.py (lines 26, 30)
  • scripts/codegen/generate_evaluator_models.py (line 27)

Fix: add encoding='utf-8' to all text-mode open() calls.

nandithasalim avatar Jun 17 '26 13:06 nandithasalim

I confirmed both affected files:

1. packages/opentelemetry-instrumentation-qdrant/opentelemetry/instrumentation/qdrant/__init__.py, lines 26-30:

with open(p, "r") as f:                            # line 26 — fix: add encoding="utf-8"
    QDRANT_CLIENT_METHODS = json.loads(f.read())

p = Path(__file__).with_name("async_qdrant_client_methods.json")
with open(p, "r") as f:                             # line 30 — fix: add encoding="utf-8"
    ASYNC_QDRANT_CLIENT_METHODS = json.loads(f.read())

These read JSON files shipped with the package (always UTF-8), but on Windows with a GBK locale Python will use the system encoding and raise UnicodeDecodeError if any bytes >127 appear in the file.

2. scripts/codegen/generate_evaluator_models.py, line 27:

with open(swagger_path) as f:                       # fix: add encoding="utf-8"
    data = json.load(f)

The Swagger spec could contain UTF-8 characters from descriptions or examples.

All three need the same fix: open(..., encoding="utf-8"). This is a cross-platform correctness issue that won't show up on Linux/macOS (where UTF-8 is the default in most configurations) but will crash deterministically on Windows with non-UTF-8 system locale.

I can open a PR covering all three if helpful.

cschanhniem avatar Jun 19 '26 04:06 cschanhniem

Hi, I'd like to work on this.

I can update the affected text-mode open() calls to pass encoding="utf-8", so these JSON/Swagger reads do not depend on the system default encoding.

LuoisaWu avatar Jul 04 '26 19:07 LuoisaWu