Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions src/splunk_ao/agent_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def create(self) -> AgentStream:
Examples
--------
agent_stream = AgentStream(name="Production Logs", project_name="My AI Project").create()
assert log_stream.is_synced()
assert agent_stream.is_synced()
"""
if not self.name:
raise ValueError("Log stream name is not set. Cannot create log stream without a name.")
Expand Down Expand Up @@ -330,16 +330,16 @@ def list(
Examples
--------
# List by project name
log_streams = AgentStream.list(project_name="My AI Project")
agent_streams = AgentStream.list(project_name="My AI Project")

# List by project ID
log_streams = AgentStream.list(project_id="project-123")
agent_streams = AgentStream.list(project_id="project-123")

# List using SPLUNK_AO_PROJECT environment variable
log_streams = AgentStream.list()
agent_streams = AgentStream.list()

# Cap the number of returned log streams
log_streams = AgentStream.list(project_name="My AI Project", limit=3)
# Cap the number of returned agent streams
agent_streams = AgentStream.list(project_name="My AI Project", limit=3)

# Fetch the next page
page_2 = AgentStream.list(project_name="My AI Project", starting_token=100)
Expand Down Expand Up @@ -371,8 +371,8 @@ def refresh(self) -> None:

Examples
--------
log_stream.refresh()
assert log_stream.is_synced()
agent_stream.refresh()
assert agent_stream.is_synced()
"""
if self.id is None:
raise ValueError("Log stream ID is not set. Cannot refresh a local-only log stream.")
Expand Down Expand Up @@ -530,14 +530,14 @@ def query(
agent_stream = AgentStream.get(name="Production Logs", project_name="My AI Project")

# Query with column-based filters and sort
results = log_stream.query(
results = agent_stream.query(
record_type=RecordType.SPAN,
filters=[
log_stream.span_columns["input"].contains("largest"),
log_stream.span_columns["metrics/completeness_gpt"].greater_than(0.8),
log_stream.span_columns["created_at"].after("2024-01-01")
agent_stream.span_columns["input"].contains("largest"),
agent_stream.span_columns["metrics/completeness_gpt"].greater_than(0.8),
agent_stream.span_columns["created_at"].after("2024-01-01")
],
sort=log_stream.span_columns["created_at"].descending(),
sort=agent_stream.span_columns["created_at"].descending(),
limit=50
)

Expand Down Expand Up @@ -626,12 +626,12 @@ def get_spans(
agent_stream = AgentStream.get(name="Production Logs", project_name="My AI Project")

# Get spans with filters and sorting
spans = log_stream.get_spans(
spans = agent_stream.get_spans(
filters=[
log_stream.span_columns["input"].contains("world"),
log_stream.span_columns["metrics/num_input_tokens"].greater_than(10)
agent_stream.span_columns["input"].contains("world"),
agent_stream.span_columns["metrics/num_input_tokens"].greater_than(10)
],
sort=log_stream.span_columns["created_at"].descending(),
sort=agent_stream.span_columns["created_at"].descending(),
limit=50
)

Expand Down Expand Up @@ -679,12 +679,12 @@ def get_traces(
agent_stream = AgentStream.get(name="Production Logs", project_name="My AI Project")

# Get traces with filters
traces = log_stream.get_traces(
traces = agent_stream.get_traces(
filters=[
log_stream.trace_columns["input"].contains("largest"),
log_stream.trace_columns["created_at"].after("2024-01-01")
agent_stream.trace_columns["input"].contains("largest"),
agent_stream.trace_columns["created_at"].after("2024-01-01")
],
sort=log_stream.trace_columns["created_at"].descending(),
sort=agent_stream.trace_columns["created_at"].descending(),
limit=50
)

Expand Down Expand Up @@ -728,12 +728,12 @@ def get_sessions(
agent_stream = AgentStream.get(name="Production Logs", project_name="My AI Project")

# Get sessions with filters
sessions = log_stream.get_sessions(
sessions = agent_stream.get_sessions(
filters=[
log_stream.session_columns["model"].equals("gpt-4o-mini"),
log_stream.session_columns["metrics/num_traces"].greater_than(5)
agent_stream.session_columns["model"].equals("gpt-4o-mini"),
agent_stream.session_columns["metrics/num_traces"].greater_than(5)
],
sort=log_stream.session_columns["created_at"].descending(),
sort=agent_stream.session_columns["created_at"].descending(),
limit=50
)

Expand Down Expand Up @@ -784,13 +784,13 @@ def export_records(
agent_stream = AgentStream.get(name="Production Logs", project_name="My AI Project")

# Export records with filters
for record in log_stream.export_records(
for record in agent_stream.export_records(
record_type=RecordType.SPAN,
filters=[
log_stream.span_columns["model"].one_of(["gpt-4", "gpt-3.5-turbo", "gpt-4o-mini"]),
log_stream.span_columns["metrics/num_input_tokens"].greater_than(1)
agent_stream.span_columns["model"].one_of(["gpt-4", "gpt-3.5-turbo", "gpt-4o-mini"]),
agent_stream.span_columns["metrics/num_input_tokens"].greater_than(1)
],
sort=log_stream.span_columns["created_at"].descending()
sort=agent_stream.span_columns["created_at"].descending()
):
print(record)
"""
Expand Down Expand Up @@ -836,7 +836,7 @@ def context(self) -> Any:
project_name="My AI Project"
)

with log_stream.context():
with agent_stream.context():
# Your logging code here
response = openai_client.chat.completions.create(...)
"""
Expand Down Expand Up @@ -879,13 +879,13 @@ def span_columns(self) -> ColumnCollection:
Examples
--------
agent_stream = AgentStream.get(name="Production Logs", project_name="My AI Project")
columns = log_stream.span_columns
columns = agent_stream.span_columns

# Access a specific column
input_column = columns["input"]

# Filter using columns
spans = log_stream.get_spans(
spans = agent_stream.get_spans(
filters=[columns["input"].contains("world")],
sort=columns["created_at"].descending()
)
Expand All @@ -912,13 +912,13 @@ def session_columns(self) -> ColumnCollection:
Examples
--------
agent_stream = AgentStream.get(name="Production Logs", project_name="My AI Project")
columns = log_stream.session_columns
columns = agent_stream.session_columns

# Access a specific column
model_column = columns["model"]

# Filter using columns
sessions = log_stream.get_sessions(
sessions = agent_stream.get_sessions(
filters=[columns["model"].equals("gpt-4o-mini")],
sort=columns["created_at"].descending()
)
Expand Down Expand Up @@ -946,13 +946,13 @@ def trace_columns(self) -> ColumnCollection:
Examples
--------
agent_stream = AgentStream.get(name="Production Logs", project_name="My AI Project")
columns = log_stream.trace_columns
columns = agent_stream.trace_columns

# Access a specific column
input_column = columns["input"]

# Filter using columns
traces = log_stream.get_traces(
traces = agent_stream.get_traces(
filters=[columns["input"].contains("largest")],
sort=columns["created_at"].descending()
)
Expand Down
8 changes: 4 additions & 4 deletions src/splunk_ao/agent_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ class AgentStream(LogStreamResponse):
from splunk_ao.agent_streams import get_agent_stream
agent_stream = get_agent_stream(name="Production Logs", project_name="My AI Project")

# List all log streams in a project
# List all agent streams in a project
from splunk_ao.agent_streams import list_agent_streams
log_streams = list_agent_streams(project_name="My AI Project")
for stream in log_streams:
logger.info(f"Log Stream: {stream.name} (ID: {stream.id})")
agent_streams = list_agent_streams(project_name="My AI Project")
for stream in agent_streams:
logger.info(f"Agent Stream: {stream.name} (ID: {stream.id})")

# Use a log stream with the context manager
from splunk_ao.openai import openai
Expand Down
30 changes: 15 additions & 15 deletions src/splunk_ao/decorator.py
Comment thread
etserend marked this conversation as resolved.
Comment thread
etserend marked this conversation as resolved.
Comment thread
etserend marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ def __call__(
----------
project
The project name to use for this context
agent_stream: The log stream name to use for this context
The log stream name to use for this context
agent_stream
The agent stream name to use for this context
experiment_id
The experiment ID to use for this context
mode
Expand Down Expand Up @@ -1209,18 +1209,18 @@ def get_logger_instance(
Optional project name to use
project_id
Optional project ID to use
log_stream
Optional log stream name to use
log_stream_id
Optional log stream ID to use
agent_stream
Optional agent stream name to use
agent_stream_id
Optional agent stream ID to use
experiment_id
Optional experiment ID to use
mode
Optional logger mode to use

Returns
-------
SplunkAOLogger instance configured with the specified project and log stream
SplunkAOLogger instance configured with the specified project and agent stream
"""
kwargs = {
"project": project if project is not None else (None if project_id is not None else _project_context.get()),
Expand Down Expand Up @@ -1309,16 +1309,16 @@ def flush(
on_error: Callable[[Exception], None] | None = None,
) -> None:
"""
Upload all captured traces under a project and log stream context to Splunk AO.
Upload all captured traces under a project and agent stream context to Splunk AO.

If no project or log stream is provided, then the currently initialized context is used.
If no project or agent stream is provided, then the currently initialized context is used.

Parameters
----------
project
The project name. Defaults to None.
log_stream
The log stream name. Defaults to None.
agent_stream
The agent stream name. Defaults to None.
experiment_id
The experiment ID. Defaults to None.
mode
Expand Down Expand Up @@ -1401,18 +1401,18 @@ def init(
mode: str | None = None,
) -> None:
"""
Initialize the context with a project and log stream. Optionally, it can also be used
Initialize the context with a project and agent stream. Optionally, it can also be used
to start a trace.

This method resets the existing active context with a new context with
the specified project and log stream.
the specified project and agent stream.

Parameters
----------
project
The project name. Defaults to None.
log_stream
The log stream name. Defaults to None.
agent_stream
The agent stream name. Defaults to None.
experiment_id
The experiment id. Defaults to None.
local_metrics
Expand Down
26 changes: 13 additions & 13 deletions src/splunk_ao/utils/singleton.py
Comment thread
etserend marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SplunkAOLoggerSingleton:

This class ensures that only one instance exists across the application and
provides a thread-safe way to retrieve or create SplunkAOLogger clients based on
the given 'project' and 'log_stream' parameters. If the parameters are not provided,
the given 'project' and 'agent_stream' parameters. If the parameters are not provided,
the class attempts to read the values from the environment variables
SPLUNK_AO_PROJECT and SPLUNK_AO_AGENT_STREAM. The loggers are stored in a dictionary
using a tuple (project, agent_stream) as the key.
Expand Down Expand Up @@ -165,16 +165,16 @@ def get(
"""
Retrieve an existing SplunkAOLogger or create a new one if it does not exist.

This method first computes the key from the project and log_stream parameters,
This method first computes the key from the project and agent_stream parameters,
checks if a logger exists in the cache, and if not, creates a new SplunkAOLogger.
The creation and caching are done in a thread-safe manner.

Parameters
----------
project (Optional[str], optional)
The project name. Defaults to None.
log_stream (Optional[str], optional)
The log stream name. Defaults to None.
agent_stream (Optional[str], optional)
The agent stream name. Defaults to None.
experiment_id (Optional[str], optional)
The experiment ID. Defaults to None.
local_metrics (Optional[list[LocalScorerConfig]], optional)
Expand Down Expand Up @@ -252,10 +252,10 @@ def reset(
The project name. Defaults to None.
project_id (Optional[str], optional)
The project ID. Defaults to None.
log_stream (Optional[str], optional)
The log stream name. Defaults to None.
log_stream_id (Optional[str], optional)
The log stream ID. Defaults to None.
agent_stream (Optional[str], optional)
The agent stream name. Defaults to None.
agent_stream_id (Optional[str], optional)
The agent stream ID. Defaults to None.
experiment_id (Optional[str], optional)
The experiment ID. Defaults to None.
mode (Optional[str], optional)
Expand Down Expand Up @@ -297,7 +297,7 @@ def flush(
"""
Flush (upload and clear) a SplunkAOLogger instance.

If both project and log_stream are None, then all cached loggers are flushed
If both project and agent_stream are None, then all cached loggers are flushed
and cleared. Otherwise, only the specific logger corresponding to the provided
key (project, agent_stream) is flushed and removed.

Expand All @@ -307,10 +307,10 @@ def flush(
The project name. Defaults to None.
project_id (Optional[str], optional)
The project ID. Defaults to None.
log_stream (Optional[str], optional)
The log stream name. Defaults to None.
log_stream_id (Optional[str], optional)
The log stream ID. Defaults to None.
agent_stream (Optional[str], optional)
The agent stream name. Defaults to None.
agent_stream_id (Optional[str], optional)
The agent stream ID. Defaults to None.
experiment_id (Optional[str], optional)
The experiment ID. Defaults to None.
mode (Optional[str], optional)
Expand Down
Loading