Skip to content

Commit 19af618

Browse files
committed
Update json.dumps call to use different separators
1 parent 08103d8 commit 19af618

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

instrumentation-genai/opentelemetry-instrumentation-vertexai/src/opentelemetry/instrumentation/vertexai/patch.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,11 @@ def handle_response(
224224
):
225225
span.set_attributes(
226226
{
227-
k: json.dumps(v, cls=Base64JsonEncoder)
227+
k: json.dumps(
228+
v,
229+
cls=Base64JsonEncoder,
230+
separators=(",", ":"),
231+
)
228232
for k, v in content_attributes.items()
229233
}
230234
)

instrumentation-genai/opentelemetry-instrumentation-vertexai/tests/test_chat_completions_experimental.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def test_generate_content(
5656
"gen_ai.usage.output_tokens": 5,
5757
"server.address": "us-central1-aiplatform.googleapis.com",
5858
"server.port": 443,
59-
"gen_ai.input.messages": '[{"role": "user", "parts": [{"content": "Say this is a test", "type": "text"}]}]',
60-
"gen_ai.output.messages": '[{"role": "model", "parts": [{"content": "This is a test.", "type": "text"}], "finish_reason": "stop"}]',
59+
"gen_ai.input.messages": '[{"role":"user","parts":[{"content":"Say this is a test","type":"text"}]}]',
60+
"gen_ai.output.messages": '[{"role":"model","parts":[{"content":"This is a test.","type":"text"}],"finish_reason":"stop"}]',
6161
}
6262

6363
logs = log_exporter.get_finished_logs()
@@ -109,8 +109,8 @@ def test_generate_content_without_events(
109109
assert spans[0].name == "chat gemini-2.5-pro"
110110
assert dict(spans[0].attributes) == {
111111
"gen_ai.operation.name": "chat",
112-
"gen_ai.output.messages": '[{"role": "model", "parts": [{"content": "This is a test.", "type": "text"}], "finish_reason": "stop"}]',
113-
"gen_ai.input.messages": '[{"role": "user", "parts": [{"content": "Say this is a test", "type": "text"}]}]',
112+
"gen_ai.output.messages": '[{"role":"model","parts":[{"content":"This is a test.","type":"text"}],"finish_reason":"stop"}]',
113+
"gen_ai.input.messages": '[{"role":"user","parts":[{"content":"Say this is a test","type":"text"}]}]',
114114
"gen_ai.request.model": "gemini-2.5-pro",
115115
"gen_ai.response.finish_reasons": ("stop",),
116116
"gen_ai.response.model": "gemini-2.5-pro",
@@ -177,7 +177,7 @@ def test_generate_content_empty_model(
177177
"gen_ai.request.model": "",
178178
"server.address": "us-central1-aiplatform.googleapis.com",
179179
"server.port": 443,
180-
"gen_ai.input.messages": '[{"role": "user", "parts": [{"content": "Say this is a test", "type": "text"}]}]',
180+
"gen_ai.input.messages": '[{"role":"user","parts":[{"content":"Say this is a test","type":"text"}]}]',
181181
}
182182
assert_span_error(spans[0])
183183

@@ -210,7 +210,7 @@ def test_generate_content_missing_model(
210210
"gen_ai.request.model": "gemini-does-not-exist",
211211
"server.address": "us-central1-aiplatform.googleapis.com",
212212
"server.port": 443,
213-
"gen_ai.input.messages": '[{"role": "user", "parts": [{"content": "Say this is a test", "type": "text"}]}]',
213+
"gen_ai.input.messages": '[{"role":"user","parts":[{"content":"Say this is a test","type":"text"}]}]',
214214
}
215215
assert_span_error(spans[0])
216216

@@ -245,7 +245,7 @@ def test_generate_content_invalid_temperature(
245245
"gen_ai.request.temperature": 1000.0,
246246
"server.address": "us-central1-aiplatform.googleapis.com",
247247
"server.port": 443,
248-
"gen_ai.input.messages": '[{"role": "user", "parts": [{"content": "Say this is a test", "type": "text"}]}]',
248+
"gen_ai.input.messages": '[{"role":"user","parts":[{"content":"Say this is a test","type":"text"}]}]',
249249
}
250250
assert_span_error(spans[0])
251251

instrumentation-genai/opentelemetry-instrumentation-vertexai/tests/test_function_calling_experimental.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def test_function_call_choice(
3838
"gen_ai.usage.input_tokens": 74,
3939
"gen_ai.usage.output_tokens": 16,
4040
"server.address": "us-central1-aiplatform.googleapis.com",
41-
"gen_ai.input.messages": '[{"role": "user", "parts": [{"content": "Get weather details in New Delhi and San Francisco?", "type": "text"}]}]',
42-
"gen_ai.output.messages": '[{"role": "model", "parts": [{"arguments": {"location": "New Delhi"}, "name": "get_current_weather", "id": "get_current_weather_0", "type": "tool_call"}, {"arguments": {"location": "San Francisco"}, "name": "get_current_weather", "id": "get_current_weather_1", "type": "tool_call"}], "finish_reason": "stop"}]',
41+
"gen_ai.input.messages": '[{"role":"user","parts":[{"content":"Get weather details in New Delhi and San Francisco?","type":"text"}]}]',
42+
"gen_ai.output.messages": '[{"role":"model","parts":[{"arguments":{"location":"New Delhi"},"name":"get_current_weather","id":"get_current_weather_0","type":"tool_call"},{"arguments":{"location":"San Francisco"},"name":"get_current_weather","id":"get_current_weather_1","type":"tool_call"}],"finish_reason":"stop"}]',
4343
"server.port": 443,
4444
}
4545

@@ -136,8 +136,8 @@ def test_tool_events(
136136
"gen_ai.usage.output_tokens": 26,
137137
"server.address": "us-central1-aiplatform.googleapis.com",
138138
"server.port": 443,
139-
"gen_ai.input.messages": '[{"role": "user", "parts": [{"content": "Get weather details in New Delhi and San Francisco?", "type": "text"}]}, {"role": "model", "parts": [{"arguments": {"location": "New Delhi"}, "name": "get_current_weather", "id": "get_current_weather_0", "type": "tool_call"}, {"arguments": {"location": "San Francisco"}, "name": "get_current_weather", "id": "get_current_weather_1", "type": "tool_call"}]}, {"role": "user", "parts": [{"response": {"content": "{\\"temperature\\": 35, \\"unit\\": \\"C\\"}"}, "id": "get_current_weather_0", "type": "tool_call_response"}, {"response": {"content": "{\\"temperature\\": 25, \\"unit\\": \\"C\\"}"}, "id": "get_current_weather_1", "type": "tool_call_response"}]}]',
140-
"gen_ai.output.messages": '[{"role": "model", "parts": [{"content": "The current temperature in New Delhi is 35\\u00b0C, and in San Francisco, it is 25\\u00b0C.", "type": "text"}], "finish_reason": "stop"}]',
139+
"gen_ai.input.messages": '[{"role":"user","parts":[{"content":"Get weather details in New Delhi and San Francisco?","type":"text"}]},{"role":"model","parts":[{"arguments":{"location":"New Delhi"},"name":"get_current_weather","id":"get_current_weather_0","type":"tool_call"},{"arguments":{"location":"San Francisco"},"name":"get_current_weather","id":"get_current_weather_1","type":"tool_call"}]},{"role":"user","parts":[{"response":{"content":"{\\"temperature\\": 35, \\"unit\\": \\"C\\"}"},"id":"get_current_weather_0","type":"tool_call_response"},{"response":{"content":"{\\"temperature\\": 25, \\"unit\\": \\"C\\"}"},"id":"get_current_weather_1","type":"tool_call_response"}]}]',
140+
"gen_ai.output.messages": '[{"role":"model","parts":[{"content":"The current temperature in New Delhi is 35\\u00b0C, and in San Francisco, it is 25\\u00b0C.","type":"text"}],"finish_reason":"stop"}]',
141141
}
142142
logs = log_exporter.get_finished_logs()
143143
assert len(logs) == 1

0 commit comments

Comments
 (0)