Skip to content

Commit 8200c88

Browse files
committed
Switch to Sha 256
1 parent 6589de3 commit 8200c88

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from __future__ import annotations
1717

18-
import binascii
18+
import hashlib
1919
import logging
2020
import posixpath
2121
import 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(

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
# pylint: disable=import-outside-toplevel,no-name-in-module
17-
import binascii
17+
import hashlib
1818
import importlib
1919
import logging
2020
import 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=[],

0 commit comments

Comments
 (0)