Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ POSTGRES_URL=POSTGRES_URL=postgresql://localhost:5432/apollo_dev
SENTRY_DSN=YOUR-API-KEY-HERE
GITHUB_TOKEN=KEY

# Langfuse observability
LANGFUSE_SECRET_KEY=sk-lf-...
LANGFUSE_PUBLIC_KEY=pk-lf-...
LANGFUSE_BASE_URL=https://cloud.langfuse.com

# HF_ACCESS_TOKEN=hf_YOUR-API-KEY-HERE # llama2 base
# ZILLIZ_URI = https://in01-XXXXXXXXXXXXX.aws-us-west-2.vectordb.zillizcloud.com:XXXXX
# ZILLIZ_TOKEN =db_admin:password (or ApiKey)
Expand Down
263 changes: 259 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pytest = "^8.4.1"
aiohttp = ">=3.10,<3.11"
sentry-sdk = "^2.35.0"
psycopg2-binary = "^2.9.10"
langfuse = "^4.0.1"
opentelemetry-instrumentation-anthropic = "^0.53.3"

[tool.poetry.group.ft]
optional = true
Expand Down
22 changes: 21 additions & 1 deletion services/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,28 @@

load_dotenv()

# Langfuse: init after load_dotenv so env vars are available, before any Anthropic client is created
from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor
AnthropicInstrumentor().instrument()

from langfuse import Langfuse
from langfuse.span_filter import is_default_export_span


def _should_export_span(span):
"""Drop spans marked as tracing-disabled (user has not opted in)."""
attrs = getattr(span, "attributes", None) or {}
if attrs.get("langfuse.trace.metadata.tracing_disabled") == "true":
return False
return is_default_export_span(span)


langfuse = Langfuse(should_export_span=_should_export_span)

env = os.getenv('ENVIRONMENT', 'unknown')
trace_rates = {
'development': 1,
'staging': 0.05,
'staging': 0.05,
'production': 0.03,
'unknown': 0.0,
}
Expand Down Expand Up @@ -68,6 +86,8 @@ def call(
sentry_sdk.capture_exception(e)
result = ApolloError(code=500, message=str(e), type="INTERNAL_ERROR").to_dict()

langfuse.flush()

if output_path:
with open(output_path, "w") as f:
json.dump(result, f)
Expand Down
Loading