Skip to content

Commit f0a3224

Browse files
committed
restrucure a bit
1 parent e4bcc7b commit f0a3224

3 files changed

Lines changed: 756 additions & 307 deletions

File tree

langfuse/_client/constants.py

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,58 @@
33
This module defines constants used throughout the Langfuse OpenTelemetry integration.
44
"""
55

6-
import enum
7-
from typing import Literal
6+
from typing import Literal, List, get_args
87
from typing_extensions import TypeAlias
98

109
LANGFUSE_TRACER_NAME = "langfuse-sdk"
1110

1211

13-
class ObservationType(str, enum.Enum):
14-
"""Enumeration of valid observation types for Langfuse tracing.
15-
16-
This enum defines all the observation types that can be used with the @observe
17-
decorator and other Langfuse SDK methods.
18-
"""
19-
20-
SPAN = "SPAN"
21-
GENERATION = "GENERATION"
22-
AGENT = "AGENT"
23-
TOOL = "TOOL"
24-
CHAIN = "CHAIN"
25-
RETRIEVER = "RETRIEVER"
26-
EMBEDDING = "EMBEDDING"
27-
EVALUATOR = "EVALUATOR"
28-
GUARDRAIL = "GUARDRAIL"
29-
30-
31-
ObservationTypeLiteralNoEvent: TypeAlias = Literal[
32-
"span",
12+
ObservationTypeGenerationLike: TypeAlias = Literal[
3313
"generation",
3414
"agent",
3515
"tool",
3616
"chain",
3717
"retriever",
3818
"evaluator",
3919
"embedding",
40-
"guardrail",
4120
]
4221

22+
ObservationTypeLiteralNoEvent: TypeAlias = (
23+
ObservationTypeGenerationLike
24+
| Literal[
25+
"span",
26+
"guardrail",
27+
]
28+
)
29+
4330
ObservationTypeLiteral: TypeAlias = ObservationTypeLiteralNoEvent | Literal["event"]
31+
"""Enumeration of valid observation types for Langfuse tracing.
32+
33+
This Literal defines all available observation types that can be used with the @observe
34+
decorator and other Langfuse SDK methods.
35+
"""
36+
37+
38+
def get_observation_types_list(
39+
literal_type: ObservationTypeGenerationLike
40+
| ObservationTypeLiteralNoEvent
41+
| ObservationTypeLiteral,
42+
) -> List[str]:
43+
"""Flattens the Literal type to provide a list of strings.
44+
45+
Args:
46+
literal_type: A Literal type or union of Literals to flatten
47+
48+
Returns:
49+
Flat list of all string values contained in the Literal type
50+
"""
51+
result = []
52+
args = get_args(literal_type)
53+
54+
for arg in args:
55+
if hasattr(arg, "__args__"):
56+
result.extend(get_observation_types_list(arg))
57+
else:
58+
result.append(arg)
59+
60+
return result

0 commit comments

Comments
 (0)