Skip to content

Commit c3af5bb

Browse files
authored
Merge pull request #29 from braintrustdata/ark/dev-docs
dev docs mv to CONTRIBUTING
2 parents 582e51a + bd0c071 commit c3af5bb

7 files changed

Lines changed: 38 additions & 54 deletions

File tree

CONTRIBUTING.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# SDK Developer Documentation
2+
3+
This file documents developing the SDK itself. If you simply wish to use the SDK or run examples, see [README.md](./README.md)
4+
5+
## Setup
6+
7+
- Install JDK 17
8+
- Recommended to use SDK Man: https://sdkman.io/ and `sdk use java 17.0.16-tem`
9+
- Ensure you can run all tests and checks: `./gradlew check build`
10+
- IDE Setup
11+
- Intellij Community
12+
- Ubuntu: `sudo snap install intellij-idea-community`
13+
- Other: https://www.jetbrains.com/idea/download/
14+
- (Optional) Install pre-commit hooks: `./gradlew installGitHooks`
15+
- These hooks automatically run common checks for you but CI also runs the same checks before merging to the main branch is allowed
16+
- NOTE: this will overwrite existing hooks. Take backups before running
17+
18+
## Running a local OpenTelemetry collector
19+
20+
OpenTelemetry provides a local collector with a debug exporter which logs all traces, logs, and metrics to stdout.
21+
22+
To run a local collector:
23+
24+
```
25+
# Assumes you're in the repo root
26+
docker run --rm -p 4318:4318 -v "$PWD/localcollector/collector.yaml:/etc/otelcol/config.yaml" otel/opentelemetry-collector:0.136.0 # latest release will probably also work
27+
```
28+
29+
To send Braintrust otel data to the local collector:
30+
31+
```
32+
# assumes you have BRAINTRUST_API_KEY and OPENAI_API_KEY exported
33+
export BRAINTRUST_API_URL="http://localhost:4318" ; export BRAINTRUST_TRACES_PATH="/v1/traces"; export BRAINTRUST_LOGS_PATH="/v1/logs" ; ./gradlew :examples:runOpenAIInstrumentation
34+
```

README.md

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,3 @@ The SDK uses a standard slf4j logger and will use the default log level (or not
5151
All Braintrust loggers will log into the `dev.braintrust` namespace. To adjust the log level, consult your logger documentation.
5252

5353
For example, to enable debug logging for slf4j-simple you would set the system property `org.slf4j.simpleLogger.log.dev.braintrust=DEBUG`
54-
55-
# SDK Developer Docs
56-
57-
The remaining sections document developing the SDK itself. Nothing below is required if you simply wish to use the SDK or run examples.
58-
59-
## Setup
60-
61-
- Install JDK 17
62-
- Recommended to use SDK Man: https://sdkman.io/ and `sdk use java 17.0.16-tem`
63-
- Ensure you can run all tests and checks: `./gradlew check build`
64-
- IDE Setup
65-
- Intellij Community
66-
- Ubuntu: `sudo snap install intellij-idea-community`
67-
- Other: https://www.jetbrains.com/idea/download/
68-
- (Optional) Install pre-commit hooks: `./gradlew installGitHooks`
69-
- These hooks automatically run common checks for you but CI also runs the same checks before merging to the main branch is allowed
70-
- NOTE: this will overwrite existing hooks. Take backups before running
71-
72-
## Running a local OpenTelemetry collector
73-
74-
OpenTelemetry provides a local collector with a debug exporter which logs all traces, logs, and metrics to stdout.
75-
76-
To run a local collector:
77-
78-
```
79-
# Assumes you're in the repo root
80-
docker run --rm -p 4318:4318 -v "$PWD/localcollector/collector.yaml:/etc/otelcol/config.yaml" otel/opentelemetry-collector:0.136.0 # latest release will probably also work
81-
```
82-
83-
To send Braintrust otel data to the local collector:
84-
85-
```
86-
# assumes you have BRAINTRUST_API_KEY and OPENAI_API_KEY exported
87-
export BRAINTRUST_API_URL="http://localhost:4318" ; export BRAINTRUST_TRACES_PATH="/v1/traces"; export BRAINTRUST_LOGS_PATH="/v1/logs" ; ./gradlew :examples:runOpenAIInstrumentation
88-
```

src/main/java/dev/braintrust/eval/Eval.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import dev.braintrust.api.BraintrustApiClient;
66
import dev.braintrust.config.BraintrustConfig;
7-
import dev.braintrust.spec.SdkSpec;
87
import dev.braintrust.trace.BraintrustContext;
98
import dev.braintrust.trace.BraintrustTracing;
109
import io.opentelemetry.api.common.AttributeKey;
@@ -26,7 +25,7 @@
2625
*/
2726
public final class Eval<INPUT, OUTPUT> {
2827
private static final AttributeKey<String> PARENT =
29-
AttributeKey.stringKey(SdkSpec.Attributes.PARENT);
28+
AttributeKey.stringKey(BraintrustTracing.PARENT_KEY);
3029
private static final ObjectMapper JSON_MAPPER =
3130
new com.fasterxml.jackson.databind.ObjectMapper();
3231
private final @Nonnull String experimentName;

src/main/java/dev/braintrust/spec/SdkSpec.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/main/java/dev/braintrust/trace/BraintrustSpanProcessor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dev.braintrust.trace;
22

33
import dev.braintrust.config.BraintrustConfig;
4-
import dev.braintrust.spec.SdkSpec;
54
import io.opentelemetry.api.common.AttributeKey;
65
import io.opentelemetry.context.Context;
76
import io.opentelemetry.sdk.common.CompletableResultCode;
@@ -21,10 +20,9 @@
2120
*/
2221
@Slf4j
2322
class BraintrustSpanProcessor implements SpanProcessor {
24-
2523
// Braintrust-specific attributes
2624
public static final AttributeKey<String> PARENT =
27-
AttributeKey.stringKey(SdkSpec.Attributes.PARENT);
25+
AttributeKey.stringKey(BraintrustTracing.PARENT_KEY);
2826

2927
private final BraintrustConfig config;
3028
private final SpanProcessor delegate;

src/main/java/dev/braintrust/trace/BraintrustTracing.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030
@Slf4j
3131
public final class BraintrustTracing {
32+
public static final String PARENT_KEY = "braintrust.parent";
3233
static final String OTEL_SERVICE_NAME = "braintrust-app";
3334
static final String INSTRUMENTATION_NAME = "braintrust-java";
3435
static final String INSTRUMENTATION_VERSION = loadVersionFromProperties();

src/test/java/dev/braintrust/eval/EvalTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import dev.braintrust.api.BraintrustApiClient;
66
import dev.braintrust.config.BraintrustConfig;
7-
import dev.braintrust.spec.SdkSpec;
87
import dev.braintrust.trace.BraintrustTracing;
98
import dev.braintrust.trace.BraintrustTracingTest;
109
import io.opentelemetry.api.GlobalOpenTelemetry;
@@ -74,7 +73,7 @@ public void evalOtelTraceWithProperAttributes() {
7473
span -> {
7574
var parent =
7675
span.getAttributes()
77-
.get(AttributeKey.stringKey(SdkSpec.Attributes.PARENT));
76+
.get(AttributeKey.stringKey(BraintrustTracing.PARENT_KEY));
7877
assertEquals(
7978
"experiment_id:" + experiment.id(),
8079
parent,

0 commit comments

Comments
 (0)