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
32 changes: 32 additions & 0 deletions skills/sdk-install/braintrust-url-formats.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Braintrust URL Formats

## App Links (Current Format)

### Experiments

`https://www.braintrust.dev/app/{org}/p/{project}/experiments/{experiment_name}?r={root_span_id}&s={span_id}`

### Datasets

`https://www.braintrust.dev/app/{org}/p/{project}/datasets/{dataset_name}?r={root_span_id}`

### Project Logs

`https://www.braintrust.dev/app/{org}/p/{project}/logs?r={root_span_id}&s={span_id}`

## Legacy Object URLs

`https://www.braintrust.dev/app/object?object_type=...&object_id=...&id=...`

## URL Parameters

| Parameter | Description |
| --------- | --------------------------------------------------------- |
| r | The root_span_id - identifies a trace |
| s | The span_id - identifies a specific span within the trace |
| id | Legacy parameter for root_span_id in object URLs |

## Notes

- The `r=` parameter is always the root_span_id
- For logs and experiments, use `s=` to reference a specific span within a trace
155 changes: 155 additions & 0 deletions skills/sdk-install/csharp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# C# SDK Install

Reference guide for installing the Braintrust C# SDK.

- SDK repo: https://github.com/braintrustdata/braintrust-sdk-dotnet
- NuGet: https://www.nuget.org/packages/Braintrust.Sdk
- Requires .NET 8.0+

## Find the latest version of the SDK

Look up the latest version from NuGet **without installing anything**. Do not guess -- use a read-only query so the environment stays unchanged until you pin the exact version.

```bash
dotnet package search Braintrust.Sdk --exact-match
```

Then install that exact version:

### .NET CLI

```bash
dotnet add package Braintrust.Sdk --version <VERSION>
```

### Or add to .csproj

```xml
<ItemGroup>
<PackageReference Include="Braintrust.Sdk" Version="<VERSION>" />
</ItemGroup>
```

## Initialize the SDK

```csharp
using Braintrust.Sdk;
using Braintrust.Sdk.Config;

var apiKey = Environment.GetEnvironmentVariable("BRAINTRUST_API_KEY");
Braintrust? braintrust = null;
System.Diagnostics.ActivitySource? activitySource = null;

if (!string.IsNullOrEmpty(apiKey))
{
// Set the project name in code (do NOT require an env var for project name).
var config = BraintrustConfig.Of(
("BRAINTRUST_API_KEY", apiKey),
("BRAINTRUST_DEFAULT_PROJECT_NAME", "my-project")
);

braintrust = Braintrust.Get(config);
activitySource = braintrust.GetActivitySource();
}
```

`Braintrust.Get(config)` is the main entry point. The SDK requires an API key to be present, so initialize Braintrust conditionally and run the application normally when `BRAINTRUST_API_KEY` is missing. `GetActivitySource()` returns the `System.Diagnostics.ActivitySource` used to create spans.

## Install instrumentation

The C# SDK instruments LLM clients by wrapping them. Only instrument clients that are actually present in the project.

### OpenAI (`OpenAI` NuGet package)

```bash
dotnet add package OpenAI
```

Create an instrumented OpenAI client:

```csharp
using Braintrust.Sdk;
using Braintrust.Sdk.Config;
using Braintrust.Sdk.Instrumentation.OpenAI;

var btApiKey = Environment.GetEnvironmentVariable("BRAINTRUST_API_KEY");
var openAIApiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY");

if (!string.IsNullOrEmpty(btApiKey) && !string.IsNullOrEmpty(openAIApiKey))
{
var config = BraintrustConfig.Of(
("BRAINTRUST_API_KEY", btApiKey),
("BRAINTRUST_DEFAULT_PROJECT_NAME", "my-project")
);
var braintrust = Braintrust.Get(config);
var activitySource = braintrust.GetActivitySource();
var client = BraintrustOpenAI.WrapOpenAI(activitySource, openAIApiKey);

// Optional: create a root activity so you can generate a permalink.
using var activity = activitySource.StartActivity("braintrust-openai-example");

var chatClient = client.GetChatClient("gpt-5-mini");
var response = await chatClient.CompleteChatAsync(
new ChatMessage[]
{
new SystemChatMessage("You are a helpful assistant."),
new UserChatMessage("What is the capital of France?")
}
);

if (activity != null)
{
var projectUri = await braintrust.GetProjectUriAsync();
var url = $"{projectUri}/logs?r={activity.TraceId}&s={activity.SpanId}";
Console.WriteLine($"View your data in Braintrust: {url}");
}
}
```

### Custom spans

For business logic that isn't an LLM call, create spans manually with the `ActivitySource`:

```csharp
using (var activity = activitySource.StartActivity("my-operation"))
{
activity?.SetTag("some.attribute", "value");
// LLM calls inside here are automatically nested under this span
}
```

## Run the application

Try to figure out how to run the application from the project structure:

- **dotnet run**: `dotnet run` or `dotnet run --project path/to/Project.csproj`
- **ASP.NET**: `dotnet run` (typically starts Kestrel)
- **Published app**: `dotnet path/to/app.dll`
- **Visual Studio / Rider**: run from IDE

If you can't determine how to run the app, ask the user.

## Generate a permalink (required)

The installer must produce a permalink to the emitted trace/logs in its final output.

In .NET, the most reliable permalink can be generated from the root Activity's TraceId/SpanId:

```csharp
if (braintrust != null && activitySource != null)
{
using var activity = activitySource.StartActivity("braintrust-install-verify");
if (activity != null)
{
// Perform a real operation that triggers LLM spans / instrumentation here.

var projectUri = await braintrust.GetProjectUriAsync();
var url = $"{projectUri}/logs?r={activity.TraceId}&s={activity.SpanId}";
Console.WriteLine($"View your data in Braintrust: {url}");
}
}
```

The final assistant response must include the printed URL.

If the SDK-generated URL is not available, construct the permalink manually using the URL format documented in `braintrust-url-formats.md` as described in the agent task (Step 5).
130 changes: 130 additions & 0 deletions skills/sdk-install/go.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Go SDK Install

Reference guide for installing the Braintrust Go SDK.

- SDK repo: https://github.com/braintrustdata/braintrust-sdk-go
- pkg.go.dev: https://pkg.go.dev/github.com/braintrustdata/braintrust-sdk-go
- Requires Go 1.22+

## Install the SDK

```bash
go get github.com/braintrustdata/braintrust-sdk-go
```

## Initialize the SDK

Every Go project needs OpenTelemetry setup and a Braintrust client.

```go
package main

import (
"context"
"log"

"github.com/braintrustdata/braintrust-sdk-go"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/sdk/trace"
)

func main() {
ctx := context.Background()

tp := trace.NewTracerProvider()
defer tp.Shutdown(ctx)
otel.SetTracerProvider(tp)

_, err := braintrust.New(tp, braintrust.WithProject("my-project"))
if err != nil {
log.Fatal(err)
}
}
```

`braintrust.New` reads `BRAINTRUST_API_KEY` from the environment automatically.

## Install instrumentation

The Go SDK uses [Orchestrion](https://github.com/DataDog/orchestrion) to automatically inject tracing at compile time -- no wrapper code needed in the application.

**1. Install orchestrion:**

```bash
go install github.com/DataDog/orchestrion@v1.6.1
```

**2. Create `orchestrion.tool.go` in the project root:**

To instrument all supported providers:

```go
//go:build tools

package main

import (
_ "github.com/DataDog/orchestrion"
_ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/all"
)
```

Or import only the integrations the project actually uses:

```go
//go:build tools

package main

import (
_ "github.com/DataDog/orchestrion"
_ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/anthropic" // anthropic-sdk-go
_ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/genai" // Google GenAI
_ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/github.com/sashabaranov/go-openai" // sashabaranov/go-openai
_ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/langchaingo" // LangChainGo
_ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/openai" // openai-go
)
```

**3. Build with orchestrion:**

```bash
orchestrion go build ./...
```

Or set GOFLAGS to use orchestrion automatically:

```bash
export GOFLAGS="-toolexec='orchestrion toolexec'"
go build ./...
```

After this, LLM client calls are automatically traced with no code changes.

### Supported providers

Orchestrion supports these providers (import the corresponding `trace/contrib/` package in `orchestrion.tool.go`):

| Provider | Import path |
| ---------------------- | --------------------------------------------------------------------------------------------- |
| OpenAI (`openai-go`) | `github.com/braintrustdata/braintrust-sdk-go/trace/contrib/openai` |
| Anthropic | `github.com/braintrustdata/braintrust-sdk-go/trace/contrib/anthropic` |
| Google GenAI / Gemini | `github.com/braintrustdata/braintrust-sdk-go/trace/contrib/genai` |
| LangChainGo | `github.com/braintrustdata/braintrust-sdk-go/trace/contrib/langchaingo` |
| sashabaranov/go-openai | `github.com/braintrustdata/braintrust-sdk-go/trace/contrib/github.com/sashabaranov/go-openai` |
| All of the above | `github.com/braintrustdata/braintrust-sdk-go/trace/contrib/all` |

## Run the application

Try to figure out how to run the application from the project structure:

- **go run**: `go run .` or `go run ./cmd/myapp`
- **Orchestrion**: `orchestrion go run .`
- **Makefile**: check for `run`, `serve`, or similar targets
- **Docker**: check for a `Dockerfile`

If you can't determine how to run the app, ask the user.

## Generate a permalink (required)

Follow the permalink generation steps in the agent task (Step 5). Use the value passed to `braintrust.WithProject(...)` as the project name.
Loading
Loading