agentleFS
braintrustdatabraintrustdata/braintrust-sdk/.agents/skills/instrumentation/SKILL.md

instrumentation

Skill30 starsChanged 17 days agoApache-2.0View on GitHub

Add or update Braintrust SDK instrumentation. Use when working on instrumentation of any kind - like wrappers, auto-instrumentation configs, invocation hooks, provider plugins, vendored SDK typings, or instrumentation-specific tests.

3 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions3 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 3

    1. macro-inc/macro★ 6ksame name
    2. basicmachines-co/basic-memory★ 4.5ksame name
    3. Moosync/Moosync★ 264same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository4 other files it gives its agents.

The file

Show its rules and text

We split this skill into the rules it gives an agent

14 rules. 0 are common, 7 are distinctive, and 7 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 7

    Distinctive

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read first based on the task:

    line 8
  2. Distinctive:

    Do not expose these internals through SDK entrypoints or public configuration options.

    line 32
  3. Distinctive:

    Update the transformer and its SDK callers together.

    line 33
  4. Very specific:

    Keep wrapping and tracing separate, including internal APIs.

    line 35
  5. Very specific:

    Put span creation, context propagation, and finalization in separate tracing functions.

    line 39
  6. Very specific:

    Do not add combined helpers such as traceInvocation or interceptAndTrace, or retain a tracing-event compatibility path.

    line 41
  7. Very specific:

    If a public instrumentation surface changes, check whether the export surface also needs updates in js/src/instrumentation/index.ts or …

    line 44
  8. Very specific:

    Treat Braintrust logging and span-finalization methods, including span.log() and span.end(), as non-throwing.

    line 49
  9. Very specific:

    Do not wrap these methods in defensive try/catch blocks or add fallback logic for hypothetical logging exceptions.

    line 50
  10. Very specific:

    Use the SDK debugLogger for SDK instrumentation diagnostics.

    line 51
  11. Distinctive:

    Keep whole-file responses intact, even if they exceed the threshold.

    line 62
  12. Distinctive:

    Do not modify package READMEs during instrumentation work unless the user specifically requests it or the change corrects outdated …

    line 65
  13. Distinctive:

    Before implementing or changing instrumentation it is advisable to add or adjust the e2e tests for the desired change, make it fail, then …

    line 71
  14. Distinctive:

    When validating instrumentation with real provider APIs or recording e2e cassettes, default to cheap models that support the behavior under …

    line 73

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Instrumentation Rules

Read first based on the task:

  • js/src/instrumentation/README.md for wrapping and tracing architecture
  • Closest file in js/src/instrumentation/core/ when changing shared invocation semantics
  • Closest file in js/src/instrumentation/plugins/ when changing provider-specific extraction or span mapping
  • Closest file in js/src/wrappers/ when manual wrappers and auto-instrumentation need to stay aligned
  • Closest test in js/tests/auto-instrumentations/ when changing hook, loader, bundler, or transform behavior
  • Closest e2e scenario in e2e/scenarios/*instrumentation* or e2e/scenarios/*node-hook* when the user-visible trace contract changes

Map the change before editing:

  • js/src/instrumentation/core/ - invocation definitions, independent tracing helpers, stream patching, shared types
  • js/src/instrumentation/plugins/ - explicit interceptor registration and provider-specific tracing functions
  • js/src/wrappers/ - manual instrumentation entrypoints that should mirror the same logical contracts
  • js/src/auto-instrumentations/ - loader and bundler instrumentation config
  • js/tests/auto-instrumentations/ - functional coverage for transformed code
  • e2e/scenarios/ - subprocess-level contract coverage against the mock Braintrust server
  • Non-invasive: instrumentation must not change user-visible behavior. Errors must still propagate, streams and promise subclasses must keep their original semantics, and any patch must be behavior-preserving and idempotent.
  • Inputs are untrusted: treat args, results, events, headers, and metadata as hostile. Prototype pollution is a concrete risk here. Avoid unsafe property access patterns, prototype-sensitive operations, and unnecessary mutation of third-party objects.
  • Support both auto-instrumentation and manual instrumentation. Auto-instrumentation does not cover every environment, loader, or framework.
  • For orchestrion auto-instrumentation, prefer targeting public API functions. Instrumenting internal helpers is more likely to break across library versions.
  • Braintrust's vendored Orchestrion implementation is purely internal to the SDK. Downstream packages must not depend on its APIs, config schema, generated helpers, or compatibility with upstream Orchestrion. Do not expose these internals through SDK entrypoints or public configuration options. Update the transformer and its SDK callers together; remove unused upstream features and compatibility scaffolding. Preserve instrumented application behavior, coordination between SDK copies, and upstream license notices.
  • Keep wrapping and tracing separate, including internal APIs. Define typed invocation hooks with defineInterceptor; intercept and invoke only compose and execute wrappers. Definitions describe call arguments, return values, and opaque additional data, without span provenance or tracing methods. The wrapping runtime must work without SDK initialization and have no dependency on spans, logging, or tracing lifecycle events. Put span creation, context propagation, and finalization in separate tracing functions. Plugins explicitly register those functions through intercept; shared tracing helpers accept callables and tracing configuration, never hooks or registration responsibilities. Do not add combined helpers such as traceInvocation or interceptAndTrace, or retain a tracing-event compatibility path. Manual wrappers and generated wrappers use the same hook through invoke and do not directly emit observability data.
  • Reuse shared repo utilities before introducing local helpers. Check js/util/index.ts, neighboring instrumentation files, and existing plugins/wrappers for utilities like isObject, merge helpers, and sanitizers before adding ad hoc replacements.
  • If a public instrumentation surface changes, check whether the export surface also needs updates in js/src/instrumentation/index.ts or js/src/exports.ts.
  • Preserve async context propagation. Changes around invocation hooks, stream patching, or loader hooks must keep the current span context across awaits and stream consumption.
  • Maintain isomorphic behavior. Node and browser/bundled paths must use compatible channel implementations and avoid channel-registry mismatches.
  • Setup, teardown, and patching must be idempotent. Enabling twice, disabling twice, or applying a patch twice should remain safe.
  • Promise/stream behavior must be preserved. Patches need to keep subclass/helper semantics intact.
  • Treat Braintrust logging and span-finalization methods, including span.log() and span.end(), as non-throwing. Do not wrap these methods in defensive try/catch blocks or add fallback logic for hypothetical logging exceptions.
  • Use the SDK debugLogger for SDK instrumentation diagnostics. Do not call console.* directly from instrumentation code; direct console use should stay inside the debug logger implementation or another explicitly justified exception.
  • Pass Error objects directly as span.log({ error }) values. The SDK serializes errors correctly, so do not add local helpers that manually turn errors into message/stack strings unless an external API requires a non-Error representation.
  • Log only the useful surface. Prefer narrow, stable payloads over dumping full request/response objects; exclude redundant or overly large data when possible.
  • Automatic capture of inline multimodal bytes as Braintrust attachments must be opt-in. Guard attachment creation and binary observation with BRAINTRUST_CAPTURE_ATTACHMENTS, and enable them only when its value is 1 or true. Audio/video recordings may contain personal data and are separately controlled with their own explicit flags (BRAINTRUST_CAPTURE_USER_AUDIO_ATTACHMENTS, BRAINTRUST_CAPTURE_AGENT_AUDIO_ATTACHMENTS): enabling the shared flag for other media never records audio/video without these being enabled. Preserve useful text, metadata, metrics, and remote references when attachment capture is disabled, and omit inline bytes from logged payloads.
  • Segmentable streaming media must use the shared configureInstrumentation({ streamingAttachmentBufferBytes }) setting instead of provider-specific chunk-size or time-based controls. It defaults to 4 MiB per logical media stream and counts binary attachment payload bytes after decoding and format conversion, including any required padding or silence. Flush near the threshold at valid media boundaries and flush remaining valid content when the recording ends. Preserve ordering, format metadata, and timestamps needed to interpret the attachments. Keep whole-file responses intact, even if they exceed the threshold; never arbitrarily split encoded images, audio, or video. This is a flush threshold, not a total memory limit or attachment-capture opt-in. Preserve application stream behavior and existing capture consent; keep any capture safety ceiling internal and distinct from the threshold.
  • Do not modify package READMEs during instrumentation work unless the user specifically requests it or the change corrects outdated information.
  • We want to limit our instrumentation to operations that are relevant for AI generations and operations (LLMs, embeddings, media generation, ...). Things like creating entities on platforms (CRUD for Workflows of Agent entities) is irrelevant to us.
  • When building instrumentation, we should always have a vendored type/interface for what we are wrapping. The type or interface should not be larger than what is relevant to the instrumentation. The type or interface should be used for typing invocation hooks and also should be used to assert the type on whatever is passed into wrappers as soon as the wrapper has verified that the passed in value is plausibly what should be wrapped.

Process

Before implementing or changing instrumentation it is advisable to add or adjust the e2e tests for the desired change, make it fail, then implement the new instrumentation until the test passes.

When validating instrumentation with real provider APIs or recording e2e cassettes, default to cheap models that support the behavior under test, unless the user explicitly requests otherwise. Keep prompts, output limits, and media duration small while preserving meaningful coverage.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.