Skip to content

Commit

Permalink
feat: add entrypoint for use in opentelemetry-instrument (#1278)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <[email protected]>
Co-authored-by: Nate Mar <[email protected]>
  • Loading branch information
codefromthecrypt and nate-mar authored Feb 11, 2025
1 parent e2e3dd1 commit 2106acf
Show file tree
Hide file tree
Showing 30 changed files with 245 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ instruments = [
"anthropic >= 0.30.0",
]

[project.entry-points.opentelemetry_instrumentor]
anthropic = "openinference.instrumentation.anthropic:AnthropicInstrumentor"

[project.urls]
Homepage = "https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-anthropic"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from opentelemetry.util._importlib_metadata import entry_points
from typing_extensions import assert_never
from wrapt import BoundFunctionWrapper

Expand Down Expand Up @@ -117,6 +118,19 @@ def setup_anthropic_instrumentation(
AnthropicInstrumentor().uninstrument()


class TestInstrumentor:
def test_entrypoint_for_opentelemetry_instrument(self) -> None:
(instrumentor_entrypoint,) = entry_points(
group="opentelemetry_instrumentor", name="anthropic"
)
instrumentor = instrumentor_entrypoint.load()()
assert isinstance(instrumentor, AnthropicInstrumentor)

# Ensure we're using the common OITracer from common openinference-instrumentation pkg
def test_oitracer(self, setup_anthropic_instrumentation: Any) -> None:
assert isinstance(AnthropicInstrumentor()._tracer, OITracer)


@pytest.mark.vcr(
decode_compressed_response=True,
before_record_request=remove_all_vcr_request_headers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ dependencies = [
instruments = [
"autogen >= 0.5.0",
]
test = [
"autogen>=0.5.0",
]

[project.entry-points.opentelemetry_instrumentor]
autogen = "openinference.instrumentation.autogen:AutogenInstrumentor"

[project.urls]
Homepage = "https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-autogen"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
def test() -> None:
return
from opentelemetry.util._importlib_metadata import entry_points

from openinference.instrumentation.autogen import AutogenInstrumentor


class TestInstrumentor:
def test_entrypoint_for_opentelemetry_instrument(self) -> None:
(instrumentor_entrypoint,) = entry_points(
group="opentelemetry_instrumentor", name="autogen"
)
instrumentor = instrumentor_entrypoint.load()()
assert isinstance(instrumentor, AutogenInstrumentor)
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ test = [
"pytest-vcr>=1.0.2",
]

[project.entry-points.opentelemetry_instrumentor]
bedrock = "openinference.instrumentation.bedrock:BedrockInstrumentor"

[project.urls]
Homepage = "https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-bedrock"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from opentelemetry.util._importlib_metadata import entry_points

from openinference.instrumentation import OITracer, using_attributes
from openinference.instrumentation.bedrock import (
Expand Down Expand Up @@ -108,9 +109,17 @@ def instrument(
in_memory_span_exporter.clear()


# Ensure we're using the common OITracer from common opeinference-instrumentation pkg
def test_oitracer() -> None:
assert isinstance(BedrockInstrumentor()._tracer, OITracer)
class TestInstrumentor:
def test_entrypoint_for_opentelemetry_instrument(self) -> None:
(instrumentor_entrypoint,) = entry_points(
group="opentelemetry_instrumentor", name="bedrock"
)
instrumentor = instrumentor_entrypoint.load()()
assert isinstance(instrumentor, BedrockInstrumentor)

# Ensure we're using the common OITracer from common openinference-instrumentation pkg
def test_oitracer(self) -> None:
assert isinstance(BedrockInstrumentor()._tracer, OITracer)


@pytest.mark.parametrize("use_context_attributes", [False, True])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ test = [
"vcrpy",
]

[project.entry-points.opentelemetry_instrumentor]
crewai = "openinference.instrumentation.crewai:CrewAIInstrumentor"

[project.urls]
Homepage = "https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-crewai"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from opentelemetry.util._importlib_metadata import entry_points
from opentelemetry.util.types import AttributeValue

from openinference.instrumentation import OITracer, using_attributes
Expand Down Expand Up @@ -45,14 +46,15 @@ def setup_crewai_instrumentation(
CrewAIInstrumentor().uninstrument()


# Ensure we're using the common OITracer from common opeinference-instrumentation pkg
def test_oitracer(
tracer_provider: TracerProvider,
in_memory_span_exporter: InMemorySpanExporter,
setup_crewai_instrumentation: Any,
) -> None:
in_memory_span_exporter.clear()
assert isinstance(CrewAIInstrumentor()._tracer, OITracer)
class TestInstrumentor:
def test_entrypoint_for_opentelemetry_instrument(self) -> None:
(instrumentor_entrypoint,) = entry_points(group="opentelemetry_instrumentor", name="crewai")
instrumentor = instrumentor_entrypoint.load()()
assert isinstance(instrumentor, CrewAIInstrumentor)

# Ensure we're using the common OITracer from common openinference-instrumentation pkg
def test_oitracer(self, setup_crewai_instrumentation: Any) -> None:
assert isinstance(CrewAIInstrumentor()._tracer, OITracer)


def test_crewai_instrumentation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ test = [
"litellm",
]

[project.entry-points.opentelemetry_instrumentor]
dspy = "openinference.instrumentation.dspy:DSPyInstrumentor"

[project.urls]
Homepage = "https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-dspy"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from opentelemetry.util._importlib_metadata import entry_points
from pytest import MonkeyPatch

from openinference.instrumentation import OITracer, using_attributes
Expand Down Expand Up @@ -98,8 +99,15 @@ def gemini_api_key(monkeypatch: MonkeyPatch) -> str:
return api_key


def test_oitracer() -> None:
assert isinstance(DSPyInstrumentor()._tracer, OITracer)
class TestInstrumentor:
def test_entrypoint_for_opentelemetry_instrument(self) -> None:
(instrumentor_entrypoint,) = entry_points(group="opentelemetry_instrumentor", name="dspy")
instrumentor = instrumentor_entrypoint.load()()
assert isinstance(instrumentor, DSPyInstrumentor)

# Ensure we're using the common OITracer from common openinference-instrumentation pkg
def test_oitracer(self) -> None:
assert isinstance(DSPyInstrumentor()._tracer, OITracer)


class TestLM:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ test = [
"responses",
]

[project.entry-points.opentelemetry_instrumentor]
groq = "openinference.instrumentation.groq:GroqInstrumentor"

[project.urls]
Homepage = "https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-groq"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from groq.types.completion_usage import CompletionUsage
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from opentelemetry.util._importlib_metadata import entry_points
from opentelemetry.util.types import AttributeValue

from openinference.instrumentation import OITracer, using_attributes
Expand Down Expand Up @@ -150,6 +151,17 @@ def _check_context_attributes(
assert attributes.get(LLM_PROMPT_TEMPLATE_VARIABLES, None)


class TestInstrumentor:
def test_entrypoint_for_opentelemetry_instrument(self) -> None:
(instrumentor_entrypoint,) = entry_points(group="opentelemetry_instrumentor", name="groq")
instrumentor = instrumentor_entrypoint.load()()
assert isinstance(instrumentor, GroqInstrumentor)

# Ensure we're using the common OITracer from common openinference-instrumentation pkg
def test_oitracer(self, setup_groq_instrumentation: Any) -> None:
assert isinstance(GroqInstrumentor()._tracer, OITracer)


def test_groq_instrumentation(
tracer_provider: TracerProvider,
in_memory_span_exporter: InMemorySpanExporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ instruments = [
"guardrails-ai",
]

[project.entry-points.opentelemetry_instrumentor]
guardrails = "openinference.instrumentation.guardrails:GuardrailsInstrumentor"

[project.urls]
Homepage = "https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-guardrails"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from opentelemetry.util._importlib_metadata import entry_points
from pydash.strings import words as _words

from openinference.instrumentation import OITracer
Expand Down Expand Up @@ -74,11 +75,17 @@ def setup_guardrails_instrumentation(
GuardrailsInstrumentor().uninstrument()


# Ensure we're using the common OITracer from common opeinference-instrumentation pkg
def test_oitracer(
setup_guardrails_instrumentation: Any,
) -> None:
assert isinstance(GuardrailsInstrumentor()._tracer, OITracer)
class TestInstrumentor:
def test_entrypoint_for_opentelemetry_instrument(self) -> None:
(instrumentor_entrypoint,) = entry_points(
group="opentelemetry_instrumentor", name="guardrails"
)
instrumentor = instrumentor_entrypoint.load()()
assert isinstance(instrumentor, GuardrailsInstrumentor)

# Ensure we're using the common OITracer from common openinference-instrumentation pkg
def test_oitracer(self, setup_guardrails_instrumentation: Any) -> None:
assert isinstance(GuardrailsInstrumentor()._tracer, OITracer)


@patch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ test = [
"pytest-recording",
]

[project.entry-points.opentelemetry_instrumentor]
haystack = "openinference.instrumentation.haystack:HaystackInstrumentor"

[project.urls]
Homepage = "https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-haystack"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from opentelemetry.trace import StatusCode
from opentelemetry.util._importlib_metadata import entry_points
from typing_extensions import TypeGuard

from openinference.instrumentation import OITracer, suppress_tracing, using_attributes
Expand Down Expand Up @@ -153,6 +154,19 @@ def setup_haystack_instrumentation(
HaystackInstrumentor().uninstrument()


class TestInstrumentor:
def test_entrypoint_for_opentelemetry_instrument(self) -> None:
(instrumentor_entrypoint,) = entry_points(
group="opentelemetry_instrumentor", name="haystack"
)
instrumentor = instrumentor_entrypoint.load()()
assert isinstance(instrumentor, HaystackInstrumentor)

# Ensure we're using the common OITracer from common openinference-instrumentation pkg
def test_oitracer(self, setup_haystack_instrumentation: Any) -> None:
assert isinstance(HaystackInstrumentor()._tracer, OITracer)


def test_haystack_instrumentation(
tracer_provider: TracerProvider,
in_memory_span_exporter: InMemorySpanExporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ test = [
"vcrpy",
]

[project.entry-points.opentelemetry_instrumentor]
instructor = "openinference.instrumentation.instructor:InstructorInstrumentor"

[project.urls]
Homepage = "https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-instructor"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from opentelemetry.util._importlib_metadata import entry_points
from pydantic import BaseModel

from openinference.instrumentation import OITracer
Expand Down Expand Up @@ -62,13 +63,17 @@ async def extract() -> UserInfo:
)


def test_oitracer(
tracer_provider: TracerProvider,
in_memory_span_exporter: InMemorySpanExporter,
setup_instructor_instrumentation: Any,
) -> None:
instructor_instrumentor = InstructorInstrumentor()
assert isinstance(instructor_instrumentor._tracer, OITracer)
class TestInstrumentor:
def test_entrypoint_for_opentelemetry_instrument(self) -> None:
(instrumentor_entrypoint,) = entry_points(
group="opentelemetry_instrumentor", name="instructor"
)
instrumentor = instrumentor_entrypoint.load()()
assert isinstance(instrumentor, InstructorInstrumentor)

# Ensure we're using the common OITracer from common openinference-instrumentation pkg
def test_oitracer(self, setup_instructor_instrumentation: Any) -> None:
assert isinstance(InstructorInstrumentor()._tracer, OITracer)


@pytest.mark.asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type-check = [
"langchain_core == 0.2.43",
]

[project.entry-points.opentelemetry_instrumentor]
langchain = "openinference.instrumentation.langchain:LangChainInstrumentor"

[project.urls]
Homepage = "https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-langchain"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from opentelemetry.semconv.trace import SpanAttributes as OTELSpanAttributes
from opentelemetry.trace import Span
from opentelemetry.util._importlib_metadata import entry_points
from respx import MockRouter

from openinference.instrumentation import using_attributes
from openinference.instrumentation.langchain import (
LangChainInstrumentor,
get_ancestor_spans,
get_current_span,
)
Expand All @@ -68,6 +70,15 @@
SUPPORTS_TEMPLATES = LANGCHAIN_VERSION < (0, 3, 0)


class TestInstrumentor:
def test_entrypoint_for_opentelemetry_instrument(self) -> None:
(instrumentor_entrypoint,) = entry_points(
group="opentelemetry_instrumentor", name="langchain"
)
instrumentor = instrumentor_entrypoint.load()()
assert isinstance(instrumentor, LangChainInstrumentor)


@pytest.mark.parametrize("is_async", [False, True])
async def test_get_current_span(
in_memory_span_exporter: InMemorySpanExporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ test = [
"tokenizers==0.20.3; python_version == '3.8'"
]

[project.entry-points.opentelemetry_instrumentor]
litellm = "openinference.instrumentation.litellm:LiteLLMInstrumentor"

[project.urls]
Homepage = "https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-litellm"

Expand Down
Loading

0 comments on commit 2106acf

Please sign in to comment.