File tree Expand file tree Collapse file tree 2 files changed +15
-19
lines changed
util/opentelemetry-util-genai
src/opentelemetry/util/genai/_upload Expand file tree Collapse file tree 2 files changed +15
-19
lines changed Original file line number Diff line number Diff line change 1515
1616from __future__ import annotations
1717
18- import binascii
18+ import hashlib
1919import logging
2020import posixpath
2121import threading
@@ -160,14 +160,13 @@ def _calculate_ref_path(
160160 # gen_ai.response.id from the active span.
161161 system_instruction_hash = None
162162 if all (isinstance (x , types .Text ) for x in system_instruction ):
163- # Get a checksum of the text.
164- system_instruction_hash = hex (
165- binascii .crc32 (
166- "\n " .join (x .content for x in system_instruction ).encode ( # pyright: ignore[reportUnknownMemberType, reportAttributeAccessIssue, reportUnknownArgumentType]
167- "utf-8"
168- )
169- )
170- )
163+ # Get a hash of the text.
164+ system_instruction_hash = hashlib .sha256 (
165+ "\n " .join (x .content for x in system_instruction ).encode ( # pyright: ignore[reportUnknownMemberType, reportAttributeAccessIssue, reportUnknownArgumentType]
166+ "utf-8"
167+ ),
168+ usedforsecurity = False ,
169+ ).hexdigest ()
171170 uuid_str = str (uuid4 ())
172171 return CompletionRefs (
173172 inputs_ref = posixpath .join (
Original file line number Diff line number Diff line change 1414
1515
1616# pylint: disable=import-outside-toplevel,no-name-in-module
17- import binascii
17+ import hashlib
1818import importlib
1919import logging
2020import sys
@@ -160,7 +160,7 @@ def test_upload_then_shutdown(self):
160160 # all items should be consumed
161161 self .hook .shutdown ()
162162 # TODO: https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3812 fix flaky test that requires sleep.
163- time .sleep (2 )
163+ time .sleep (0.5 )
164164 self .assertEqual (
165165 self .mock_fs .open .call_count ,
166166 3 ,
@@ -172,13 +172,10 @@ def test_system_insruction_is_hashed_to_avoid_reupload(self):
172172 types .Text (content = "You are a helpful assistant." ),
173173 types .Text (content = "You will do your best." ),
174174 ]
175- expected_hash = hex (
176- binascii .crc32 (
177- "\n " .join (x .content for x in system_instructions ).encode (
178- "utf-8"
179- )
180- )
181- )
175+ expected_hash = hashlib .sha256 (
176+ "\n " .join (x .content for x in system_instructions ).encode ("utf-8" ),
177+ usedforsecurity = False ,
178+ ).hexdigest ()
182179 record = LogRecord ()
183180 self .hook .on_completion (
184181 inputs = [],
@@ -187,7 +184,7 @@ def test_system_insruction_is_hashed_to_avoid_reupload(self):
187184 log_record = record ,
188185 )
189186 # Wait a bit for file upload to finish..
190- time .sleep (0.5 )
187+ time .sleep (2 )
191188 self .mock_fs .exists .return_value = True
192189 self .hook .on_completion (
193190 inputs = [],
You can’t perform that action at this time.
0 commit comments