Skip to content
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ To send Braintrust otel data to the local collector:

```
# assumes you have BRAINTRUST_API_KEY and OPENAI_API_KEY exported
export BRAINTRUST_API_URL="http://localhost:4318" ; export BRAINTRUST_TRACES_PATH="/v1/traces"; export BRAINTRUST_LOGS_PATH="/v1/logs" ; ./gradlew :examples:runOpenAIInstrumentation
export BRAINTRUST_API_URL="http://localhost:4318" ; export BRAINTRUST_TRACES_PATH="/v1/traces"; export BRAINTRUST_LOGS_PATH="/v1/logs" ; ./gradlew :examples:openai-instrumentation:run
```
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ A list of supported instrumentation can be found [here](./braintrust-sdk/instrum

## Running Examples

Example source code can be found [here](./examples/src/main/java/dev/braintrust/examples)
Example source code can be found [here](./examples). Each example is its own Gradle subproject under `examples/` with its own `:run` target.

```bash
export BRAINTRUST_API_KEY="your-braintrust-api-key"
Expand All @@ -115,9 +115,9 @@ export ANTHROPIC_API_KEY="your-anthropic-api-key" # to run anthropic examples
brew install openjdk@17 # macOS
sudo apt install openjdk-17-jdk # ubuntu
# to run a specific example
./gradlew :examples:runSimpleOpenTelemetry
# to see all examples
./gradlew :examples:tasks --group="Braintrust SDK Examples"
./gradlew :examples:simple-open-telemetry:run
# to list every example subproject
./gradlew projects
```

## Logging
Expand Down
18 changes: 18 additions & 0 deletions examples/anthropic-instrumentation/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
application {
mainClass = 'dev.braintrust.examples.AnthropicInstrumentationExample'
}

dependencies {
implementation project(':braintrust-sdk:instrumentation:anthropic_2_2_0')
implementation "com.anthropic:anthropic-java:2.8.1"
}

run {
description = 'Run the Anthropic instrumentation example. NOTE: this requires ANTHROPIC_API_KEY to be exported and will make a small call to anthropic, using your tokens'
debugOptions {
enabled = true
port = 5566
server = true
suspend = false
}
}
222 changes: 33 additions & 189 deletions examples/build.gradle
Original file line number Diff line number Diff line change
@@ -1,201 +1,45 @@
plugins {
id 'java'
id 'application'
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
vendor = JvmVendorSpec.ADOPTIUM // eclipse JVM
}
withJavadocJar()
withSourcesJar()
}

repositories {
mavenCentral()
}

def braintrustLogLevel = System.getenv('BRAINTRUST_LOG_LEVEL') ?: 'info'

dependencies {
implementation project(':braintrust-sdk')
implementation project(':braintrust-sdk:instrumentation:openai_2_15_0')
implementation project(':braintrust-sdk:instrumentation:anthropic_2_2_0')
implementation project(':braintrust-sdk:instrumentation:genai_1_18_0')
implementation project(':braintrust-sdk:instrumentation:langchain_1_8_0')
implementation project(':braintrust-sdk:instrumentation:springai_1_0_0')
implementation project(':braintrust-sdk:instrumentation:aws_bedrock_2_30_0')
runtimeOnly "org.slf4j:slf4j-simple:${slf4jVersion}"
// To run otel examples
implementation "io.opentelemetry:opentelemetry-exporter-otlp:${otelVersion}"
// to run OAI instrumentation examples
implementation 'com.openai:openai-java:2.8.1'
// to run anthropic examples
implementation "com.anthropic:anthropic-java:2.8.1"
// to run gemini examples
implementation 'com.google.genai:google-genai:1.20.0'
// spring ai examples
implementation 'org.springframework.ai:spring-ai-anthropic:1.1.0'
implementation 'org.springframework.ai:spring-ai-bedrock-converse:1.1.0'
implementation 'org.springframework.ai:spring-ai-google-genai:1.1.0'
implementation 'org.springframework.ai:spring-ai-openai:1.1.0'
// spring-ai-openai requires spring-webflux (WebClient) at runtime
implementation 'org.springframework:spring-webflux:6.2.3'
// spring boot for SpringAIExample (exclude logback, use slf4j-simple like other examples)
implementation('org.springframework.boot:spring-boot-starter:3.4.1') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
// to run langchain4j examples
implementation 'dev.langchain4j:langchain4j:1.9.1'
implementation 'dev.langchain4j:langchain4j-open-ai:1.9.1'

}

application {
mainClass = 'dev.braintrust.examples.SimpleOpenTelemetryExample'
}

task runSimpleOpenTelemetry(type: JavaExec) {
group = 'Braintrust SDK Examples'
description = 'Run the simple OpenTelemetry example'
classpath = sourceSets.main.runtimeClasspath
mainClass = 'dev.braintrust.examples.SimpleOpenTelemetryExample'
systemProperty 'org.slf4j.simpleLogger.log.dev.braintrust', braintrustLogLevel
}

task runCustomOpenTelemetry(type: JavaExec) {
group = 'Braintrust SDK Examples'
description = 'Run the custom OpenTelemetry example'
classpath = sourceSets.main.runtimeClasspath
mainClass = 'dev.braintrust.examples.CustomOpenTelemetryExample'
systemProperty 'org.slf4j.simpleLogger.log.dev.braintrust', braintrustLogLevel
}
// Shared convention for all example subprojects.
//
// Each example lives in its own subproject under examples/ and applies the
// 'application' plugin so it can be launched with:
//
// ./gradlew :examples:<example-name>:run
//
// List every example via:
//
// ./gradlew projects
//
// Per-example build.gradle files only declare their mainClass, extra
// dependencies, and (optionally) a description / debugOptions block on the
// inherited 'run' task.

task runOpenAIInstrumentation(type: JavaExec) {
group = 'Braintrust SDK Examples'
description = 'Run the OpenAI instrumentation example. NOTE: this requires OPENAI_API_KEY to be exported and will make a small call to openai, using your tokens'
classpath = sourceSets.main.runtimeClasspath
mainClass = 'dev.braintrust.examples.OpenAIInstrumentationExample'
systemProperty 'org.slf4j.simpleLogger.log.dev.braintrust', braintrustLogLevel
debugOptions {
enabled = true
port = 5566
server = true
suspend = false
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'application'

task runExperiment(type: JavaExec) {
group = 'Braintrust SDK Examples'
description = 'Run the experiment example'
classpath = sourceSets.main.runtimeClasspath
mainClass = 'dev.braintrust.examples.ExperimentExample'
systemProperty 'org.slf4j.simpleLogger.log.dev.braintrust', braintrustLogLevel
debugOptions {
enabled = true
port = 5566
server = true
suspend = false
}
}
group = rootProject.group
version = rootProject.version

task runAnthropicInstrumentation(type: JavaExec) {
group = 'Braintrust SDK Examples'
description = 'Run the Anthropic instrumentation example. NOTE: this requires ANTHROPIC_API_KEY to be exported and will make a small call to anthropic, using your tokens'
classpath = sourceSets.main.runtimeClasspath
mainClass = 'dev.braintrust.examples.AnthropicInstrumentationExample'
systemProperty 'org.slf4j.simpleLogger.log.dev.braintrust', braintrustLogLevel
debugOptions {
enabled = true
port = 5566
server = true
suspend = false
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
vendor = JvmVendorSpec.ADOPTIUM // eclipse JVM
}
}
}


task runPromptFetching(type: JavaExec) {
group = 'Braintrust SDK Examples'
description = 'Run the prompt fetching example'
classpath = sourceSets.main.runtimeClasspath
mainClass = 'dev.braintrust.examples.PromptFetchingExample'
systemProperty 'org.slf4j.simpleLogger.log.dev.braintrust', braintrustLogLevel
debugOptions {
enabled = true
port = 5566
server = true
suspend = false
repositories {
mavenCentral()
}
}

task runGeminiInstrumentation(type: JavaExec) {
group = 'Braintrust SDK Examples'
description = 'Run the Gemini instrumentation example. NOTE: this requires GOOGLE_API_KEY or GEMINI_API_KEY to be exported and will make a small call to google, using your tokens'
classpath = sourceSets.main.runtimeClasspath
mainClass = 'dev.braintrust.examples.GeminiInstrumentationExample'
systemProperty 'org.slf4j.simpleLogger.log.dev.braintrust', braintrustLogLevel
debugOptions {
enabled = true
port = 5566
server = true
suspend = false
}
}
def braintrustLogLevel = System.getenv('BRAINTRUST_LOG_LEVEL') ?: 'info'

task runSpringAI(type: JavaExec) {
group = 'Braintrust SDK Examples'
description = 'Run the Spring Boot + Spring AI example'
classpath = sourceSets.main.runtimeClasspath
mainClass = 'dev.braintrust.examples.SpringAIExample'
systemProperty 'org.slf4j.simpleLogger.log.dev.braintrust', braintrustLogLevel

debugOptions {
enabled = true
port = 5566
server = true
suspend = false
}
}

task runRemoteEval(type: JavaExec) {
group = 'Braintrust SDK Examples'
description = 'Run the remote eval example'
classpath = sourceSets.main.runtimeClasspath
mainClass = 'dev.braintrust.examples.RemoteEvalExample'
systemProperty 'org.slf4j.simpleLogger.log.dev.braintrust', braintrustLogLevel
debugOptions {
enabled = true
port = 5566
server = true
suspend = false
dependencies {
implementation project(':braintrust-sdk')
runtimeOnly "org.slf4j:slf4j-simple:${slf4jVersion}"
}
}

task runLangchainSimple(type: JavaExec) {
group = 'Braintrust SDK Examples'
description = 'Run the LangChain4j instrumentation example. NOTE: this requires OPENAI_API_KEY to be exported and will make a small call to openai, using your tokens'
classpath = sourceSets.main.runtimeClasspath
mainClass = 'dev.braintrust.examples.LangchainSimpleExample'
systemProperty 'org.slf4j.simpleLogger.log.dev.braintrust', braintrustLogLevel
debugOptions {
enabled = true
port = 5566
server = true
suspend = false
}
}

task runLangchainAIServices(type: JavaExec) {
group = 'Braintrust SDK Examples'
description = 'Run the LangChain4j AI Services example. NOTE: this requires OPENAI_API_KEY to be exported and will make a small call to openai, using your tokens'
classpath = sourceSets.main.runtimeClasspath
mainClass = 'dev.braintrust.examples.LangchainAIServicesExample'
systemProperty 'org.slf4j.simpleLogger.log.dev.braintrust', braintrustLogLevel
debugOptions {
enabled = true
port = 5566
server = true
suspend = false
tasks.named('run') {
group = 'Braintrust SDK Examples'
systemProperty 'org.slf4j.simpleLogger.log.dev.braintrust', braintrustLogLevel
}
}
7 changes: 7 additions & 0 deletions examples/classifiers/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
application {
mainClass = 'dev.braintrust.examples.ClassifiersExample'
}

run {
description = 'Run the classifiers example'
}
11 changes: 11 additions & 0 deletions examples/custom-open-telemetry/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
application {
mainClass = 'dev.braintrust.examples.CustomOpenTelemetryExample'
}

dependencies {
implementation "io.opentelemetry:opentelemetry-exporter-otlp:${otelVersion}"
}

run {
description = 'Run the custom OpenTelemetry example'
}
18 changes: 18 additions & 0 deletions examples/experiment/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
application {
mainClass = 'dev.braintrust.examples.ExperimentExample'
}

dependencies {
implementation project(':braintrust-sdk:instrumentation:openai_2_15_0')
implementation 'com.openai:openai-java:2.8.1'
}

run {
description = 'Run the experiment example'
debugOptions {
enabled = true
port = 5566
server = true
suspend = false
}
}
18 changes: 18 additions & 0 deletions examples/gemini-instrumentation/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
application {
mainClass = 'dev.braintrust.examples.GeminiInstrumentationExample'
}

dependencies {
implementation project(':braintrust-sdk:instrumentation:genai_1_18_0')
implementation 'com.google.genai:google-genai:1.20.0'
}

run {
description = 'Run the Gemini instrumentation example. NOTE: this requires GOOGLE_API_KEY or GEMINI_API_KEY to be exported and will make a small call to google, using your tokens'
debugOptions {
enabled = true
port = 5566
server = true
suspend = false
}
}
19 changes: 19 additions & 0 deletions examples/langchain-ai-services/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
application {
mainClass = 'dev.braintrust.examples.LangchainAIServicesExample'
}

dependencies {
implementation project(':braintrust-sdk:instrumentation:langchain_1_8_0')
implementation 'dev.langchain4j:langchain4j:1.9.1'
implementation 'dev.langchain4j:langchain4j-open-ai:1.9.1'
}

run {
description = 'Run the LangChain4j AI Services example. NOTE: this requires OPENAI_API_KEY to be exported and will make a small call to openai, using your tokens'
debugOptions {
enabled = true
port = 5566
server = true
suspend = false
}
}
19 changes: 19 additions & 0 deletions examples/langchain-simple/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
application {
mainClass = 'dev.braintrust.examples.LangchainSimpleExample'
}

dependencies {
implementation project(':braintrust-sdk:instrumentation:langchain_1_8_0')
implementation 'dev.langchain4j:langchain4j:1.9.1'
implementation 'dev.langchain4j:langchain4j-open-ai:1.9.1'
}

run {
description = 'Run the LangChain4j instrumentation example. NOTE: this requires OPENAI_API_KEY to be exported and will make a small call to openai, using your tokens'
debugOptions {
enabled = true
port = 5566
server = true
suspend = false
}
}
18 changes: 18 additions & 0 deletions examples/openai-instrumentation/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
application {
mainClass = 'dev.braintrust.examples.OpenAIInstrumentationExample'
}

dependencies {
implementation project(':braintrust-sdk:instrumentation:openai_2_15_0')
implementation 'com.openai:openai-java:2.8.1'
}

run {
description = 'Run the OpenAI instrumentation example. NOTE: this requires OPENAI_API_KEY to be exported and will make a small call to openai, using your tokens'
debugOptions {
enabled = true
port = 5566
server = true
suspend = false
}
}
Loading
Loading