Skip to content

feat: Add braintrust/apply-instrumentation entrypoint for CJS/TS patching#2038

Open
Luca Forstner (lforst) wants to merge 4 commits into
mainfrom
lforst/apply-instrumentation
Open

feat: Add braintrust/apply-instrumentation entrypoint for CJS/TS patching#2038
Luca Forstner (lforst) wants to merge 4 commits into
mainfrom
lforst/apply-instrumentation

Conversation

@lforst
Copy link
Copy Markdown
Member

@lforst Luca Forstner (lforst) commented May 21, 2026

We have the problem that we don't have a good setup story around frameworks like Nestjs that are CJS but don't give you a clean way of passing the --import hook. For this I thought we could expose something like import 'braintrust/apply-instrumentation' which is simply an import with a side effect that applies runtime patching. It's also good for platforms like Vercel where passing the --import argument is super painful in general.

This will now be usable with

  • CJS doing require('braintrust/apply-instrumentation') for all subsequent requires
  • ESM doing import 'braintrust/apply-instrumentation' for all subsequent dynamic imports (import('foobar').then(() => console.log('foobar is instrumented')))

initLogger can be called whenever.

Currently we only expose this for Nodejs - I haven't looked into how to make this work for other frameworks. I generally like the ergonomics of this and it is an additional tool in our toolbox of doing instrumentation.

…ntation

# Conflicts:
#	js/src/auto-instrumentations/configs/all.ts
#	js/src/instrumentation/braintrust-plugin.ts
#	js/src/instrumentation/registry.ts
"braintrust": minor
---

feat: Add `braintrust/apply-instrumentation` entrypoint for CJS/TS patching
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.

should we call it braintrust/apply-auto-instrumentation instead?

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