feat(logger): add OpenTelemetry-compatible log emission - #2468
feat(logger): add OpenTelemetry-compatible log emission#2468Abhijeet Prasad (AbhiPrasad) wants to merge 2 commits into
Conversation
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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
There was a problem hiding this comment.
💡 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".
| ...(severityNumber >= OTEL_LOG_LEVELS.error && typeof body === "string" | ||
| ? { error: body } | ||
| : {}), |
There was a problem hiding this comment.
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 👍 / 👎.
resolves https://linear.app/braintrustdata/issue/SDK-345/add-logging-api-to-javascript-sdk
Add
Logger.emitLog()and severity helpers for creating independentlogrows without manually constructing spans.Correlate logs with active Braintrust or OpenTelemetry spans, while using a per-logger baseline trace for unscoped records: