1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- """This module defines the generic hooks for GenAI content uploading
15+ """This module defines the generic hooks for GenAI content completion
1616
1717The hooks are specified as part of semconv in `Uploading content to external storage
1818<https://github.com/open-telemetry/semantic-conventions/blob/v1.37.0/docs/gen-ai/gen-ai-spans.md#uploading-content-to-external-storage>`__.
1919
20- This module defines the `UploadHook ` type that custom implementations should implement, and a
21- `load_upload_hook ` function to load it from an entry point.
20+ This module defines the `CompletionHook ` type that custom implementations should implement, and a
21+ `load_completion_hook ` function to load it from an entry point.
2222"""
2323
2424from __future__ import annotations
3434)
3535from opentelemetry .util .genai import types
3636from opentelemetry .util .genai .environment_variables import (
37- OTEL_INSTRUMENTATION_GENAI_UPLOAD_HOOK ,
37+ OTEL_INSTRUMENTATION_GENAI_COMPLETION_HOOK ,
3838)
3939
4040_logger = logging .getLogger (__name__ )
4141
4242
4343@runtime_checkable
44- class UploadHook (Protocol ):
45- """A hook to upload GenAI content to an external storage .
44+ class CompletionHook (Protocol ):
45+ """A hook to be called on completion of a GenAI operation .
4646
4747 This is the interface for a hook that can be
48- used to upload GenAI content to an external storage . The hook is a
48+ used to capture GenAI content on completion . The hook is a
4949 callable that takes the inputs, outputs, and system instruction of a
5050 GenAI interaction, as well as the span and log record associated with
5151 it.
@@ -66,7 +66,7 @@ class UploadHook(Protocol):
6666 interaction.
6767 """
6868
69- def upload (
69+ def on_completion (
7070 self ,
7171 * ,
7272 inputs : list [types .InputMessage ],
@@ -77,43 +77,47 @@ def upload(
7777 ) -> None : ...
7878
7979
80- class _NoOpUploadHook ( UploadHook ):
81- def upload (self , ** kwargs : Any ) -> None :
80+ class _NoOpCompletionHook ( CompletionHook ):
81+ def on_completion (self , ** kwargs : Any ) -> None :
8282 return None
8383
8484
85- def load_upload_hook () -> UploadHook :
86- """Load the upload hook from entry point or return a noop implementation
85+ def load_completion_hook () -> CompletionHook :
86+ """Load the completion hook from entry point or return a noop implementation
8787
88- This function loads an upload hook from the entry point group
89- ``opentelemetry_genai_upload_hook `` with name coming from
90- :envvar:`OTEL_INSTRUMENTATION_GENAI_UPLOAD_HOOK `. If one can't be found, returns a no-op
88+ This function loads an completion hook from the entry point group
89+ ``opentelemetry_genai_completion_hook `` with name coming from
90+ :envvar:`OTEL_INSTRUMENTATION_GENAI_COMPLETION_HOOK `. If one can't be found, returns a no-op
9191 implementation.
9292 """
93- hook_name = environ .get (OTEL_INSTRUMENTATION_GENAI_UPLOAD_HOOK , None )
93+ hook_name = environ .get (OTEL_INSTRUMENTATION_GENAI_COMPLETION_HOOK , None )
9494 if not hook_name :
95- return _NoOpUploadHook ()
95+ return _NoOpCompletionHook ()
9696
97- for entry_point in entry_points (group = "opentelemetry_genai_upload_hook" ): # pyright: ignore[reportUnknownVariableType]
97+ for entry_point in entry_points ( # pyright: ignore[reportUnknownVariableType]
98+ group = "opentelemetry_genai_completion_hook"
99+ ):
98100 name = cast (str , entry_point .name ) # pyright: ignore[reportUnknownMemberType]
99101 try :
100102 if hook_name != name :
101103 continue
102104
103105 hook = entry_point .load ()() # pyright: ignore[reportUnknownVariableType, reportUnknownMemberType]
104- if not isinstance (hook , UploadHook ):
105- _logger .debug ("%s is not a valid UploadHook. Using noop" , name )
106+ if not isinstance (hook , CompletionHook ):
107+ _logger .debug (
108+ "%s is not a valid CompletionHook. Using noop" , name
109+ )
106110 continue
107111
108- _logger .debug ("Using UploadHook %s" , name )
112+ _logger .debug ("Using CompletionHook %s" , name )
109113 return hook
110114
111115 except Exception : # pylint: disable=broad-except
112116 _logger .exception (
113- "UploadHook %s configuration failed. Using noop" , name
117+ "CompletionHook %s configuration failed. Using noop" , name
114118 )
115119
116- return _NoOpUploadHook ()
120+ return _NoOpCompletionHook ()
117121
118122
119- __all__ = ["UploadHook " , "load_upload_hook " ]
123+ __all__ = ["CompletionHook " , "load_completion_hook " ]
0 commit comments