org.llm4s.trace.LangfuseTracing
See theLangfuseTracing companion object
class LangfuseTracing(langfuseUrl: String, publicKey: String, secretKey: String, environment: String, release: String, version: String) extends Tracing
Langfuse Tracing implementation for production observability.
Sends trace events to Langfuse for centralized observability, debugging, and LLM application monitoring. Supports all trace event types with type-safe Result[Unit] return values.
== Features ==
- Real-time event streaming to Langfuse
- Hierarchical trace structure (traces with child spans)
- Token usage and cost tracking
- Error logging with stack traces
- Agent state snapshots with conversation history
== Configuration ==
Configure via environment variables or direct instantiation:
// Environment variables
LANGFUSE_PUBLIC_KEY=pk-lf-...
LANGFUSE_SECRET_KEY=sk-lf-...
LANGFUSE_URL=https://cloud.langfuse.com (optional)
// Or programmatic configuration
val tracing = new LangfuseTracing(
langfuseUrl = "https://cloud.langfuse.com",
publicKey = "pk-lf-...",
secretKey = "sk-lf-...",
environment = "production",
release = "1.0.0",
version = "1.0.0"
)
== Usage ==
val tracing: Tracing = LangfuseTracing.from(config)
for {
_ <- tracing.traceEvent(TraceEvent.AgentInitialized("query", tools))
_ <- tracing.traceCompletion(completion, "gpt-4")
_ <- tracing.traceTokenUsage(usage, "gpt-4", "completion")
} yield ()
Value parameters
- environment
-
Environment name (e.g., "production", "staging")
- langfuseUrl
-
Langfuse API URL (default: https://cloud.langfuse.com)
- publicKey
-
Langfuse public key for authentication
- release
-
Release/version identifier
- secretKey
-
Langfuse secret key for authentication
- version
-
API version
Attributes
- See also
-
ConsoleTracing for local development
NoOpTracing for disabled tracing
TracingMode for configuration modes
- Companion
- object
- Graph
-
- Supertypes
Members list
In this article