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
5 changes: 5 additions & 0 deletions .changeset/soft-eagles-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"braintrust": patch
---

Make the default git metadata settings exclude diff content unless the org opts in.
2 changes: 1 addition & 1 deletion js/src/framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export interface Evaluator<
baseExperimentId?: string;

/**
* Optional settings for collecting git metadata. By default, will collect all git metadata fields allowed in org-level settings.
* Optional settings for collecting git metadata. By default, will collect git metadata fields allowed in org-level settings, excluding diff content unless the org opts in.
*/
gitMetadataSettings?: GitMetadataSettings;

Expand Down
8 changes: 5 additions & 3 deletions js/src/gitutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from "./generated_types";
import { debugLogger } from "./debug-logger";
import { simpleGit } from "simple-git";
import { defaultGitMetadataSettings } from "../util/git_fields";

const COMMON_BASE_BRANCHES = ["main", "master", "develop"];

Expand Down Expand Up @@ -149,17 +150,18 @@ function truncateToByteLimit(s: string, byteLimit: number = 65536): string {
}

export async function getRepoInfo(settings?: GitMetadataSettings) {
if (settings && settings.collect === "none") {
const resolvedSettings = settings ?? defaultGitMetadataSettings();
if (resolvedSettings.collect === "none") {
return undefined;
}

const repo = await repoInfo();
if (!repo || !settings || settings.collect === "all") {
if (!repo || resolvedSettings.collect === "all") {
return repo;
}

let sanitized: RepoInfo = {};
settings.fields?.forEach((field) => {
resolvedSettings.fields?.forEach((field) => {
sanitized = { ...sanitized, [field]: repo[field] };
});

Expand Down
10 changes: 5 additions & 5 deletions js/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
IdField,
IS_MERGE_FIELD,
LogFeedbackFullArgs,
defaultGitMetadataSettings,
mergeDicts,
mergeGitMetadataSettings,
mergeRowBatch,
Expand Down Expand Up @@ -3545,7 +3546,7 @@ type InitializedExperiment<IsOpen extends boolean | undefined> =
* @param options.apiKey The API key to use. If the parameter is not specified, will try to use the `BRAINTRUST_API_KEY` environment variable. If no API key is specified, will prompt the user to login.
* @param options.orgName (Optional) The name of a specific organization to connect to. This is useful if you belong to multiple.
* @param options.metadata (Optional) A dictionary with additional data about the test example, model outputs, or just about anything else that's relevant, that you can use to help find and analyze examples later. For example, you could log the `prompt`, example's `id`, or anything else that would be useful to slice/dice later. The values in `metadata` can be any JSON-serializable type, but its keys must be strings.
* @param options.gitMetadataSettings (Optional) Settings for collecting git metadata. By default, will collect all git metadata fields allowed in org-level settings.
* @param options.gitMetadataSettings (Optional) Settings for collecting git metadata. By default, will collect git metadata fields allowed in org-level settings, excluding diff content unless the org opts in.
* @param setCurrent If true (the default), set the global current-experiment to the newly-created one.
* @param options.open If the experiment already exists, open it in read-only mode. Throws an error if the experiment does not already exist.
* @param options.projectId The id of the project to create the experiment in. This takes precedence over `project` if specified.
Expand Down Expand Up @@ -3699,9 +3700,7 @@ export function init<IsOpen extends boolean = false>(
return repoInfo;
}
let mergedGitMetadataSettings = {
...(state.gitMetadataSettings || {
collect: "all",
}),
...(state.gitMetadataSettings || defaultGitMetadataSettings()),
};
if (gitMetadataSettings) {
mergedGitMetadataSettings = mergeGitMetadataSettings(
Expand Down Expand Up @@ -5709,7 +5708,8 @@ function _saveOrgInfo(
state.orgName = org.name;
state.apiUrl = iso.getEnv("BRAINTRUST_API_URL") ?? org.api_url;
state.proxyUrl = iso.getEnv("BRAINTRUST_PROXY_URL") ?? org.proxy_url;
state.gitMetadataSettings = org.git_metadata || undefined;
state.gitMetadataSettings =
org.git_metadata || defaultGitMetadataSettings();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to default these settings in both the SDKs and the control
plane? I worry about maintining duplicate copies of defaults across our control
plane and SDKs in case we want to revise this.

If we are always defaulting in the control plane now, maybe we can defensively
switch this to not collecting anything if the apikey/login endpoint returns
nothing?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manu Goyal (@manugoyal) given that this PR merged with the same behavior: braintrustdata/braintrust-sdk-python#408

Should we change that one as well or keep what's currently in this patch?

break;
}
}
Expand Down
22 changes: 21 additions & 1 deletion js/util/git_fields.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
import { GitMetadataSettingsType as GitMetadataSettings } from "./generated_types";
import { type GitMetadataSettingsType as GitMetadataSettings } from "./generated_types";

export const DEFAULT_GIT_METADATA_FIELDS: NonNullable<
GitMetadataSettings["fields"]
> = [
"commit",
"branch",
"tag",
"dirty",
"author_name",
"author_email",
"commit_message",
"commit_time",
];

export function defaultGitMetadataSettings(): GitMetadataSettings {
return {
collect: "some",
fields: [...DEFAULT_GIT_METADATA_FIELDS],
};
}

export function mergeGitMetadataSettings(
s1: GitMetadataSettings,
Expand Down
5 changes: 4 additions & 1 deletion js/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ export {
spanTypeAttributeValues,
} from "./span_types";

export { mergeGitMetadataSettings } from "./git_fields";
export {
defaultGitMetadataSettings,
mergeGitMetadataSettings,
} from "./git_fields";

export { loadPrettyXact, prettifyXact } from "./xact-ids";

Expand Down
Loading