diff --git a/js/src/gitutil.ts b/js/src/gitutil.ts index ef7a26bcb..b82d177c0 100644 --- a/js/src/gitutil.ts +++ b/js/src/gitutil.ts @@ -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"]; @@ -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] }; }); diff --git a/js/src/logger.ts b/js/src/logger.ts index 81da807fe..dee2c3342 100644 --- a/js/src/logger.ts +++ b/js/src/logger.ts @@ -31,6 +31,7 @@ import { IdField, IS_MERGE_FIELD, LogFeedbackFullArgs, + defaultGitMetadataSettings, mergeDicts, mergeGitMetadataSettings, mergeRowBatch, @@ -3535,7 +3536,7 @@ type InitializedExperiment = * @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. @@ -3689,9 +3690,7 @@ export function init( return repoInfo; } let mergedGitMetadataSettings = { - ...(state.gitMetadataSettings || { - collect: "all", - }), + ...(state.gitMetadataSettings || defaultGitMetadataSettings()), }; if (gitMetadataSettings) { mergedGitMetadataSettings = mergeGitMetadataSettings( @@ -4263,8 +4262,8 @@ export function initDataset< legacy, _internal_btql, resolvedVersion instanceof LazyValue || - normalizedEnvironment !== undefined || - normalizedSnapshotName !== undefined + normalizedEnvironment !== undefined || + normalizedSnapshotName !== undefined ? { ...(resolvedVersion instanceof LazyValue ? { @@ -5699,7 +5698,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(); break; } } @@ -6041,9 +6041,9 @@ export type WithTransactionId = R & { export const DEFAULT_FETCH_BATCH_SIZE = 1000; export const MAX_BTQL_ITERATIONS = 10000; -export class ObjectFetcher implements AsyncIterable< - WithTransactionId -> { +export class ObjectFetcher + implements AsyncIterable> +{ private _fetchedData: WithTransactionId[] | undefined = undefined; constructor( diff --git a/js/util/git_fields.ts b/js/util/git_fields.ts index 8eb06d625..6001516f4 100644 --- a/js/util/git_fields.ts +++ b/js/util/git_fields.ts @@ -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, diff --git a/js/util/index.ts b/js/util/index.ts index 0d1d0b1a4..83d2b76c5 100644 --- a/js/util/index.ts +++ b/js/util/index.ts @@ -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";