Log multiple projects
The first logger you initialize in your program becomes the current (default) logger. Any subsequent traced function calls will use the current logger. If you’d like to log to multiple projects, you will need to create multiple loggers, in which case setting just one as the current leads to unexpected behavior. When you initialize a logger, usesetCurrent: false to set it as the current logger.
Cache loggers
When you initialize a logger, it performs some background work to (a) login to Braintrust if you haven’t already, and (b) fetch project metadata. This background work does not block your code; however, if you initialize a logger on each request, it will slow down logging performance quite a bit. Instead, it’s a best practice to cache these loggers and reuse them:Initialize login
The logger lazily authorizes against Braintrust when it is first used. This information is shared across loggers, but you may want to explicitly calllogin() once to avoid having to pass in an API key to each logger (or
to use the BRAINTRUST_API_KEY environment variable).
There is a lower-level mechanism which can even let you use different API keys for different loggers, but it’s not documented
or officially supported. Get in touch if you need this.