Open reiyw opened 6 days ago
Thanks for reporting @reiyw! Can you confirm that adding an empty __init__.py
to opentelemetry/semconv
under the opentelemetry-semconv-conventions-ai
solves this?
adding an empty
__init__.py
toopentelemetry/semconv
under theopentelemetry-semconv-conventions-ai
That won't solve the problem. Since the opentelemetry.semconv
package is a regular package in opentelemetry-semantic-conventions
, if it is loaded first, this issue will occur regardless of whether the opentelemetry.semconv
package is a regular package or a namespace package in opentelemetry-semantic-conventions-ai
.
@reiyw how do you think we should resoive it? rename the package to be under opentelemetry/semconv-ai
or something?
@nirga That is one solution. Another solution is to have the opentelemetry.semconv
package distributed by opentelemetry-semantic-conventions
changed from a regular package to a namespace package.
Either way it would be a breaking change, but the way of restructuring the opentelemetry.semconv.ai
package would be easier for you to control the situation. As an example, the steps for restructuring would be as follows:
packages/opentelemetry-semantic-conventions-ai/opentelemetry/semconv/ai
to packages/opentelemetry-semantic-conventions-ai/opentelemetry/semconv_ai
.opentelemetry/semconv_ai
to the tool.poetry.packages.include
.semconv/ai/__init__.py
to re-export the symbols in semconv_ai
and issue a DeprecationWarning
. At this point, the user can import the same package with import opentelemetry.semconv.ai
and import opentelemetry.semconv_ai
, but will be prompted to switch to the latter style.opentelemetry/semconv/ai
after a certain migration period.
Which component is this bug for?
LLM Semantic Conventions
π Description
Due to an inconsistency in the packaging methods between
opentelemetry-semantic-conventions
andopentelemetry-semantic-conventions-ai
, importingopentelemetry.semconv.ai
may fail in certain environments.π Reproduction steps
Reproduction repository: https://github.com/reiyw/opentelemetry-semconv-ai-repro
Run the following code:
π Expected behavior
It should be imported without any issues.
π Actual Behavior with Screenshots
The following error is output:
π€ Python Version
3.11
π Provide any additional context for the Bug.
The root cause of this issue is the inconsistency in the packaging methods between
opentelemetry-semantic-conventions
andopentelemetry-semantic-conventions-ai
. Inopentelemetry-semantic-conventions
, an emptyopentelemetry/semconv/__init__.py
is placed, which causes theopentelemetry.semconv
package to be recognized as a regular package. On the other hand, inopentelemetry-semantic-conventions-ai
, the absence ofopentelemetry/semconv/__init__.py
leads to theopentelemetry.semconv
package being recognized as a namespace package.It is not a problem in the style of consolidating packages in one place (the usual style using pip or poetry) for a package to be a regular package and a namespace package at the same time, but in general it can cause import problems. The following is the directory structure of the
opentelemetry.semconv
package whentraceloop-sdk
is installed using pip:In this situation, the
opentelemetry.semconv.ai
package is recognized as a subpackage of theopentelemetry.semconv
package, so it can be imported without any problems.On the other hand, consider the following directory structure:
In this situation, the package logic is broken. In the
site-packages-1
directory,opentelemetry.semconv
is a regular package that does not include theai
namespace, so if it is loaded first, the import ofopentelemetry.semconv.ai
will fail. This directory structure may seem strange, but it is the structure adopted by rules_python (the Python toolchain for Bazel), and namespace packages are a mechanism that allows for this kind of structure.I think the fundamental solution to this problem is one of the following two:
opentelemetry-semantic-conventions
to make theopentelemetry.semconv
package a namespace package.opentelemetry.semconv.ai
package. For example, distributing it as theopentelemetry.semconv_ai
package.opentelemetry
is an officially namespace package, so it should work correctly.There are workarounds for this at runtime, as shown in my reproduction repository, but it would be better to resolve the underlying problem.
π Have you spent some time to check if this bug has been raised before?
Are you willing to submit PR?
None