|
| 1 | +# CONTRIBUTORS.md |
| 2 | + |
| 3 | +This file provides guidance for contributors and AI agents working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is an unofficial Elixir SDK for Langfuse, an open-source LLM observability platform. The SDK provides tracing capabilities for LLM applications, allowing developers to create traces, events, spans, generations, and scores. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +### Dependencies and Setup |
| 12 | +```bash |
| 13 | +mix deps.get # Install dependencies |
| 14 | +``` |
| 15 | + |
| 16 | +### Testing |
| 17 | +```bash |
| 18 | +mix test # Run all tests |
| 19 | +mix test test/specific_test.exs # Run specific test file |
| 20 | +``` |
| 21 | + |
| 22 | +### OpenAPI Code Generation |
| 23 | +```bash |
| 24 | +mix sdk.build # Regenerate API client from OpenAPI spec |
| 25 | +mix spec.sync # Download latest OpenAPI spec from Langfuse |
| 26 | +mix api.gen default openapi.yml # Generate client code from spec |
| 27 | +``` |
| 28 | + |
| 29 | +### Documentation |
| 30 | +```bash |
| 31 | +mix docs # Generate documentation |
| 32 | +``` |
| 33 | + |
| 34 | +## Architecture |
| 35 | + |
| 36 | +### Core Structure |
| 37 | +- `LangfuseSdk` - Main module providing `create/1`, `update/1`, `create_many/1` functions |
| 38 | +- `LangfuseSdk.Ingestor` - Handles API payload transformation and ingestion |
| 39 | +- `LangfuseSdk.Tracing.*` - Domain models (Trace, Event, Span, Generation, Score) |
| 40 | +- `LangfuseSdk.Support.*` - Utilities for auth, client, media handling, value translation |
| 41 | +- `LangfuseSdk.Generated.*` - Auto-generated API client code from OpenAPI spec |
| 42 | + |
| 43 | +### Generated Code |
| 44 | +The `lib/langfuse_sdk/generated/` directory contains auto-generated code from the Langfuse OpenAPI specification. This includes: |
| 45 | +- `operations/` - API endpoint functions |
| 46 | +- `schemas/` - Data structure definitions |
| 47 | + |
| 48 | +**Important**: Only regenerate this code when updating to a new API version, as it may introduce breaking changes. |
| 49 | + |
| 50 | +### Tracing Models |
| 51 | +The SDK supports five main tracing entities: |
| 52 | +- **Trace** - Top-level container for LLM application execution |
| 53 | +- **Event** - Point-in-time occurrences within a trace |
| 54 | +- **Span** - Time-bounded operations within a trace |
| 55 | +- **Generation** - LLM API calls (supports image inputs via media handling) |
| 56 | +- **Score** - Evaluation metrics for traces or observations |
| 57 | + |
| 58 | +### Media Support |
| 59 | +Generations support image inputs through automatic URL replacement handled by `LangfuseSdk.Support.Media`. |
| 60 | + |
| 61 | +### Configuration |
| 62 | +Set environment variables or config: |
| 63 | +```elixir |
| 64 | +config :langfuse_sdk, |
| 65 | + host: System.get_env("LANGFUSE_HOST"), |
| 66 | + secret_key: System.get_env("LANGFUSE_SECRET_KEY"), |
| 67 | + public_key: System.get_env("LANGFUSE_PUBLIC_KEY") |
| 68 | +``` |
| 69 | + |
| 70 | +## Code Generation Workflow |
| 71 | + |
| 72 | +When updating the SDK to match a new Langfuse API version: |
| 73 | +1. Run `mix spec.sync` to download latest OpenAPI spec |
| 74 | +2. Run `mix api.gen default openapi.yml` to regenerate client code |
| 75 | +3. Test thoroughly as this may introduce breaking changes |
| 76 | +4. Update any custom code that depends on generated schemas/operations |
| 77 | + |
| 78 | +--- |
| 79 | + |
| 80 | +## Instructions for AI Agents |
| 81 | + |
| 82 | +This section provides specific guidance for AI agents (Claude Code, etc.) working in this repository. |
| 83 | + |
| 84 | +### Agent Guidelines |
| 85 | +- Always use the TodoWrite tool to plan and track multi-step tasks |
| 86 | +- Follow the existing code conventions and patterns in the codebase |
| 87 | +- Check dependencies in `mix.exs` before introducing new libraries |
| 88 | +- Use `mix test` to verify changes work correctly |
| 89 | +- For OpenAPI regeneration, use `mix sdk.build` - but only when updating API versions |
| 90 | + |
| 91 | +### Important Notes for Agents |
| 92 | +- The `lib/langfuse_sdk/generated/` directory is auto-generated from OpenAPI specs |
| 93 | +- Do not manually edit files in the `generated/` directory |
| 94 | +- Generations support image inputs via automatic URL replacement (see `LangfuseSdk.Support.Media`) |
| 95 | +- The main API entry points are `LangfuseSdk.create/1`, `LangfuseSdk.update/1`, and `LangfuseSdk.create_many/1` |
| 96 | +- Configuration requires `LANGFUSE_HOST`, `LANGFUSE_SECRET_KEY`, and `LANGFUSE_PUBLIC_KEY` environment variables |
| 97 | + |
| 98 | +### Testing Approach |
| 99 | +- Run `mix test` for all tests |
| 100 | +- Use `mix test test/specific_test.exs` for individual test files |
| 101 | +- Test files are located in `test/` with support files in `test/support/` |
| 102 | + |
| 103 | +### When Making Changes |
| 104 | +1. Understand the tracing model hierarchy: Trace → Event/Span/Generation → Score |
| 105 | +2. Check `LangfuseSdk.Ingestor` for payload transformation logic |
| 106 | +3. Verify changes don't break the OpenAPI-generated client interface |
| 107 | +4. Test with real Langfuse instances when possible |
0 commit comments