Skip to content
Open
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
13 changes: 12 additions & 1 deletion langfuse/_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,18 @@ def update_current_generation(
current_otel_span = self._get_current_otel_span()

if current_otel_span is not None:
generation = LangfuseGeneration(
# Keep a generation-like type such as "embedding"; other types
# become "generation" so that model and usage are recorded.
observation_type = self._get_observation_type_from_otel_span(
current_otel_span
)
generation_class = (
self._get_span_class(observation_type)
if observation_type
in get_observation_types_list(ObservationTypeGenerationLike)
else LangfuseGeneration
)
generation = generation_class(
otel_span=current_otel_span, langfuse_client=self
)

Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_observe.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ async def guardrail_check() -> bool:
}


def test_capture_output_false_preserves_embedding_type_when_current_generation_is_updated(
langfuse_memory_client: Any, memory_exporter: Any
) -> None:
@observe(name="embed_text", as_type="embedding", capture_output=False)
def embed_text() -> list[float]:
langfuse_memory_client.update_current_generation(
model="text-embedding-3-small", usage_details={"input": 5}
)
return [0.1, 0.2]

embed_text()

langfuse_memory_client.flush()

embedding_span = _finished_spans_by_name(memory_exporter, "embed_text")[0]
attributes = embedding_span.attributes

assert attributes[LangfuseOtelSpanAttributes.OBSERVATION_TYPE] == "embedding"
assert (
attributes[LangfuseOtelSpanAttributes.OBSERVATION_MODEL]
== "text-embedding-3-small"
)


def test_sync_generator_preserves_context_without_output_capture(
langfuse_memory_client: Any, memory_exporter: Any
) -> None:
Expand Down