Skip to content

Commit dd7ec47

Browse files
docs(integration): Add github integration docs (#124)
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
1 parent 4c8d795 commit dd7ec47

10 files changed

+284
-1
lines changed
154 KB
Loading
150 KB
Loading
69.5 KB
Loading
69.7 KB
Loading
320 KB
Loading
290 KB
Loading
128 KB
Loading
127 KB
Loading

integrations/github.mdx

Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
---
2+
title: "GitHub"
3+
description: "Run experiments in CI and get evaluation results directly in your pull requests"
4+
---
5+
6+
# Track Experiment Results in CI
7+
8+
Instead of deploying blindly and hoping for the best, you can validate changes with real data before they reach production.
9+
10+
Create experiments that automatically run your agent flow in CI, test your changes against production-quality datasets, and get comprehensive evaluation results directly in your pull request. This ensures every change is validated with the same rigor as your application code.
11+
12+
13+
## How It Works
14+
15+
Run an experiment in your CI/CD pipeline with the Traceloop GitHub App integration. Receive experiment evaluation results as comments on your pull requests, helping you validate AI model changes, prompt updates, and configuration modifications before merging to production.
16+
17+
<Steps>
18+
<Step title="Install the Traceloop GitHub App">
19+
Go to the [integrations page](https://app.traceloop.com/settings/integrations) within Traceloop and click on the GitHub card.
20+
21+
Click "Install GitHub App" to be redirected to GitHub where you can install the Traceloop app for your organization or personal account.
22+
23+
<Info>
24+
You can also install Traceloop GitHub app [here](https://github.com/apps/traceloop/installations/new)
25+
</Info>
26+
</Step>
27+
28+
<Step title="Configure Repository Access">
29+
Select the repositories where you want to enable Traceloop experiment runs. You can choose:
30+
- All repositories in your organization
31+
- Specific repositories only
32+
33+
After installing the app you will be redirected to a Traceloop authorization page.
34+
35+
<Info>
36+
**Permissions Required:** The app needs read access to your repository contents and write access to pull requests to post evaluation results as comments.
37+
</Info>
38+
</Step>
39+
40+
<Step title="Authorize GitHub app installation at Traceloop">
41+
<Frame>
42+
<img className="block dark:hidden" src="/img/traceloop-integrations/github-app-auth-light.png" />
43+
<img className="hidden dark:block" src="/img/traceloop-integrations/github-app-auth-dark.png" />
44+
</Frame>
45+
</Step>
46+
47+
<Step title="Create Your Experiment Script">
48+
Create an [experiment](/experiments/introduction) script that runs your AI flow. An experiment consists of three key components:
49+
50+
- **[Dataset](/datasets/quick-start)**: A collection of test inputs that represent real-world scenarios your AI will handle
51+
- **Task Function**: Your AI flow code that processes each dataset row (e.g., calling your LLM, running RAG, executing agent logic)
52+
- **[Evaluators](/evaluators/intro)**: Automated quality checks that measure your AI's performance (e.g., accuracy, safety, relevance)
53+
54+
The experiment runs your task function on every row in the dataset, then applies evaluators to measure quality. This validates your changes with real data before production.
55+
56+
The script below shows how to test a question-answering flow:
57+
58+
<CodeGroup>
59+
60+
```python Python
61+
import asyncio
62+
import os
63+
from openai import AsyncOpenAI
64+
from traceloop.sdk import Traceloop
65+
from traceloop.sdk.experiment.model import RunInGithubResponse
66+
67+
# Initialize Traceloop client
68+
client = Traceloop.init(
69+
app_name="research-experiment-ci-cd"
70+
)
71+
72+
async def generate_research_response(question: str) -> str:
73+
"""Generate a research response using OpenAI"""
74+
openai_client = AsyncOpenAI(api_key=os.getenv("OPENAI_API_KEY"))
75+
76+
response = await openai_client.chat.completions.create(
77+
model="gpt-4",
78+
messages=[
79+
{
80+
"role": "system",
81+
"content": "You are a helpful research assistant. Provide accurate, well-researched answers.",
82+
},
83+
{"role": "user", "content": question},
84+
],
85+
temperature=0.7,
86+
max_tokens=500,
87+
)
88+
89+
return response.choices[0].message.content
90+
91+
92+
async def research_task(row):
93+
"""Task function that processes each dataset row"""
94+
query = row.get("query", "")
95+
answer = await generate_research_response(query)
96+
97+
return {
98+
"completion": answer,
99+
"question": query,
100+
"sentence": answer
101+
}
102+
103+
104+
async def main():
105+
"""Run experiment in GitHub context"""
106+
print("🚀 Running research experiment in GitHub CI/CD...")
107+
108+
# Execute tasks locally and send results to backend
109+
response = await client.experiment.run(
110+
task=research_task,
111+
dataset_slug="research-queries",
112+
dataset_version="v2",
113+
evaluators=["research-word-counter", "research-relevancy"],
114+
experiment_slug="research-exp",
115+
)
116+
117+
if isinstance(response, RunInGithubResponse):
118+
print(f"Experiment {response.experiment_slug} completed!")
119+
120+
121+
if __name__ == "__main__":
122+
asyncio.run(main())
123+
```
124+
125+
```typescript TypeScript
126+
import * as traceloop from "@traceloop/node-server-sdk";
127+
import { OpenAI } from "openai";
128+
import type { ExperimentTaskFunction } from "@traceloop/node-server-sdk";
129+
130+
// Initialize Traceloop
131+
traceloop.initialize({
132+
appName: "research-experiment-ci-cd",
133+
disableBatch: true,
134+
traceloopSyncEnabled: true,
135+
});
136+
137+
await traceloop.waitForInitialization();
138+
const client = traceloop.getClient();
139+
140+
/**
141+
* Generate a research response using OpenAI
142+
*/
143+
async function generateResearchResponse(question: string): Promise<string> {
144+
const openai = new OpenAI({
145+
apiKey: process.env.OPENAI_API_KEY,
146+
});
147+
148+
const response = await openai.chat.completions.create({
149+
model: "gpt-4",
150+
messages: [
151+
{
152+
role: "system",
153+
content: "You are a helpful research assistant. Provide accurate, well-researched answers.",
154+
},
155+
{ role: "user", content: question },
156+
],
157+
temperature: 0.7,
158+
max_tokens: 500,
159+
});
160+
161+
return response.choices?.[0]?.message?.content || "";
162+
}
163+
164+
/**
165+
* Task function that processes each dataset row
166+
*/
167+
const researchTask: ExperimentTaskFunction = async (row) => {
168+
const query = (row.query as string) || "";
169+
const answer = await generateResearchResponse(query);
170+
171+
return {
172+
completion: answer,
173+
question: query,
174+
sentence: answer,
175+
};
176+
};
177+
178+
/**
179+
* Run experiment in GitHub context
180+
*/
181+
async function main() {
182+
console.log("🚀 Running research experiment in GitHub CI/CD...");
183+
184+
// Execute tasks locally and send results to backend
185+
const response = await client.experiment.run(researchTask, {
186+
datasetSlug: "research-queries",
187+
datasetVersion: "v2",
188+
evaluators: ["research-word-counter", "research-relevancy"],
189+
experimentSlug: "research-exp",
190+
});
191+
192+
console.log(`Experiment research-exp completed!`);
193+
}
194+
195+
main().catch((error) => {
196+
console.error("Experiment failed:", error);
197+
process.exit(1);
198+
});
199+
```
200+
201+
</CodeGroup>
202+
</Step>
203+
204+
<Step title="Set up Your CI Workflow">
205+
Add a GitHub Actions workflow to automatically run Traceloop experiments on pull requests.
206+
Below is an example workflow file you can customize for your project:
207+
```yaml ci-cd configuration
208+
name: Run Traceloop Experiments
209+
210+
on:
211+
pull_request:
212+
branches: [main, master]
213+
214+
jobs:
215+
run-experiments:
216+
runs-on: ubuntu-latest
217+
218+
steps:
219+
- name: Checkout code
220+
uses: actions/checkout@v4
221+
222+
- name: Set up Python
223+
uses: actions/setup-python@v5
224+
with:
225+
python-version: '3.11'
226+
227+
- name: Install dependencies
228+
run: |
229+
pip install traceloop-sdk openai
230+
231+
- name: Run experiments
232+
env:
233+
TRACELOOP_API_KEY: ${{ secrets.TRACELOOP_API_KEY }}
234+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
235+
run: |
236+
python experiments/run_ci_experiments.py
237+
```
238+
239+
<Note>
240+
**Add secrets to your GitHub repository**
241+
242+
Make sure all secrets used in your experiment script (like `OPENAI_API_KEY`) are added to both:
243+
- Your GitHub Actions workflow configuration
244+
- Your GitHub repository secrets
245+
246+
Traceloop requires you to add `TRACELOOP_API_KEY` to your GitHub repository secrets. [Generate one in Settings →](/settings/managing-api-keys)
247+
</Note>
248+
249+
<Frame>
250+
<img className="block dark:hidden" src="/img/traceloop-integrations/github-app-secrets-light.png" />
251+
<img className="hidden dark:block" src="/img/traceloop-integrations/github-app-secrets-dark.png" />
252+
</Frame>
253+
</Step>
254+
255+
<Step title="View Results in Your Pull Request">
256+
Once configured, every pull request will automatically trigger the experiment run. The Traceloop GitHub App will post a comment on the PR with a comprehensive summary of the evaluation results.
257+
258+
<Frame>
259+
<img className="block dark:hidden" src="/img/traceloop-integrations/github-app-comment-light.png" />
260+
<img className="hidden dark:block" src="/img/traceloop-integrations/github-app-comment-dark.png" />
261+
</Frame>
262+
263+
The PR comment includes:
264+
- **Overall experiment status**
265+
- **Evaluation metrics**
266+
- **Link to detailed results**
267+
268+
### Experiment Dashboard
269+
270+
Click on the link in the PR comment to view the complete experiment run in the Traceloop experiment dashboard, where you can:
271+
- Review individual test cases and their evaluator scores
272+
- Analyze which specific inputs passed or failed
273+
- Compare results with previous runs to track improvements or regressions
274+
- Drill down into evaluator reasoning and feedback
275+
276+
<Frame>
277+
<img className="block dark:hidden" src="/img/traceloop-integrations/github-app-exp-run-results-light.png" />
278+
<img className="hidden dark:block" src="/img/traceloop-integrations/github-app-exp-run-results-dark.png" />
279+
</Frame>
280+
</Step>
281+
</Steps>

mint.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@
201201
"group": "Integrations",
202202
"pages": [
203203
"integrations/posthog",
204-
"integrations/slack"
204+
"integrations/slack",
205+
"integrations/github"
206+
205207
]
206208
},
207209
{

0 commit comments

Comments
 (0)