Skip to content
Closed
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
52 changes: 52 additions & 0 deletions .github/workflows/js-sdk-cjs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: JS SDK CJS OTEL Integration Tests
on:
pull_request:

jobs:
otel-integration-tests-cjs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: recursive

- name: Install dependencies
uses: ./.github/actions/deps

- name: Build braintrust SDK
shell: bash
run: |
eval "$(mise activate)"
cd sdk/js
pnpm build

- name: Install integration test dependencies
shell: bash
run: |
eval "$(mise activate)"
cd sdk/js/integration-tests
pnpm install

- name: Configure for CJS
shell: bash
run: |
cd sdk/js/integration-tests
# Backup original files and use CJS versions
mv package.json package-esm.json.bak
mv tsconfig.json tsconfig-esm.json.bak
cp package-cjs.json package.json
cp tsconfig-cjs.json tsconfig.json

- name: Run OTEL integration tests (CJS)
shell: bash
env:
BRAINTRUST_API_KEY: ${{ secrets.BRAINTRUST_API_KEY }}
BRAINTRUST_OTEL_COMPAT: "true"
NODE_OPTIONS: "--require tsx/cjs"
run: |
eval "$(mise activate)"
cd sdk/js/integration-tests
pnpm test
timeout-minutes: 10
41 changes: 41 additions & 0 deletions .github/workflows/js-sdk-esm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: JS SDK ESM OTEL Integration Tests
on:
pull_request:

jobs:
otel-integration-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: recursive

- name: Install dependencies
uses: ./.github/actions/deps

- name: Build braintrust SDK
shell: bash
run: |
eval "$(mise activate)"
cd sdk/js
pnpm build

- name: Install integration test dependencies
shell: bash
run: |
eval "$(mise activate)"
cd sdk/js/integration-tests
pnpm install

- name: Run OTEL integration tests
shell: bash
env:
BRAINTRUST_API_KEY: ${{ secrets.BRAINTRUST_API_KEY }}
BRAINTRUST_OTEL_COMPAT: "true"
run: |
eval "$(mise activate)"
cd sdk/js/integration-tests
pnpm test
timeout-minutes: 10
65 changes: 65 additions & 0 deletions .github/workflows/js-sdk-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: js-sdk-example

on:
pull_request:

permissions:
contents: read

jobs:
test-example:
name: Test Braintrust Example
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install SDK dependencies
working-directory: js
run: pnpm install

- name: Install OTEL example dependencies
working-directory: js/examples/otel
run: npm install

- name: Run otel as CJS example
working-directory: js/examples/otel
env:
BRAINTRUST_OTEL_COMPAT: false
BRAINTRUST_API_KEY: ${{ secrets.BRAINTRUST_API_KEY }}
run: |
node -e "console.log('CJS mode:', typeof require !== 'undefined')"
npm start

- name: Backup original otel package.json
working-directory: js/examples/otel
run: cp package.json package.json.bak

- name: Enable ESM for this run
working-directory: js/examples/otel
run: |
jq '. + {"type":"module"}' package.json > package.temp.json
mv package.temp.json package.json

- name: Run otel as ESM example
working-directory: js/examples/otel
env:
BRAINTRUST_OTEL_COMPAT: false
BRAINTRUST_API_KEY: ${{ secrets.BRAINTRUST_API_KEY }}
run: |
node -e "console.log('ESM mode:', typeof import.meta.url === 'string')"
npm start

- name: Restore original package.json
working-directory: js/examples/otel
if: always()
run: mv package.json.bak package.json
118 changes: 118 additions & 0 deletions .github/workflows/js-sdk-node-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: js-sdk-node-example

on:
pull_request:

permissions:
contents: read

jobs:
test-node-example:
name: Test Braintrust Node Example
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4

- name: Setup Node.js 20 for building
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install SDK dependencies
working-directory: js
run: pnpm install

- name: Build SDK
working-directory: js
run: npm run build

- name: Setup Node.js 14 for testing
uses: actions/setup-node@v4
with:
node-version: "14"

- name: Configure for CJS and update imports
working-directory: js/examples/otel
run: |
# Backup original files and use CJS versions
mv package.json package-esm.json.bak
cp package-cjs.json package.json
# Only swap tsconfig if it exists
if [ -f tsconfig.json ]; then
mv tsconfig.json tsconfig-esm.json.bak
fi
cp tsconfig-cjs.json tsconfig.json

# Update import to use compiled CJS dist files
sed -i 's|from "../../src"|from "../../dist/index.js"|g' nodesdk_example.ts
echo "Updated nodesdk_example.ts to use compiled CJS files"

- name: Install OTEL example dependencies
working-directory: js/examples/otel
run: npm install

- name: Compile example to JavaScript
working-directory: js/examples/otel
run: |
npm run build
echo "Verifying compiled file exists..."
ls -la nodesdk_example.js
echo "Compiled successfully!"

- name: Verify OTEL dependencies installed
working-directory: js/examples/otel
run: |
echo "Verifying OTEL packages installed..."
packages=(
"@opentelemetry/api"
"@opentelemetry/sdk-trace-base"
"@opentelemetry/sdk-node"
"@opentelemetry/context-async-hooks"
"openai"
)
for package in "${packages[@]}"; do
if [ ! -d "node_modules/$package" ]; then
echo "❌ Package $package not found"
exit 1
fi
echo "✅ $package verified"
done
echo "All required packages verified successfully"

- name: Check if API key is available
id: check_api_key
run: |
if [ -z "${{ secrets.BRAINTRUST_API_KEY }}" ]; then
echo "api_key_available=false" >> $GITHUB_OUTPUT
echo "⚠️ BRAINTRUST_API_KEY secret not set - test will be skipped"
else
echo "api_key_available=true" >> $GITHUB_OUTPUT
fi

- name: Run OTEL example with npm start
if: steps.check_api_key.outputs.api_key_available == 'true'
working-directory: js/examples/otel
env:
BRAINTRUST_OTEL_COMPAT: false
BRAINTRUST_API_KEY: ${{ secrets.BRAINTRUST_API_KEY }}
run: |
node -e "console.log('ESM mode:', typeof import.meta.url === 'string')"
npm start

- name: Restore original config files
if: always()
working-directory: js/examples/otel
run: |
# Restore original files
mv package-esm.json.bak package.json || true
if [ -f tsconfig-esm.json.bak ]; then
mv tsconfig-esm.json.bak tsconfig.json || true
fi
# Restore original imports and remove compiled file
git checkout nodesdk_example.ts || true
rm -f nodesdk_example.js || true
Loading
Loading