Skip to content

feat(logger): add OpenTelemetry-compatible log emission - #2468

Open
Abhijeet Prasad (AbhiPrasad) wants to merge 2 commits into
mainfrom
abhi-feat-add-logger-log-emission
Open

feat(logger): add OpenTelemetry-compatible log emission#2468
Abhijeet Prasad (AbhiPrasad) wants to merge 2 commits into
mainfrom
abhi-feat-add-logger-log-emission

Conversation

@AbhiPrasad

@AbhiPrasad Abhijeet Prasad (AbhiPrasad) commented Sep 10, 2026

Copy link
Copy Markdown
Member

resolves https://linear.app/braintrustdata/issue/SDK-345/add-logging-api-to-javascript-sdk

Add Logger.emitLog() and severity helpers for creating independent log rows without manually constructing spans.

logger.error("Payment failed", { paymentId: "pay_123" });
logger.emitLog("Retrying payment", "info", { attempt: 2 });

Correlate logs with active Braintrust or OpenTelemetry spans, while using a per-logger baseline trace for unscoped records:

helper -> emitLog -> type="log" row
                     |-- active span
                     |     trace ID = active trace ID
                     |     span ID  = active span ID
                     |
                     `-- no active span
                           trace ID = logger baseline trace ID
                           span ID  = newly generated span ID

Add `Logger.emitLog()` and severity helpers for creating independent `log`
rows without manually constructing spans.

    logger.error("Payment failed", { paymentId: "pay_123" });
    logger.emitLog("Retrying payment", "info", { attempt: 2 });

Correlate logs with active Braintrust or OpenTelemetry spans, while using a
per-logger baseline trace for unscoped records:

    helper -> emitLog -> type="log" row
                         |-- active span
                         |     trace ID = active trace ID
                         |     span ID  = active span ID
                         |
                         `-- no active span
                               trace ID = logger baseline trace ID
                               span ID  = newly generated span ID

Map the six base OpenTelemetry severities into `context.otel.log`, populate
`error` for string bodies at error or fatal severity, and preserve
synchronous-flush behavior.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 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-09-10T22:41:01.175763Z c083a6e PR opened
ℹ️ 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.

@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: c083a6e633

ℹ️ 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 thread js/src/logger.ts
Comment on lines +2939 to +2941
...(severityNumber >= OTEL_LOG_LEVELS.error && typeof body === "string"
? { error: body }
: {}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve non-string error bodies in the error field

When callers use the natural logger.error(new Error("Payment failed")) form—or pass any structured error body—this condition omits the Braintrust error field and records the value only as output, unlike an equivalent string body. Consequently, consumers and UI behavior that identify failures through the error column will not recognize these error/fatal records as failures; the existing serializer already supports Error values, so error-severity bodies should be assigned to error regardless of whether they are strings.

Useful? React with 👍 / 👎.

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.

1 participant