arize-phoenix 3.11.0__py3-none-any.whl → 3.12.0__py3-none-any.whl

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 arize-phoenix might be problematic. Click here for more details.

phoenix/trace/__init__.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import contextlib
2
2
  from typing import Iterator
3
3
 
4
+ from .projects import using_project
4
5
  from .span_evaluations import DocumentEvaluations, Evaluations, SpanEvaluations, TraceEvaluations
5
6
  from .trace_dataset import TraceDataset
6
7
 
@@ -10,6 +11,7 @@ __all__ = [
10
11
  "SpanEvaluations",
11
12
  "DocumentEvaluations",
12
13
  "TraceEvaluations",
14
+ "using_project",
13
15
  ]
14
16
 
15
17
 
@@ -0,0 +1,56 @@
1
+ import types
2
+ from typing import Any, Callable, Optional, Type
3
+
4
+ from openinference.semconv.resource import ResourceAttributes
5
+ from opentelemetry.sdk import trace
6
+ from opentelemetry.sdk.resources import Resource
7
+ from wrapt import wrap_function_wrapper
8
+
9
+
10
+ def project_override_wrapper(project_name: str) -> Callable[..., None]:
11
+ def wrapper(
12
+ wrapped: Any,
13
+ instance: "trace.ReadableSpan",
14
+ args: Any,
15
+ kwargs: Any,
16
+ ) -> None:
17
+ wrapped(*args, **kwargs)
18
+ instance._resource = Resource(
19
+ {
20
+ **instance._resource.attributes,
21
+ ResourceAttributes.PROJECT_NAME: project_name,
22
+ },
23
+ instance._resource.schema_url,
24
+ )
25
+
26
+ return wrapper
27
+
28
+
29
+ class using_project:
30
+ """
31
+ A context manager that switches the project for all spans created within the context.
32
+
33
+ This is useful for managing projects in notebook environments, however this should not be used
34
+ in production environments or complicated OpenTelemetry setups, as dynamically modifying the
35
+ span resource can lead to unexpected behavior.
36
+ """
37
+
38
+ def __init__(self, project_name: str) -> None:
39
+ self.project_name = project_name
40
+
41
+ def __enter__(self) -> None:
42
+ self.unwrapped_init: Optional[Callable[..., None]] = trace.ReadableSpan.__init__
43
+ wrap_function_wrapper(
44
+ module="opentelemetry.sdk.trace",
45
+ name="ReadableSpan.__init__",
46
+ wrapper=project_override_wrapper(self.project_name),
47
+ )
48
+
49
+ def __exit__(
50
+ self,
51
+ exc_type: Optional[Type[BaseException]],
52
+ exc_value: Optional[BaseException],
53
+ traceback: Optional[types.TracebackType],
54
+ ) -> None:
55
+ setattr(trace.ReadableSpan, "__init__", self.unwrapped_init)
56
+ self.unwrapped_init = None
phoenix/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "3.11.0"
1
+ __version__ = "3.12.0"