Skip to content

Commit 1596ddd

Browse files
authored
feat(traces): add more observation types (#1290)
* init commit * Use as_type * clean * cleanup * cleanup * todo clarifty case sensitivity * format * revert * add test * lower case * fix lint * format * types * cleanup * fix test * update * update * fix cases * fix some more types * update SDK * fix types * add type checing isntructions * restore * restore 2 * restore * restore 3 * simplify * simplift * simplify * fix case * rearrange spans * restrucure a bit * cleanup * make mypy happy * py3.9 compat * happy mypy * cleanup * a bit more clean * cleanup * overload all the things * overload * rename spanwrapper to observation wrapper * don't update events * fix test * fix span * fix test * langchain * formatting * add langchain test * add core test * cleanup * add deprecation warning * fix types * change generation like and span like * fix * test format * from review * format * add generation-like test * chore: update auto gen SDK (#1300) * unrelated changes to generated sdk * also readme * reset * revert * revert * fix lint * fix tests * embedding correct attrs * fix typing * fix bug * fix mypy
1 parent 342efe9 commit 1596ddd

36 files changed

+4474
-636
lines changed

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ poetry install --all-extras
2121
poetry run pre-commit install
2222
```
2323

24+
### Type Checking
25+
26+
To run type checking on the langfuse package, run:
27+
```sh
28+
poetry run mypy langfuse --no-error-summary
29+
```
30+
2431
### Tests
2532

2633
#### Setup

langfuse/__init__.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,38 @@
22

33
from ._client import client as _client_module
44
from ._client.attributes import LangfuseOtelSpanAttributes
5+
from ._client.constants import ObservationTypeLiteral
56
from ._client.get_client import get_client
67
from ._client.observe import observe
7-
from ._client.span import LangfuseEvent, LangfuseGeneration, LangfuseSpan
8+
from ._client.span import (
9+
LangfuseEvent,
10+
LangfuseGeneration,
11+
LangfuseSpan,
12+
LangfuseAgent,
13+
LangfuseTool,
14+
LangfuseChain,
15+
LangfuseEmbedding,
16+
LangfuseEvaluator,
17+
LangfuseRetriever,
18+
LangfuseGuardrail,
19+
)
820

921
Langfuse = _client_module.Langfuse
1022

1123
__all__ = [
1224
"Langfuse",
1325
"get_client",
1426
"observe",
27+
"ObservationTypeLiteral",
1528
"LangfuseSpan",
1629
"LangfuseGeneration",
1730
"LangfuseEvent",
1831
"LangfuseOtelSpanAttributes",
32+
"LangfuseAgent",
33+
"LangfuseTool",
34+
"LangfuseChain",
35+
"LangfuseEmbedding",
36+
"LangfuseEvaluator",
37+
"LangfuseRetriever",
38+
"LangfuseGuardrail",
1939
]

langfuse/_client/attributes.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
from datetime import datetime
1515
from typing import Any, Dict, List, Literal, Optional, Union
1616

17+
from langfuse._client.constants import (
18+
ObservationTypeGenerationLike,
19+
ObservationTypeSpanLike,
20+
)
21+
1722
from langfuse._utils.serializer import EventSerializer
1823
from langfuse.model import PromptClient
1924
from langfuse.types import MapValue, SpanLevel
@@ -93,9 +98,12 @@ def create_span_attributes(
9398
level: Optional[SpanLevel] = None,
9499
status_message: Optional[str] = None,
95100
version: Optional[str] = None,
101+
observation_type: Optional[
102+
Union[ObservationTypeSpanLike, Literal["event"]]
103+
] = "span",
96104
) -> dict:
97105
attributes = {
98-
LangfuseOtelSpanAttributes.OBSERVATION_TYPE: "span",
106+
LangfuseOtelSpanAttributes.OBSERVATION_TYPE: observation_type,
99107
LangfuseOtelSpanAttributes.OBSERVATION_LEVEL: level,
100108
LangfuseOtelSpanAttributes.OBSERVATION_STATUS_MESSAGE: status_message,
101109
LangfuseOtelSpanAttributes.VERSION: version,
@@ -122,9 +130,10 @@ def create_generation_attributes(
122130
usage_details: Optional[Dict[str, int]] = None,
123131
cost_details: Optional[Dict[str, float]] = None,
124132
prompt: Optional[PromptClient] = None,
133+
observation_type: Optional[ObservationTypeGenerationLike] = "generation",
125134
) -> dict:
126135
attributes = {
127-
LangfuseOtelSpanAttributes.OBSERVATION_TYPE: "generation",
136+
LangfuseOtelSpanAttributes.OBSERVATION_TYPE: observation_type,
128137
LangfuseOtelSpanAttributes.OBSERVATION_LEVEL: level,
129138
LangfuseOtelSpanAttributes.OBSERVATION_STATUS_MESSAGE: status_message,
130139
LangfuseOtelSpanAttributes.VERSION: version,

0 commit comments

Comments
 (0)