Skip to content

feat: add _create_in_project_group to logger options - #837

Merged
Abhijeet Prasad (AbhiPrasad) merged 3 commits into
mainfrom
lforst/create-in-project-group
Oct 1, 2026
Merged

Abhijeet Prasad (AbhiPrasad) merged 3 commits into
mainfrom
lforst/create-in-project-group

Conversation

@lforst

@lforst Luca Forstner (lforst) commented Oct 1, 2026 •

Copy link
Copy Markdown
Member
  • When you call init_logger(project="..."), the SDK looks the project up by name and creates it if it doesn't exist yet. This happens lazily, the first time the logger actually needs the project ID.
  • Until now there was no way to say which project group a newly created project should go into. Logger-created projects always landed ungrouped.
  • init_logger now accepts an experimental _create_in_project_group option. When it is set, the SDK passes project_group_name along with the project name when it registers the project.
    • If the project already exists but belongs to a different group, the backend rejects the request with a 409. The SDK raises that error and does not retry without the group.
    • The option is ignored when project_id is passed, because no project is created in that case.
  • The group name is stored with the logger's other lazy project-resolution arguments. That means it is kept when a logger or span is exported and later resolved somewhere else, and it stays compatible with span exports from the JS SDK.
  • The option has a leading underscore because project_group_name isn't in the pinned OpenAPI schema yet. The SDK uses a local extension of the generated request type until it is.
import braintrust

logger = braintrust.init_logger(
    project="my-project",
    _create_in_project_group="my-group",  # new: create the project inside this existing project group
)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T20:03:51.627046Z df5e686 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment thread py/src/braintrust/logger.py Outdated
from requests.adapters import HTTPAdapter

from . import context, id_gen
from .api._generated.models.projects import CreateProject

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this will break tests, means we dont lazy load the api.

@AbhiPrasad

Copy link
Copy Markdown
Member

will take this over to fix CI

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df5e6867fc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment on lines +5229 to +5230
# A `project_name:` parent would register the project outside its group.
if not _id and (self.parent_compute_object_metadata_args or {}).get("project_group_name"):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve the group in exported OTel contexts

When an unresolved span from a grouped logger is passed to braintrust.otel.context_from_span_export(), that helper still converts compute_object_metadata_args to project_name:<name> via _get_braintrust_parent() and drops project_group_name. The receiving service will therefore register or route the project outside the requested group—the exact case this new special handling avoids for direct injection. Resolve the grouped project to a project_id in this export-to-OTel path as well.

Useful? React with 👍 / 👎.

@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit fe86bed into main Oct 1, 2026
83 checks passed
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) deleted the lforst/create-in-project-group branch October 1, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants