Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add opentelemetry preview documentation #1213

Merged
merged 10 commits into from
Feb 2, 2025
Merged
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
14 changes: 13 additions & 1 deletion cookbook/_routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,25 @@
{
"notebook": "integration_huggingface_openai_sdk.ipynb",
"docsPath": "docs/integrations/huggingface"
},
},
{
"notebook": "integration_deepseek_openai_sdk.ipynb",
"docsPath": "docs/integrations/deepseek"
},
{
"notebook": "integration_grpq_sdk.ipynb",
"docsPath": "docs/integrations/groq-sdk"
},
{
"notebook": "otel_integration_pydantic_ai.ipynb",
"docsPath": "docs/opentelemetry/example-pydantic-ai"
},
{
"notebook": "otel_integration_openllmetry.ipynb",
"docsPath": "docs/opentelemetry/example-openllmetry"
},
{
"notebook": "otel_integration_openlit.ipynb",
"docsPath": "docs/opentelemetry/example-openlit"
}
]
112 changes: 112 additions & 0 deletions cookbook/otel_integration_openlit.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"description: Example cookbook for the OpenLIT Langfuse integration using OpenTelemetry.\n",
"category: Integrations\n",
"---\n",
"\n",
"# OpenLIT Integration via OpenTelemetry"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"id": "8xR_verv0yp8",
"outputId": "1bf27d03-bc6a-4fda-e486-a049534cdc09"
},
"outputs": [],
"source": [
"%pip install openai langfuse openlit"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "1-vH4lFi6t-D"
},
"outputs": [],
"source": [
"import os\n",
"import base64\n",
"\n",
"LANGFUSE_PUBLIC_KEY=\"\"\n",
"LANGFUSE_SECRET_KEY=\"\"\n",
"LANGFUSE_AUTH=base64.b64encode(f\"{LANGFUSE_PUBLIC_KEY}:{LANGFUSE_SECRET_KEY}\".encode()).decode()\n",
"\n",
"os.environ[\"OTEL_EXPORTER_OTLP_ENDPOINT\"] = \"https://cloud.langfuse.com/api/public/otel\" # EU data region\n",
"# os.environ[\"OTEL_EXPORTER_OTLP_ENDPOINT\"] = \"https://us.cloud.langfuse.com/api/public/otel\" # US data region\n",
"os.environ[\"OTEL_EXPORTER_OTLP_HEADERS\"] = f\"Authorization=Basic {LANGFUSE_AUTH}\"\n",
"\n",
"# your openai key\n",
"os.environ[\"OPENAI_API_KEY\"] = \"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "xMaAjHXSi0Kr",
"outputId": "277ddaa5-8de1-47f8-b5d1-d4df5dbd448a"
},
"outputs": [],
"source": [
"from openai import OpenAI\n",
"import openlit\n",
"\n",
"openlit.init(disable_batch=True)\n",
"\n",
"openai_client = OpenAI()\n",
"\n",
"chat_completion = openai_client.chat.completions.create(\n",
" messages=[\n",
" {\n",
" \"role\": \"user\",\n",
" \"content\": \"What is LLM Observability?\",\n",
" }\n",
" ],\n",
" model=\"gpt-3.5-turbo\",\n",
")\n",
"\n",
"print(chat_completion)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "EWrLi7RltrrK"
},
"source": [
"[Example trace](https://cloud.langfuse.com/project/cloramnkj0002jz088vzn1ja4/traces/64902f6a5b4f27738be939b7ad38eab3?timestamp=2025-02-02T22%3A09%3A53.053Z)\n",
"\n",
"![OpenLIT OpenAI Trace](https://langfuse.com/images/cookbook/otel-integration-openlit/openlit-openai-trace.png)"
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
124 changes: 124 additions & 0 deletions cookbook/otel_integration_openllmetry.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "24b5jqb5sXOL"
},
"source": [
"---\n",
"description: Example cookbook for the OpenLLMetry Langfuse integration using OpenTelemetry.\n",
"category: Integrations\n",
"---\n",
"\n",
"# OpenLLMetry Integration via OpenTelemetry"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"collapsed": true,
"id": "tsziF7Z7-9ck",
"outputId": "9d99f0ab-2a41-478d-90fb-1cf9121de0d8"
},
"outputs": [],
"source": [
"%pip install openai traceloop-sdk"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "-u8TzbYhAMzs"
},
"outputs": [],
"source": [
"import os\n",
"import base64\n",
"\n",
"LANGFUSE_PUBLIC_KEY=\"\"\n",
"LANGFUSE_SECRET_KEY=\"\"\n",
"LANGFUSE_AUTH=base64.b64encode(f\"{LANGFUSE_PUBLIC_KEY}:{LANGFUSE_SECRET_KEY}\".encode()).decode()\n",
"\n",
"os.environ[\"OTEL_EXPORTER_OTLP_ENDPOINT\"] = \"https://cloud.langfuse.com/api/public/otel\" # EU data region\n",
"# os.environ[\"OTEL_EXPORTER_OTLP_ENDPOINT\"] = \"https://us.cloud.langfuse.com/api/public/otel\" # US data region\n",
"os.environ[\"OTEL_EXPORTER_OTLP_HEADERS\"] = f\"Authorization=Basic {LANGFUSE_AUTH}\"\n",
"\n",
"# your openai key\n",
"os.environ[\"OPENAI_API_KEY\"] = \"\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "uHYYPKKGsTmt"
},
"source": [
"## OpenAI SDK"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "XS9RbpCb_CU4",
"outputId": "e70ee013-39b8-45e1-abc9-c99e0ff34ba3"
},
"outputs": [],
"source": [
"from openai import OpenAI\n",
"from traceloop.sdk import Traceloop\n",
"\n",
"Traceloop.init(disable_batch=True)\n",
"\n",
"openai_client = OpenAI()\n",
"\n",
"chat_completion = openai_client.chat.completions.create(\n",
" messages=[\n",
" {\n",
" \"role\": \"user\",\n",
" \"content\": \"What is LLM Observability?\",\n",
" }\n",
" ],\n",
" model=\"gpt-4o-mini\",\n",
")\n",
"\n",
"print(chat_completion)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "T_kOwnq1sf3b"
},
"source": [
"[Example Trace](https://cloud.langfuse.com/project/cloramnkj0002jz088vzn1ja4/traces/e417c49b4044725e48aa0e089534fa12?timestamp=2025-02-02T22%3A04%3A04.487Z)\n",
"\n",
"![OpenLLMetry OpenAI Trace](https://langfuse.com/images/cookbook/otel-integration-openllmetry/openllmetry-openai-trace.png)"
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading