|
| 1 | +# Copyright The OpenTelemetry Authors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from __future__ import annotations |
| 16 | + |
| 17 | +from os import environ |
| 18 | + |
| 19 | +from opentelemetry.util.genai.environment_variables import ( |
| 20 | + OTEL_INSTRUMENTATION_GENAI_UPLOAD_BASE_PATH, |
| 21 | +) |
| 22 | +from opentelemetry.util.genai.upload_hook import UploadHook, _NoOpUploadHook |
| 23 | + |
| 24 | + |
| 25 | +def fsspec_upload_hook() -> UploadHook: |
| 26 | + # If fsspec is not installed the hook will be a no-op. |
| 27 | + try: |
| 28 | + # pylint: disable=import-outside-toplevel |
| 29 | + from opentelemetry.util.genai._fsspec_upload.fsspec_hook import ( |
| 30 | + FsspecUploader, |
| 31 | + FsspecUploadHook, |
| 32 | + ) |
| 33 | + except ImportError: |
| 34 | + return _NoOpUploadHook() |
| 35 | + |
| 36 | + base_path = environ.get(OTEL_INSTRUMENTATION_GENAI_UPLOAD_BASE_PATH) |
| 37 | + if not base_path: |
| 38 | + return _NoOpUploadHook() |
| 39 | + |
| 40 | + return FsspecUploadHook( |
| 41 | + uploader=FsspecUploader(), |
| 42 | + base_path=base_path, |
| 43 | + ) |
0 commit comments