Skip to content

Commit 0267c6f

Browse files
authored
fix: AG2 minor refactor for LIBRARY_NAME & LIBRARY_VERSION (#1010)
minor refactor
1 parent 54c4570 commit 0267c6f

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

agentops/instrumentation/ag2/__init__.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,24 @@
55
than individual message exchanges.
66
"""
77

8-
from agentops.instrumentation.ag2.instrumentor import AG2Instrumentor
9-
from agentops.instrumentation.ag2.version import LIBRARY_NAME, LIBRARY_VERSION
8+
from agentops.logging import logger
9+
10+
11+
def get_version() -> str:
12+
"""Get the version of the AG2 package, or 'unknown' if not found"""
13+
try:
14+
from importlib.metadata import version
15+
16+
return version("ag2")
17+
except ImportError:
18+
logger.debug("Could not find AG2 version")
19+
return "unknown"
20+
21+
22+
LIBRARY_NAME = "ag2"
23+
LIBRARY_VERSION: str = get_version()
24+
25+
# Import after defining constants to avoid circular imports
26+
from agentops.instrumentation.ag2.instrumentor import AG2Instrumentor # noqa: E402
1027

1128
__all__ = ["AG2Instrumentor", "LIBRARY_NAME", "LIBRARY_VERSION"]

agentops/instrumentation/ag2/instrumentor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from wrapt import wrap_function_wrapper
1414

1515
from agentops.logging import logger
16-
from agentops.instrumentation.ag2.version import LIBRARY_NAME, LIBRARY_VERSION
16+
from agentops.instrumentation.ag2 import LIBRARY_NAME, LIBRARY_VERSION
1717
from agentops.semconv import Meters
1818
from agentops.semconv.message import MessageAttributes
1919
from agentops.semconv.span_attributes import SpanAttributes

agentops/instrumentation/ag2/version.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)