Skip to content

Commit f07f311

Browse files
committed
Updated the review comments
1 parent 6d33235 commit f07f311

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

packages/opentelemetry-instrumentation-google-generativeai/opentelemetry/instrumentation/google_generativeai/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ async def _awrap(
213213
duration_histogram.record(
214214
duration,
215215
attributes={
216-
"gen_ai.provider.name": "Google",
217-
"gen_ai.response.model": llm_model
216+
GenAIAttributes.GEN_AI_PROVIDER_NAME: "Google",
217+
GenAIAttributes.GEN_AI_RESPONSE_MODEL: llm_model
218218
},
219219
)
220220
if response:
@@ -284,8 +284,8 @@ def _wrap(
284284
duration_histogram.record(
285285
duration,
286286
attributes={
287-
"gen_ai.provider.name": "Google",
288-
"gen_ai.response.model": llm_model
287+
GenAIAttributes.GEN_AI_PROVIDER_NAME: "Google",
288+
GenAIAttributes.GEN_AI_RESPONSE_MODEL: llm_model
289289
},
290290
)
291291
if response:

packages/opentelemetry-instrumentation-google-generativeai/opentelemetry/instrumentation/google_generativeai/span_utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,17 +473,17 @@ def set_model_response_attributes(span, response, llm_model, token_histogram):
473473
token_histogram.record(
474474
response.usage_metadata.prompt_token_count,
475475
attributes={
476-
"gen_ai.provider.name": "Google",
477-
"gen_ai.token.type": "input",
478-
"gen_ai.response.model": llm_model,
476+
GenAIAttributes.GEN_AI_PROVIDER_NAME: "Google",
477+
GenAIAttributes.GEN_AI_TOKEN_TYPE: "input",
478+
GenAIAttributes.GEN_AI_RESPONSE_MODEL: llm_model,
479479
}
480480
)
481481
token_histogram.record(
482482
response.usage_metadata.candidates_token_count,
483483
attributes={
484-
"gen_ai.provider.name": "Google",
485-
"gen_ai.token.type": "output",
486-
"gen_ai.response.model": llm_model,
484+
GenAIAttributes.GEN_AI_PROVIDER_NAME: "Google",
485+
GenAIAttributes.GEN_AI_TOKEN_TYPE: "output",
486+
GenAIAttributes.GEN_AI_RESPONSE_MODEL: llm_model,
487487
},
488488
)
489489

packages/opentelemetry-instrumentation-google-generativeai/tests/test_generate_content.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ def test_generate_metrics(metrics_test_context, genai_client):
9494

9595
# ---- Required metrics (semantic conventions) ----
9696
required_metrics = {
97-
"gen_ai.client.operation.duration",
98-
"gen_ai.client.token.usage",
97+
Meters.LLM_OPERATION_DURATION,
98+
Meters.LLM_TOKEN_USAGE,
9999
}
100100
assert required_metrics.issubset(metrics.keys())
101101

102-
duration_metric = metrics["gen_ai.client.operation.duration"]
102+
duration_metric = metrics[Meters.LLM_OPERATION_DURATION]
103103

104104
assert duration_metric.unit is not None
105105
assert duration_metric.data.data_points
@@ -111,16 +111,16 @@ def test_generate_metrics(metrics_test_context, genai_client):
111111
assert duration_dp.sum >= 0
112112

113113
# Required attributes (values are intentionally not hard-coded)
114-
assert "gen_ai.provider.name" in duration_dp.attributes
115-
assert "gen_ai.response.model" in duration_dp.attributes
114+
assert GenAIAttributes.GEN_AI_PROVIDER_NAME in duration_dp.attributes
115+
assert GenAIAttributes.GEN_AI_RESPONSE_MODEL in duration_dp.attributes
116116

117117
token_metric = metrics[Meters.LLM_TOKEN_USAGE]
118118

119119
assert token_metric.unit == "token"
120120
assert token_metric.data.data_points
121121

122122
token_points_by_type = {
123-
dp.attributes.get("gen_ai.token.type"): dp
123+
dp.attributes.get(SpanAttributes.LLM_TOKEN_TYPE): dp
124124
for dp in token_metric.data.data_points
125125
}
126126

@@ -132,5 +132,5 @@ def test_generate_metrics(metrics_test_context, genai_client):
132132
assert dp.sum >= 0
133133

134134
# Required semantic attributes
135-
assert "gen_ai.provider.name" in dp.attributes
136-
assert "gen_ai.response.model" in dp.attributes
135+
assert GenAIAttributes.GEN_AI_PROVIDER_NAME in dp.attributes
136+
assert GenAIAttributes.GEN_AI_RESPONSE_MODEL in dp.attributes

0 commit comments

Comments
 (0)