arize-phoenix 3.10.0__py3-none-any.whl → 3.11.1__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.

@@ -6,6 +6,7 @@ from abc import ABC, abstractmethod
6
6
  from collections import UserList
7
7
  from datetime import datetime
8
8
  from enum import Enum
9
+ from importlib.util import find_spec
9
10
  from pathlib import Path
10
11
  from tempfile import TemporaryDirectory
11
12
  from typing import (
@@ -619,9 +620,11 @@ def _is_colab() -> bool:
619
620
 
620
621
  def _is_sagemaker() -> bool:
621
622
  """Determines whether this is in a SageMaker notebook"""
623
+ if find_spec("sagemaker") is None:
624
+ return False
622
625
  try:
623
- import sagemaker # type: ignore # noqa: F401
624
- except ImportError:
626
+ _get_sagemaker_notebook_base_url()
627
+ except Exception:
625
628
  return False
626
629
  try:
627
630
  from IPython.core.getipython import get_ipython
phoenix/trace/__init__.py CHANGED
@@ -1,3 +1,6 @@
1
+ import contextlib
2
+ from typing import Iterator
3
+
1
4
  from .span_evaluations import DocumentEvaluations, Evaluations, SpanEvaluations, TraceEvaluations
2
5
  from .trace_dataset import TraceDataset
3
6
 
@@ -8,3 +11,16 @@ __all__ = [
8
11
  "DocumentEvaluations",
9
12
  "TraceEvaluations",
10
13
  ]
14
+
15
+
16
+ @contextlib.contextmanager
17
+ def suppress_tracing() -> Iterator[None]:
18
+ """Context manager to pause OpenTelemetry instrumentation."""
19
+ try:
20
+ from opentelemetry.context import _SUPPRESS_INSTRUMENTATION_KEY, attach, detach, set_value
21
+ except ImportError:
22
+ yield
23
+ return
24
+ token = attach(set_value(_SUPPRESS_INSTRUMENTATION_KEY, True))
25
+ yield
26
+ detach(token)
phoenix/trace/exporter.py CHANGED
@@ -4,10 +4,9 @@ import weakref
4
4
  from queue import SimpleQueue
5
5
  from threading import Thread
6
6
  from types import MethodType
7
- from typing import Any, Optional, Union
7
+ from typing import Any, Optional
8
8
  from urllib.parse import urljoin
9
9
 
10
- import opentelemetry.proto.trace.v1.trace_pb2 as otlp
11
10
  import requests
12
11
  from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
13
12
  from requests import Session
@@ -15,15 +14,13 @@ from typing_extensions import TypeAlias, assert_never
15
14
 
16
15
  import phoenix.trace.v1 as pb
17
16
  from phoenix.config import get_env_collector_endpoint, get_env_host, get_env_port
18
- from phoenix.trace.otel import encode
19
- from phoenix.trace.schemas import Span
20
17
 
21
18
  logger = logging.getLogger(__name__)
22
19
  logger.addHandler(logging.NullHandler())
23
20
 
24
21
  END_OF_QUEUE = None # sentinel value for queue termination
25
22
 
26
- Message: TypeAlias = Union[otlp.Span, pb.Evaluation]
23
+ Message: TypeAlias = pb.Evaluation
27
24
 
28
25
 
29
26
  class NoOpExporter:
@@ -52,7 +49,7 @@ class HttpExporter:
52
49
  port: Optional[int] = None,
53
50
  ) -> None:
54
51
  """
55
- Span/Evaluation Exporter using HTTP.
52
+ Evaluation Exporter using HTTP.
56
53
 
57
54
  Parameters
58
55
  ----------
@@ -90,10 +87,8 @@ class HttpExporter:
90
87
  weakref.finalize(self, self._queue.put, END_OF_QUEUE)
91
88
  self._start_consumer()
92
89
 
93
- def export(self, item: Union[Span, pb.Evaluation]) -> None:
94
- if isinstance(item, Span):
95
- self._queue.put(encode(item))
96
- elif isinstance(item, pb.Evaluation):
90
+ def export(self, item: pb.Evaluation) -> None:
91
+ if isinstance(item, pb.Evaluation):
97
92
  self._queue.put(item)
98
93
  else:
99
94
  logger.exception(f"unrecognized item type: {type(item)}")
@@ -121,8 +116,6 @@ class HttpExporter:
121
116
  logger.exception(e)
122
117
 
123
118
  def _url(self, message: Message) -> str:
124
- if isinstance(message, otlp.Span):
125
- return urljoin(self._base_url, "/v1/spans")
126
119
  if isinstance(message, pb.Evaluation):
127
120
  return urljoin(self._base_url, "/v1/evaluations")
128
121
  logger.exception(f"unrecognized message type: {type(message)}")
@@ -1,26 +1,3 @@
1
- import sys
2
- from typing import Any
1
+ from phoenix.trace.langchain.instrumentor import LangChainInstrumentor
3
2
 
4
- import phoenix.trace.langchain.instrumentor as _instrumentor
5
- import phoenix.trace.langchain.tracer as _tracer
6
-
7
- _DUMMY = "OpenInferenceTracer"
8
-
9
-
10
- class _Deprecation:
11
- __all__ = ("LangChainInstrumentor", _DUMMY)
12
-
13
- def __getattr__(self, name: str) -> Any:
14
- if name == "tracer":
15
- return _tracer
16
- if name == "instrumentor":
17
- return _instrumentor
18
- if name == _DUMMY:
19
- return getattr(_tracer, name)
20
- if name == "LangChainInstrumentor":
21
- return _instrumentor.LangChainInstrumentor
22
- raise AttributeError(f"module {__name__} has no attribute {name}")
23
-
24
-
25
- # See e.g. https://stackoverflow.com/a/7668273
26
- sys.modules[__name__] = _Deprecation() # type: ignore
3
+ __all__ = ("LangChainInstrumentor",)
@@ -11,7 +11,6 @@ from opentelemetry.sdk.trace.export import SimpleSpanProcessor
11
11
 
12
12
  from phoenix.config import get_env_project_name
13
13
  from phoenix.trace.exporter import _OpenInferenceExporter
14
- from phoenix.trace.tracer import _show_deprecation_warnings
15
14
 
16
15
  logger = logging.getLogger(__name__)
17
16
 
@@ -21,7 +20,6 @@ __all__ = ("LangChainInstrumentor",)
21
20
 
22
21
  class LangChainInstrumentor(Instrumentor):
23
22
  def __init__(self, *args: Any, **kwargs: Any) -> None:
24
- _show_deprecation_warnings(self, *args, **kwargs)
25
23
  if find_spec("langchain_core") is None:
26
24
  raise PackageNotFoundError(
27
25
  "Missing `langchain-core`. Install with `pip install langchain-core`."
@@ -11,7 +11,6 @@ from opentelemetry.sdk.trace.export import SimpleSpanProcessor
11
11
  from phoenix.config import get_env_project_name
12
12
  from phoenix.trace.errors import IncompatibleLibraryVersionError
13
13
  from phoenix.trace.exporter import _OpenInferenceExporter
14
- from phoenix.trace.tracer import _show_deprecation_warnings
15
14
 
16
15
  logger = logging.getLogger(__name__)
17
16
 
@@ -95,7 +94,6 @@ class OpenInferenceTraceCallbackHandler(_OpenInferenceTraceCallbackHandler):
95
94
  """
96
95
 
97
96
  def __init__(self, *args: Any, **kwargs: Any) -> None:
98
- _show_deprecation_warnings(self, *args, **kwargs)
99
97
  tracer_provider = trace_sdk.TracerProvider(
100
98
  resource=Resource({ResourceAttributes.PROJECT_NAME: get_env_project_name()})
101
99
  )
@@ -11,14 +11,12 @@ from opentelemetry.sdk.trace.export import SimpleSpanProcessor
11
11
 
12
12
  from phoenix.config import get_env_project_name
13
13
  from phoenix.trace.exporter import _OpenInferenceExporter
14
- from phoenix.trace.tracer import _show_deprecation_warnings
15
14
 
16
15
  logger = logging.getLogger(__name__)
17
16
 
18
17
 
19
18
  class OpenAIInstrumentor(Instrumentor):
20
19
  def __init__(self, *args: Any, **kwargs: Any) -> None:
21
- _show_deprecation_warnings(self, *args, **kwargs)
22
20
  if find_spec("openai") is None:
23
21
  raise PackageNotFoundError("Missing `openai`. Install with `pip install openai`.")
24
22
  super().__init__()
phoenix/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "3.10.0"
1
+ __version__ = "3.11.1"
@@ -1,47 +0,0 @@
1
- """
2
- This module is defunct and will be removed in the future. It's currently
3
- maintaining a dummy class to avoid breaking any import code.
4
- """
5
-
6
- import logging
7
- import sys
8
- from typing import Any, Iterator
9
-
10
- from phoenix.trace.schemas import Span
11
-
12
- logger = logging.getLogger(__name__)
13
-
14
- _DUMMY = "OpenInferenceTracer"
15
- _DEPRECATION_MESSAGE = (
16
- f"`{__name__}.{_DUMMY}` is a defunct class in the current version of Phoenix, "
17
- "and will be removed in the future. For a migration guide, see "
18
- "https://github.com/Arize-ai/phoenix/blob/main/MIGRATION.md"
19
- )
20
-
21
-
22
- class _DummyObject:
23
- def __init__(self, *_: Any, **__: Any) -> None:
24
- logger.warning(_DEPRECATION_MESSAGE)
25
-
26
- def get_spans(self) -> Iterator[Span]:
27
- logger.warning(_DEPRECATION_MESSAGE)
28
- logger.warning(
29
- "`.get_spans()` is a defunct method that does nothing, and will be removed "
30
- "in the future. For a migration guide, see "
31
- "https://github.com/Arize-ai/phoenix/blob/main/MIGRATION.md"
32
- )
33
- return iter(())
34
-
35
-
36
- class _DefunctModule:
37
- __all__ = (_DUMMY,)
38
-
39
- def __getattr__(self, name: str) -> Any:
40
- if name == _DUMMY:
41
- logger.warning(_DEPRECATION_MESSAGE)
42
- return _DummyObject
43
- raise AttributeError(f"module {__name__} has no attribute {name}")
44
-
45
-
46
- # See e.g. https://stackoverflow.com/a/7668273
47
- sys.modules[__name__] = _DefunctModule() # type: ignore
phoenix/trace/tracer.py DELETED
@@ -1,99 +0,0 @@
1
- """
2
- This module is defunct and will be removed in the future. It's currently
3
- maintaining a dummy class to avoid breaking any import code.
4
- """
5
-
6
- import logging
7
- import sys
8
- from typing import Any, Iterator, Protocol
9
-
10
- from phoenix.trace.exporter import HttpExporter
11
-
12
- logger = logging.getLogger(__name__)
13
-
14
-
15
- class SpanExporter(Protocol):
16
- def export(self, _: Any) -> None: ...
17
-
18
-
19
- _DEFUNCT_MSG = (
20
- "`phoenix.trace.tracer.Tracer` is defunct in the current version of Phoenix, "
21
- "and will be removed in the future. For a migration guide, see "
22
- "https://github.com/Arize-ai/phoenix/blob/main/MIGRATION.md"
23
- )
24
-
25
- _USE_ENV_MSG = """
26
- Setting the Phoenix endpoint via HttpExporter() is no longer supported.
27
- Please use environment variables instead:
28
- - os.environ["PHOENIX_HOST"] = "127.0.0.1"
29
- - os.environ["PHOENIX_PORT"] = "54321"
30
- - os.environ["PHOENIX_COLLECTOR_ENDPOINT"] = "http://127.0.0.1:54321
31
- For a migration guide, see https://github.com/Arize-ai/phoenix/blob/main/MIGRATION.md
32
- """
33
-
34
- _ON_APPEND_DEPRECATION_MSG = (
35
- "OpenInference has been updated for full OpenTelemetry compliance. The ability to set "
36
- "`on_append` callbacks are removed. For a migration guide, see "
37
- "https://github.com/Arize-ai/phoenix/blob/main/MIGRATION.md"
38
- )
39
-
40
-
41
- def _show_deprecation_warnings(obj: object, *args: Any, **kwargs: Any) -> None:
42
- if args or kwargs:
43
- logger.warning(
44
- f"{obj.__class__.__name__}() no longer takes any arguments. "
45
- "The arguments provided has been ignored. For a migration guide, "
46
- "see https://github.com/Arize-ai/phoenix/blob/main/MIGRATION.md"
47
- )
48
- if any(callable(arg) for arg in args) or "callback" in kwargs:
49
- logger.warning(
50
- "The `callback` argument is defunct and no longer has any effect. "
51
- "If you need access to spans for processing, some options include "
52
- "exporting spans from Phoenix or adding a SpanProcessor to the "
53
- "OpenTelemetry TracerProvider. For a migration guide, "
54
- "see https://github.com/Arize-ai/phoenix/blob/main/MIGRATION.md"
55
- )
56
- if any(isinstance(arg, HttpExporter) for arg in args):
57
- logger.warning(_USE_ENV_MSG)
58
-
59
-
60
- class Tracer:
61
- _exporter: Any
62
-
63
- def __init__(self, exporter: Any = None, on_append: Any = None) -> None:
64
- logger.warning(_DEFUNCT_MSG)
65
- if exporter is not None:
66
- logger.warning(_USE_ENV_MSG)
67
- if on_append is not None:
68
- logger.warning(_ON_APPEND_DEPRECATION_MSG)
69
-
70
- def create_span(self, *_: Any, **__: Any) -> Any:
71
- logger.warning(_DEFUNCT_MSG)
72
-
73
- def get_spans(self) -> Iterator[Any]:
74
- logger.warning(_DEFUNCT_MSG)
75
- logger.warning(
76
- ".get_spans() is a defunct method that does nothing. "
77
- "It will be removed in the future. For a migration guide, "
78
- "see https://github.com/Arize-ai/phoenix/blob/main/MIGRATION.md"
79
- )
80
- return iter(())
81
-
82
-
83
- class _DefunctModule:
84
- __all__ = ("Tracer", "SpanExporter")
85
-
86
- def __getattr__(self, name: str) -> Any:
87
- if name == "Tracer":
88
- logger.warning(_DEFUNCT_MSG)
89
- return Tracer
90
- if name == "SpanExporter":
91
- logger.warning("`SpanExporter` is defunct and will be removed in the future.")
92
- return SpanExporter
93
- if name == "_show_deprecation_warnings":
94
- return _show_deprecation_warnings
95
- raise AttributeError(f"module {__name__} has no attribute {name}")
96
-
97
-
98
- # See e.g. https://stackoverflow.com/a/7668273
99
- sys.modules[__name__] = _DefunctModule() # type: ignore