Skip to content

[OTEL] Logging setup - #2853

Open
George Ng (GeorgeNgMsft) wants to merge 13 commits into
mainfrom
dev/georgeng/otel-phase2-structured-logging
Open

[OTEL] Logging setup#2853
George Ng (GeorgeNgMsft) wants to merge 13 commits into
mainfrom
dev/georgeng/otel-phase2-structured-logging

Conversation

@GeorgeNgMsft

@GeorgeNgMsft George Ng (GeorgeNgMsft) commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds opt-in OpenTelemetry logging to TypeAgent. Logs can be written to a local JSONL file, exported through OTLP, and correlated with traces.

image image

Logging Pipeline

  • Converts existing structured logger events into bounded, redacted OTel records.
  • Preserves trace context and  info ,  warning , and  error  severity.
  • Copies enabled  typeagent:*  debug output as OTel  DEBUG  records without changing console output.
  • Supports agent subprocesses with separate  debug  module instances.

Export and Privacy

  • Exports logs through OTLP and/or local per-process JSONL files.
  • Limits payload depth and size, handles cycles, and isolates telemetry failures.
  • Allowlists dispatcher identifiers, statuses, timings, and counts.
  • Excludes prompts, user requests, action parameters, errors, stacks, and unknown dispatcher fields.

Configuration and Developer Tools

  • Adds YAML and environment settings for OTLP, JSONL, structured logs, debug bridging, and trace sampling.
  • Wires telemetry into the agent server, API server, CLI, shell, dispatcher, and agent subprocesses.
  • Adds  pnpm run telemetry:grafana  to install or run Grafana LGTM locally on loopback-only ports.
  • Documents the full setup and validation workflow.

Data Flow

Structured Logger → privacy filter → OTel Logs API ─┬→ local JSONL
Enabled debug output → debug bridge ────────────────└→ OTLP → Loki/Grafana
Active spans ─────────────────────────────────────────→ OTLP → Tempo/Grafana

Add severity-aware Structured Logger events, bounded cycle-safe OTel body mapping, trace correlation, and defense-in-depth redaction.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 67859676-8c6c-43f7-bfe4-ee784f8db79d
Add multi-instance debug bridging, bounded process-safe JSONL log export, configuration, failure diagnostics, and correlated local integration coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 67859676-8c6c-43f7-bfe4-ee784f8db79d
### Summary
Builds on the previously-landed `OtelLoggerSink`, debug bridge, and
JSONL
exporter by **wiring them into every TypeAgent-owned Node host** and
making
structured-log export **explicitly opt-in**. No new telemetry primitives
— this
is composition, gating, and hardening. Existing `debug`/`DEBUG` output
is
unchanged.

### Changes

**Configuration-driven structured logs**

• Adds  telemetry.structuredLogs , defaulting to  false  because
dispatcher event payloads may contain user data.
• Supports the  TYPEAGENT_OTEL_STRUCTURED_LOGS  environment override.
• Hosts resolve telemetry configuration once and pass the effective
value into  DispatcherOptions.telemetry.structuredLogs .
•  getLoggerSink  attaches  OtelLoggerSink  only when structured logging
is enabled. Existing debug and database sinks are unchanged.
• Agent server, API, and standalone shell apply the setting to the
dispatchers they create.

**Host telemetry and debug-bridge wiring**

• Wires  initTelemetry({ config, debugModules, debugBridge })  into the
agent server, API, and shell composition roots.
• CLI entry points and agent subprocesses provide their  debug  module
instances to telemetry initialization.
• Agent-server hosts include the legacy  agent-server:*  namespace
without renaming namespaces or breaking existing  DEBUG  configurations.
• Prompt logger output remains intentionally excluded from the debug
bridge.

**Agent subprocess support**

• Resolves an agent’s local  debug  package before telemetry
initialization so separately installed module instances are bridged.
• Uses CommonJS resolution rather than importing an absolute filesystem
path, preserving Windows compatibility.
• Extracts this behavior into  agentDebug.ts  with coverage for
agent-local and shared module instances.

**Debug-bridge hardening**

• Adds configurable included namespace prefixes while retaining
 typeagent:*  as the default.
• Tracks effective bridge options for each installed module.
• Rejects repeated installation with conflicting namespace or redaction
options instead of silently ignoring the later policy.
• Preserves idempotent, reference-counted installation when options
match.

**Tests**

• Covers real  debug  instances created before and after bridge
installation.
• Covers multiple debug module instances, restoration, reference
counting, and conflicting options.
• Verifies legacy namespace inclusion and continued prompt logger
exclusion.
• Covers YAML and environment resolution for  telemetry.structuredLogs .
• Covers Windows-safe agent-local debug module loading.

---------

Copilot-Session: 6407aa6e-4d59-49ec-9fa4-5a321f2971ef
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

# Conflicts:
#	ts/packages/telemetry/src/otel/bootstrap.ts
@GeorgeNgMsft
George Ng (GeorgeNgMsft) marked this pull request as ready for review August 13, 2026 04:42
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