-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(llm-observability): LangChain spans #176
Conversation
posthog/ai/langchain/callbacks.py
Outdated
if not run: | ||
return | ||
if isinstance(run, GenerationMetadata): | ||
log.warning(f"Run {run_id} is not a generation but attempted to be captured as a trace or span.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.warning(f"Run {run_id} is not a generation but attempted to be captured as a trace or span.") | |
log.warning(f"Run {run_id} is a generation, but attempted to be captured as a trace or span.") |
posthog/ai/langchain/callbacks.py
Outdated
run = self._pop_run_metadata(run_id) | ||
if not run: | ||
return | ||
if not isinstance(run, GenerationMetadata): | ||
log.warning(f"Run {run_id} is not a generation but attempted to be captured as a generation.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.warning(f"Run {run_id} is not a generation but attempted to be captured as a generation.") | |
log.warning(f"Run {run_id} is not a generation, but attempted to be captured as a generation.") |
posthog/ai/langchain/callbacks.py
Outdated
if parent_run_id is not None: | ||
event_properties["$ai_span_id"] = run_id | ||
event_properties["$ai_parent_id"] = parent_run_id | ||
event_properties["$ai_span_name"] = run.name | ||
else: | ||
event_properties["$ai_trace_name"] = run.name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one thing that gets me, should we be using $ai_span_id
and $ai_span_name
for both span and trace IDs/names after all? It feels pretty intuitive and definitely much simpler than somewhat duplicated properties (it'd be a breaking change, but it's a beta product)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about unifying them, too. Intuitively, I want to inherit $ai_generation
and $ai_trace
from $ai_span
, so it makes sense to use $ai_span_id
and $ai_span_name
on all LLM events. We still want to keep $ai_trace_id
and $ai_parent_id
, though.
So I propose renaming $ai_trace_name
(existing) to $ai_span_name
, keeping the naming unified across all three events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
posthog/ai/langchain/callbacks.py
Outdated
|
||
|
||
RunStorage = Dict[UUID, RunMetadata] | ||
RunMetadataUnion = Union[SpanMetadata, GenerationMetadata] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: A little redundant to suffix with Union
RunMetadataUnion = Union[SpanMetadata, GenerationMetadata] | |
RunMetadata = Union[SpanMetadata, GenerationMetadata] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, I've missed that. There was a naming conflict before haha. I'll fix it!
…hon into feat/langchain-spans
Problem
We want to capture the input and output of intermediary chains during agent workflows.
Changes
New fields:
$ai_parent_id
to capture a parent ID and build a tree.$ai_generation_id
to capture a generation ID and unify API.$ai_span_id
to capture an ID for a span.