28
28
from opentelemetry ._logs import LogRecord
29
29
from opentelemetry .test .test_base import TestBase
30
30
from opentelemetry .util .genai import types
31
- from opentelemetry .util .genai ._fsspec_upload .completion_hook import (
32
- FsspecUploadCompletionHook ,
31
+ from opentelemetry .util .genai ._upload .completion_hook import (
32
+ UploadCompletionHook ,
33
33
)
34
34
from opentelemetry .util .genai .completion_hook import (
35
35
_NoOpCompletionHook ,
44
44
@patch .dict (
45
45
"os.environ" ,
46
46
{
47
- "OTEL_INSTRUMENTATION_GENAI_COMPLETION_HOOK" : "fsspec_upload " ,
47
+ "OTEL_INSTRUMENTATION_GENAI_COMPLETION_HOOK" : "upload " ,
48
48
"OTEL_INSTRUMENTATION_GENAI_UPLOAD_BASE_PATH" : BASE_PATH ,
49
49
},
50
50
clear = True ,
51
51
)
52
- class TestFsspecEntryPoint (TestCase ):
53
- def test_fsspec_entry_point (self ):
54
- self .assertIsInstance (
55
- load_completion_hook (), FsspecUploadCompletionHook
56
- )
52
+ class TestUploadEntryPoint (TestCase ):
53
+ def test_upload_entry_point (self ):
54
+ self .assertIsInstance (load_completion_hook (), UploadCompletionHook )
57
55
58
- def test_fsspec_entry_point_no_fsspec (self ):
56
+ def test_upload_entry_point_no_fsspec (self ):
59
57
"""Tests that the a no-op uploader is used when fsspec is not installed"""
60
58
61
- from opentelemetry .util .genai import _fsspec_upload
59
+ from opentelemetry .util .genai import _upload
62
60
63
61
# Simulate fsspec imports failing
64
62
with patch .dict (
65
63
sys .modules ,
66
- {"opentelemetry.util.genai._fsspec_upload .completion_hook" : None },
64
+ {"opentelemetry.util.genai._upload .completion_hook" : None },
67
65
):
68
- importlib .reload (_fsspec_upload )
66
+ importlib .reload (_upload )
69
67
self .assertIsInstance (load_completion_hook (), _NoOpCompletionHook )
70
68
71
69
@@ -114,15 +112,15 @@ def _increment_mock_call(self, /, *args, **kwargs):
114
112
super ()._increment_mock_call (* args , ** kwargs )
115
113
116
114
117
- class TestFsspecUploadCompletionHook (TestCase ):
115
+ class TestUploadCompletionHook (TestCase ):
118
116
def setUp (self ):
119
117
self ._fsspec_patcher = patch (
120
- "opentelemetry.util.genai._fsspec_upload .completion_hook.fsspec"
118
+ "opentelemetry.util.genai._upload .completion_hook.fsspec"
121
119
)
122
120
self .mock_fsspec = self ._fsspec_patcher .start ()
123
121
self .mock_fsspec .open = ThreadSafeMagicMock ()
124
122
125
- self .hook = FsspecUploadCompletionHook (
123
+ self .hook = UploadCompletionHook (
126
124
base_path = BASE_PATH ,
127
125
max_size = MAXSIZE ,
128
126
)
@@ -187,7 +185,7 @@ def test_upload_blocked(self):
187
185
)
188
186
189
187
self .assertIn (
190
- "fsspec upload queue is full, dropping upload" , logs .output [0 ]
188
+ "upload queue is full, dropping upload" , logs .output [0 ]
191
189
)
192
190
193
191
def test_shutdown_timeout (self ):
@@ -212,13 +210,11 @@ def test_failed_upload_logs(self):
212
210
)
213
211
self .hook .shutdown ()
214
212
215
- self .assertIn ("fsspec uploader failed" , logs .output [0 ])
213
+ self .assertIn ("uploader failed" , logs .output [0 ])
216
214
217
215
def test_invalid_upload_format (self ):
218
216
with self .assertRaisesRegex (ValueError , "Invalid upload_format" ):
219
- FsspecUploadCompletionHook (
220
- base_path = BASE_PATH , upload_format = "invalid"
221
- )
217
+ UploadCompletionHook (base_path = BASE_PATH , upload_format = "invalid" )
222
218
223
219
def test_parse_upload_format_envvar (self ):
224
220
for envvar_value , expect in (
@@ -233,7 +229,7 @@ def test_parse_upload_format_envvar(self):
233
229
{"OTEL_INSTRUMENTATION_GENAI_UPLOAD_FORMAT" : envvar_value },
234
230
clear = True ,
235
231
):
236
- hook = FsspecUploadCompletionHook (base_path = BASE_PATH )
232
+ hook = UploadCompletionHook (base_path = BASE_PATH )
237
233
self .addCleanup (hook .shutdown )
238
234
self .assertEqual (
239
235
hook ._format ,
@@ -246,7 +242,7 @@ def test_parse_upload_format_envvar(self):
246
242
{"OTEL_INSTRUMENTATION_GENAI_UPLOAD_FORMAT" : "json" },
247
243
clear = True ,
248
244
):
249
- hook = FsspecUploadCompletionHook (
245
+ hook = UploadCompletionHook (
250
246
base_path = BASE_PATH , upload_format = "jsonl"
251
247
)
252
248
self .addCleanup (hook .shutdown )
@@ -262,18 +258,18 @@ def test_upload_after_shutdown_logs(self):
262
258
)
263
259
self .assertEqual (len (logs .output ), 3 )
264
260
self .assertIn (
265
- "attempting to upload file after FsspecUploadCompletionHook .shutdown() was already called" ,
261
+ "attempting to upload file after UploadCompletionHook .shutdown() was already called" ,
266
262
logs .output [0 ],
267
263
)
268
264
269
265
270
- class TestFsspecUploadCompletionHookIntegration (TestBase ):
266
+ class TestUploadCompletionHookIntegration (TestBase ):
271
267
def setUp (self ):
272
268
super ().setUp ()
273
- self .hook = FsspecUploadCompletionHook (base_path = BASE_PATH )
269
+ self .hook = UploadCompletionHook (base_path = BASE_PATH )
274
270
275
- def create_hook (self ) -> FsspecUploadCompletionHook :
276
- self .hook = FsspecUploadCompletionHook (base_path = BASE_PATH )
271
+ def create_hook (self ) -> UploadCompletionHook :
272
+ self .hook = UploadCompletionHook (base_path = BASE_PATH )
277
273
return self .hook
278
274
279
275
def tearDown (self ):
@@ -365,9 +361,7 @@ def test_upload_bytes(self) -> None:
365
361
)
366
362
367
363
def test_upload_json (self ) -> None :
368
- hook = FsspecUploadCompletionHook (
369
- base_path = BASE_PATH , upload_format = "json"
370
- )
364
+ hook = UploadCompletionHook (base_path = BASE_PATH , upload_format = "json" )
371
365
self .addCleanup (hook .shutdown )
372
366
log_record = LogRecord ()
373
367
@@ -390,9 +384,7 @@ def test_upload_json(self) -> None:
390
384
)
391
385
392
386
def test_upload_jsonlines (self ) -> None :
393
- hook = FsspecUploadCompletionHook (
394
- base_path = BASE_PATH , upload_format = "jsonl"
395
- )
387
+ hook = UploadCompletionHook (base_path = BASE_PATH , upload_format = "jsonl" )
396
388
self .addCleanup (hook .shutdown )
397
389
log_record = LogRecord ()
398
390
0 commit comments