mirascope.integrations.otel¶
configure
¶
Configures the OpenTelemetry tracer, this function should only be called once.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
processors |
Sequence[SpanProcessor] | None
|
Optional[Sequence[SpanProcessor]] The span processors to use, if None, a console exporter will be used. |
None
|
Returns:
Type | Description |
---|---|
Tracer
|
The configured tracer. |
Source code in mirascope/integrations/otel/_utils.py
with_otel
¶
Wraps a Mirascope function with OpenTelemetry.
Example:
from mirascope.core import anthropic, prompt_template
from mirascope.integrations.otel import with_otel, configure
configure()
def format_book(title: str, author: str) -> str:
return f"{title} by {author}"
@with_otel()
@anthropic.call(model="claude-3-5-sonnet-20240620", tools=[format_book])
def recommend_book(genre: str) -> str:
return f"Recommend a {genre} book"
print(recommend_book("fantasy"))
Source code in mirascope/integrations/otel/_with_otel.py
with_hyperdx
¶
Decorator to wrap a function with hyperdx.
Example:
import os
from mirascope.core import anthropic, prompt_template
from mirascope.integrations.otel import with_hyperdx
os.environ["HYPERDX_API_KEY"] = "YOUR_API_KEY"
def format_book(title: str, author: str):
return f"{title} by {author}"
@with_hyperdx()
@anthropic.call(model="claude-3-5-sonnet-20240620", tools=[format_book])
def recommend_book(genre: str) -> str:
return f"Recommend a {genre} book"
print(recommend_book("fantasy"))