opentelemetry-instrumentation-replicate 0.16.5__tar.gz → 0.16.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of opentelemetry-instrumentation-replicate might be problematic. Click here for more details.
- {opentelemetry_instrumentation_replicate-0.16.5 → opentelemetry_instrumentation_replicate-0.16.6}/PKG-INFO +1 -1
- {opentelemetry_instrumentation_replicate-0.16.5 → opentelemetry_instrumentation_replicate-0.16.6}/opentelemetry/instrumentation/replicate/__init__.py +14 -30
- opentelemetry_instrumentation_replicate-0.16.6/opentelemetry/instrumentation/replicate/config.py +2 -0
- opentelemetry_instrumentation_replicate-0.16.6/opentelemetry/instrumentation/replicate/utils.py +23 -0
- opentelemetry_instrumentation_replicate-0.16.6/opentelemetry/instrumentation/replicate/version.py +1 -0
- {opentelemetry_instrumentation_replicate-0.16.5 → opentelemetry_instrumentation_replicate-0.16.6}/pyproject.toml +1 -1
- opentelemetry_instrumentation_replicate-0.16.5/opentelemetry/instrumentation/replicate/version.py +0 -1
- {opentelemetry_instrumentation_replicate-0.16.5 → opentelemetry_instrumentation_replicate-0.16.6}/README.md +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: opentelemetry-instrumentation-replicate
|
|
3
|
-
Version: 0.16.
|
|
3
|
+
Version: 0.16.6
|
|
4
4
|
Summary: OpenTelemetry Replicate instrumentation
|
|
5
5
|
Home-page: https://github.com/traceloop/openllmetry/tree/main/packages/opentelemetry-instrumentation-replicate
|
|
6
6
|
License: Apache-2.0
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"""OpenTelemetry Replicate instrumentation"""
|
|
2
|
+
|
|
2
3
|
import logging
|
|
3
4
|
import os
|
|
4
5
|
import types
|
|
5
6
|
from typing import Collection
|
|
7
|
+
from opentelemetry.instrumentation.replicate.config import Config
|
|
8
|
+
from opentelemetry.instrumentation.replicate.utils import dont_throw
|
|
6
9
|
from wrapt import wrap_function_wrapper
|
|
7
10
|
|
|
8
11
|
from opentelemetry import context as context_api
|
|
@@ -88,19 +91,7 @@ def _set_input_attributes(span, args, kwargs):
|
|
|
88
91
|
return
|
|
89
92
|
|
|
90
93
|
|
|
91
|
-
|
|
92
|
-
if response is None:
|
|
93
|
-
return
|
|
94
|
-
if isinstance(response, list):
|
|
95
|
-
for index, item in enumerate(response):
|
|
96
|
-
prefix = f"{SpanAttributes.LLM_COMPLETIONS}.{index}"
|
|
97
|
-
_set_span_attribute(span, f"{prefix}.content", item)
|
|
98
|
-
elif isinstance(response, str):
|
|
99
|
-
_set_span_attribute(
|
|
100
|
-
span, f"{SpanAttributes.LLM_COMPLETIONS}.0.content", response
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
|
|
94
|
+
@dont_throw
|
|
104
95
|
def _set_response_attributes(span, response):
|
|
105
96
|
if should_send_prompts():
|
|
106
97
|
if isinstance(response, list):
|
|
@@ -128,28 +119,17 @@ def _build_from_streaming_response(span, response):
|
|
|
128
119
|
span.end()
|
|
129
120
|
|
|
130
121
|
|
|
122
|
+
@dont_throw
|
|
131
123
|
def _handle_request(span, args, kwargs):
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
_set_input_attributes(span, args, kwargs)
|
|
135
|
-
|
|
136
|
-
except Exception as ex: # pylint: disable=broad-except
|
|
137
|
-
logger.warning(
|
|
138
|
-
"Failed to set input attributes for replicate span, error: %s", str(ex)
|
|
139
|
-
)
|
|
124
|
+
if span.is_recording():
|
|
125
|
+
_set_input_attributes(span, args, kwargs)
|
|
140
126
|
|
|
141
127
|
|
|
128
|
+
@dont_throw
|
|
142
129
|
def _handle_response(span, response):
|
|
143
|
-
try:
|
|
144
|
-
if span.is_recording():
|
|
145
|
-
_set_response_attributes(span, response)
|
|
146
|
-
|
|
147
|
-
except Exception as ex: # pylint: disable=broad-except
|
|
148
|
-
logger.warning(
|
|
149
|
-
"Failed to set response attributes for replicate span, error: %s",
|
|
150
|
-
str(ex),
|
|
151
|
-
)
|
|
152
130
|
if span.is_recording():
|
|
131
|
+
_set_response_attributes(span, response)
|
|
132
|
+
|
|
153
133
|
span.set_status(Status(StatusCode.OK))
|
|
154
134
|
|
|
155
135
|
|
|
@@ -198,6 +178,10 @@ def _wrap(tracer, to_wrap, wrapped, instance, args, kwargs):
|
|
|
198
178
|
class ReplicateInstrumentor(BaseInstrumentor):
|
|
199
179
|
"""An instrumentor for Replicate's client library."""
|
|
200
180
|
|
|
181
|
+
def __init__(self, exception_logger=None):
|
|
182
|
+
super().__init__()
|
|
183
|
+
Config.exception_logger = exception_logger
|
|
184
|
+
|
|
201
185
|
def instrumentation_dependencies(self) -> Collection[str]:
|
|
202
186
|
return _instruments
|
|
203
187
|
|
opentelemetry_instrumentation_replicate-0.16.6/opentelemetry/instrumentation/replicate/utils.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from opentelemetry.instrumentation.replicate.config import Config
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def dont_throw(func):
|
|
6
|
+
"""
|
|
7
|
+
A decorator that wraps the passed in function and logs exceptions instead of throwing them.
|
|
8
|
+
|
|
9
|
+
@param func: The function to wrap
|
|
10
|
+
@return: The wrapper function
|
|
11
|
+
"""
|
|
12
|
+
# Obtain a logger specific to the function's module
|
|
13
|
+
logger = logging.getLogger(func.__module__)
|
|
14
|
+
|
|
15
|
+
def wrapper(*args, **kwargs):
|
|
16
|
+
try:
|
|
17
|
+
return func(*args, **kwargs)
|
|
18
|
+
except Exception as e:
|
|
19
|
+
logger.warning("Failed to execute %s, error: %s", func.__name__, str(e))
|
|
20
|
+
if Config.exception_logger:
|
|
21
|
+
Config.exception_logger(e)
|
|
22
|
+
|
|
23
|
+
return wrapper
|
opentelemetry_instrumentation_replicate-0.16.6/opentelemetry/instrumentation/replicate/version.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.16.6"
|
|
@@ -8,7 +8,7 @@ show_missing = true
|
|
|
8
8
|
|
|
9
9
|
[tool.poetry]
|
|
10
10
|
name = "opentelemetry-instrumentation-replicate"
|
|
11
|
-
version = "0.16.
|
|
11
|
+
version = "0.16.6"
|
|
12
12
|
description = "OpenTelemetry Replicate instrumentation"
|
|
13
13
|
authors = [ "Kartik Prajapati <kartik@ktklab.org>" ]
|
|
14
14
|
repository = "https://github.com/traceloop/openllmetry/tree/main/packages/opentelemetry-instrumentation-replicate"
|
opentelemetry_instrumentation_replicate-0.16.5/opentelemetry/instrumentation/replicate/version.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.16.5"
|
|
File without changes
|