Skip to content

Commit 274a14b

Browse files
committed
fix: replace getattr with string literals, add TODO for semconv migration, fix pylint
1 parent 6ed56b6 commit 274a14b

4 files changed

Lines changed: 7 additions & 24 deletions

File tree

util/opentelemetry-util-genai/src/opentelemetry/util/genai/_agent_invocation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
ToolDefinition,
3636
)
3737

38+
# TODO: Migrate to GenAI constants once available in semconv package
3839
_GEN_AI_AGENT_VERSION = "gen_ai.agent.version"
3940
_GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS = (
4041
"gen_ai.usage.cache_creation.input_tokens"

util/opentelemetry-util-genai/src/opentelemetry/util/genai/_inference_invocation.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,11 @@
4040
should_emit_event,
4141
)
4242

43-
_GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS: str = getattr(
44-
GenAI,
45-
"GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS",
46-
"gen_ai.usage.cache_creation.input_tokens",
47-
)
48-
_GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS: str = getattr(
49-
GenAI,
50-
"GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS",
51-
"gen_ai.usage.cache_read.input_tokens",
43+
# TODO: Migrate to GenAI constants once available in semconv package
44+
_GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS = (
45+
"gen_ai.usage.cache_creation.input_tokens"
5246
)
47+
_GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS = "gen_ai.usage.cache_read.input_tokens"
5348

5449

5550
class InferenceInvocation(GenAIInvocation):

util/opentelemetry-util-genai/src/opentelemetry/util/genai/_upload/completion_hook.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@
5252
gen_ai_attributes.GEN_AI_SYSTEM_INSTRUCTIONS + "_ref"
5353
)
5454

55-
GEN_AI_TOOL_DEFINITIONS = getattr(
56-
gen_ai_attributes, "GEN_AI_TOOL_DEFINITIONS", "gen_ai.tool.definitions"
57-
)
55+
# TODO: Migrate to gen_ai_attributes constant once available in semconv package
56+
GEN_AI_TOOL_DEFINITIONS = "gen_ai.tool.definitions"
5857
GEN_AI_TOOL_DEFINITIONS_REF: Final = GEN_AI_TOOL_DEFINITIONS + "_ref"
5958

6059
_MESSAGE_INDEX_KEY = "index"

util/opentelemetry-util-genai/tests/test_handler_agent.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,6 @@ def test_finish_reasons_empty_list_omitted(self):
126126
invocation.finish_reasons = []
127127
invocation.stop()
128128
attrs = self.span_exporter.get_finished_spans()[0].attributes
129-
assert GenAI.GEN_AI_RESPONSE_FINISH_REASONS not in attrs
130-
131-
def test_no_response_model_or_finish_reasons(self):
132-
invocation = self.handler.start_invoke_local_agent("openai")
133-
invocation.stop()
134-
attrs = self.span_exporter.get_finished_spans()[0].attributes
135129
assert GenAI.GEN_AI_RESPONSE_MODEL not in attrs
136130
assert GenAI.GEN_AI_RESPONSE_FINISH_REASONS not in attrs
137131

@@ -260,12 +254,6 @@ def test_agent_name_set_after_construction(self):
260254
assert span.name == "invoke_agent Named Agent"
261255
assert span.attributes[GenAI.GEN_AI_AGENT_NAME] == "Named Agent"
262256

263-
def test_provider_always_set(self):
264-
invocation = self.handler.start_invoke_local_agent("gcp_vertex_ai")
265-
invocation.stop()
266-
attrs = self.span_exporter.get_finished_spans()[0].attributes
267-
assert attrs[GenAI.GEN_AI_PROVIDER_NAME] == "gcp_vertex_ai"
268-
269257

270258
class TestAgentInvocationContent(unittest.TestCase):
271259
def setUp(self):

0 commit comments

Comments
 (0)