Skip to content

Conversation

@langfuse-bot
Copy link
Collaborator

@langfuse-bot langfuse-bot commented Oct 17, 2025

Important

This pull request adds OpenTelemetry support to the Langfuse API, including new clients and data models for trace ingestion, and introduces a PromptType for distinguishing prompt types.

  • OpenTelemetry Support:
    • Adds OpentelemetryClient and AsyncOpentelemetryClient in opentelemetry/client.py for handling OpenTelemetry trace ingestion.
    • Introduces models for OpenTelemetry data: OtelAttribute, OtelAttributeValue, OtelResource, OtelResourceSpan, OtelScope, OtelScopeSpan, OtelSpan, OtelTraceResponse in opentelemetry/types.
    • Updates client.py to include OpentelemetryClient and AsyncOpentelemetryClient.
  • Prompt Enhancements:
    • Adds PromptType in prompts/types/prompt_type.py to distinguish between text and chat prompts.
    • Updates PromptMeta in prompts/types/prompt_meta.py to include PromptType field.

This description was created by Ellipsis for 6698b96. You can customize this summary. It will automatically update as commits are pushed.

Disclaimer: Experimental PR review

Greptile Overview

Updated On: 2025-10-17 14:09:34 UTC

Summary

This PR updates the auto-generated API client to add native OpenTelemetry (OTLP/HTTP) trace ingestion support and enhance prompt type handling.

Key Changes

  • New OpenTelemetry Integration: Added complete OTLP/HTTP specification-compliant trace ingestion endpoint at /api/public/otel/v1/traces with 8 new type definitions (OtelSpan, OtelAttribute, OtelResourceSpan, etc.)
  • Enhanced Type Safety: Introduced explicit PromptType enum (chat/text) with visitor pattern support for better type discrimination in prompt metadata
  • Improved Documentation: Updated deprecated ingestion endpoint references to point to correct OTel path and added comprehensive API documentation with usage examples
  • Backward Compatible: All changes are additive - existing functionality remains unchanged, new opentelemetry client property added to both sync and async API clients

Integration Points

The new OTel types integrate with the existing SDK's OpenTelemetry implementation in langfuse/_client/ which already uses OTel spans internally. This API update provides the HTTP endpoint for external OTel-compliant telemetry systems to send traces directly to Langfuse.

Code Quality

All files are auto-generated by Fern from the OpenAPI specification, following consistent patterns with proper Pydantic models, error handling, and both sync/async support.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk as it consists of auto-generated API client code that is purely additive
  • Score of 5 reflects that all changes are auto-generated from a validated OpenAPI spec, follow established patterns, are purely additive (no breaking changes), include comprehensive error handling, and maintain backward compatibility. The new OTel endpoint implements a well-defined standard (OTLP/HTTP), and the PromptType enum addition improves type safety without affecting existing code.
  • No files require special attention - all changes are auto-generated and follow consistent patterns

Important Files Changed

File Analysis

Filename Score Overview
langfuse/api/client.py 5/5 Added opentelemetry client property to sync and async clients for OTel trace ingestion
langfuse/api/resources/ingestion/client.py 5/5 Updated deprecated endpoint documentation to reference correct OTel path /api/public/otel/v1/traces
langfuse/api/resources/opentelemetry/client.py 5/5 New client implementing OTLP/HTTP trace export endpoint with sync and async support
langfuse/api/resources/opentelemetry/types/otel_span.py 5/5 Pydantic model for individual OTel spans with trace/span IDs, timestamps, and Langfuse-specific attributes
langfuse/api/resources/prompts/types/prompt_type.py 5/5 New enum defining prompt types (chat/text) with visitor pattern support

Sequence Diagram

sequenceDiagram
    participant Client as SDK Client
    participant OTelClient as OpentelemetryClient
    participant API as Langfuse API
    participant Backend as Langfuse Backend

    Note over Client,Backend: New OpenTelemetry Trace Ingestion Flow

    Client->>OTelClient: export_traces(resource_spans)
    Note over Client,OTelClient: resource_spans contain:<br/>- OtelResourceSpan<br/>- OtelResource (attributes)<br/>- OtelScopeSpan<br/>- OtelSpan (trace data)
    
    OTelClient->>API: POST /api/public/otel/v1/traces
    Note over OTelClient,API: JSON: {"resourceSpans": [...]}
    
    API->>Backend: Process OTLP trace data
    Note over API,Backend: Maps OTel spans to<br/>Langfuse observations
    
    Backend-->>API: Processing complete
    API-->>OTelClient: 200 OK
    Note over API,OTelClient: Returns OtelTraceResponse<br/>(empty object on success)
    
    OTelClient-->>Client: OtelTraceResponse
    
    Note over Client,Backend: Legacy Ingestion (Deprecated)
    Client->>API: POST /api/public/ingestion
    Note over Client,API: Old endpoint still supported<br/>but deprecated
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

20 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

</dl>
</details>

## Opentelemetry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: The header currently reads ## Opentelemetry. It should likely be corrected to ## OpenTelemetry to match the standard naming used later in the documentation.

Suggested change
## Opentelemetry
## OpenTelemetry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants