@senad-d/observme 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/.env.example +57 -0
  2. package/CHANGELOG.md +52 -0
  3. package/LICENSE +21 -0
  4. package/ObservMe-Production-Docs/00-README.md +79 -0
  5. package/ObservMe-Production-Docs/01-requirements-and-scope.md +207 -0
  6. package/ObservMe-Production-Docs/02-reference-architecture.md +306 -0
  7. package/ObservMe-Production-Docs/03-pi-event-and-session-model.md +266 -0
  8. package/ObservMe-Production-Docs/04-telemetry-semantic-conventions.md +722 -0
  9. package/ObservMe-Production-Docs/05-otel-pipeline-and-collector.md +355 -0
  10. package/ObservMe-Production-Docs/06-security-privacy-redaction.md +294 -0
  11. package/ObservMe-Production-Docs/07-extension-implementation-blueprint.md +447 -0
  12. package/ObservMe-Production-Docs/08-query-grafana-integration.md +276 -0
  13. package/ObservMe-Production-Docs/09-dashboards-alerts-slos.md +640 -0
  14. package/ObservMe-Production-Docs/10-testing-release-operations.md +319 -0
  15. package/ObservMe-Production-Docs/11-deployment-runbooks.md +203 -0
  16. package/ObservMe-Production-Docs/12-configuration-reference.md +337 -0
  17. package/ObservMe-Production-Docs/13-source-notes.md +33 -0
  18. package/ObservMe-Production-Docs/pi-session-format.md +427 -0
  19. package/README.md +356 -0
  20. package/SECURITY.md +45 -0
  21. package/dashboards/observme-agent-node-graphs.json +250 -0
  22. package/dashboards/observme-agents.json +1880 -0
  23. package/dashboards/observme-alerts.yaml +113 -0
  24. package/dashboards/observme-branches-compactions.json +1042 -0
  25. package/dashboards/observme-cost.json +1254 -0
  26. package/dashboards/observme-errors.json +1659 -0
  27. package/dashboards/observme-export-health.json +1802 -0
  28. package/dashboards/observme-latency.json +1494 -0
  29. package/dashboards/observme-llm-conversations.json +730 -0
  30. package/dashboards/observme-logs-llm.json +644 -0
  31. package/dashboards/observme-models.json +933 -0
  32. package/dashboards/observme-overview.json +2129 -0
  33. package/dashboards/observme-slo-health.json +737 -0
  34. package/dashboards/observme-slos.yaml +56 -0
  35. package/dashboards/observme-tools.json +902 -0
  36. package/dashboards/observme-trace-journey.json +1793 -0
  37. package/docs/STRUCTURE.md +49 -0
  38. package/docs/agent-subagent-observability-requirements.md +997 -0
  39. package/docs/compatibility-matrix.md +39 -0
  40. package/docs/configuration-tui-design-standard.md +767 -0
  41. package/docs/configuration.md +38 -0
  42. package/docs/review-validation.md +115 -0
  43. package/docs/validation-flow.md +117 -0
  44. package/examples/collector.yaml +123 -0
  45. package/examples/observme.yaml +131 -0
  46. package/img/demo.gif +0 -0
  47. package/img/icon.svg +47 -0
  48. package/package.json +103 -0
  49. package/src/commands/obs-agents-runtime.ts +150 -0
  50. package/src/commands/obs-agents.ts +491 -0
  51. package/src/commands/obs-args.ts +63 -0
  52. package/src/commands/obs-backfill.ts +1334 -0
  53. package/src/commands/obs-command-support.ts +43 -0
  54. package/src/commands/obs-cost.ts +228 -0
  55. package/src/commands/obs-diagnostics.ts +22 -0
  56. package/src/commands/obs-errors.ts +156 -0
  57. package/src/commands/obs-health.ts +301 -0
  58. package/src/commands/obs-link.ts +90 -0
  59. package/src/commands/obs-logs.ts +194 -0
  60. package/src/commands/obs-loki-summary.ts +184 -0
  61. package/src/commands/obs-session.ts +259 -0
  62. package/src/commands/obs-status.ts +359 -0
  63. package/src/commands/obs-tools.ts +274 -0
  64. package/src/commands/obs-trace.ts +411 -0
  65. package/src/commands/obs.ts +211 -0
  66. package/src/config/bootstrap-project-config.ts +300 -0
  67. package/src/config/defaults.ts +143 -0
  68. package/src/config/load-config.ts +631 -0
  69. package/src/config/project-paths.ts +61 -0
  70. package/src/config/schema.ts +405 -0
  71. package/src/config/validate.ts +456 -0
  72. package/src/constants.ts +4 -0
  73. package/src/diagnostics/sanitize.ts +6 -0
  74. package/src/extension.ts +38 -0
  75. package/src/otel/logs.ts +160 -0
  76. package/src/otel/metrics.ts +165 -0
  77. package/src/otel/otlp-endpoint.ts +10 -0
  78. package/src/otel/sdk.ts +114 -0
  79. package/src/otel/shutdown.ts +102 -0
  80. package/src/otel/traces.ts +166 -0
  81. package/src/pi/agent-lineage.ts +378 -0
  82. package/src/pi/agent-tree-tracker.ts +258 -0
  83. package/src/pi/event-handlers/agent-turn.ts +155 -0
  84. package/src/pi/event-handlers/lifecycle.ts +642 -0
  85. package/src/pi/event-handlers/llm.ts +115 -0
  86. package/src/pi/event-handlers/session-events.ts +159 -0
  87. package/src/pi/event-handlers/tool-bash.ts +275 -0
  88. package/src/pi/handler-internals.ts +2154 -0
  89. package/src/pi/handler-runtime.ts +633 -0
  90. package/src/pi/handler-types.ts +261 -0
  91. package/src/pi/handlers.ts +75 -0
  92. package/src/pi/subagent-spawn.ts +975 -0
  93. package/src/pi/subagent-types.ts +29 -0
  94. package/src/privacy/content-capture.ts +104 -0
  95. package/src/privacy/hash.ts +93 -0
  96. package/src/privacy/redact.ts +619 -0
  97. package/src/privacy/secret-patterns.ts +185 -0
  98. package/src/privacy/truncate.ts +69 -0
  99. package/src/query/grafana-readiness.ts +164 -0
  100. package/src/query/grafana-transport.ts +481 -0
  101. package/src/query/grafana.ts +371 -0
  102. package/src/query/loki.ts +332 -0
  103. package/src/query/prometheus.ts +388 -0
  104. package/src/query/tempo.ts +332 -0
  105. package/src/safety/sensitive-input.ts +208 -0
  106. package/src/semconv/attributes.ts +279 -0
  107. package/src/semconv/metrics.ts +146 -0
  108. package/src/semconv/spans.ts +19 -0
  109. package/src/semconv/values.ts +13 -0
  110. package/src/util/bounded-map.ts +97 -0
  111. package/tsconfig.json +15 -0
package/.env.example ADDED
@@ -0,0 +1,57 @@
1
+ # ObservMe extension environment example.
2
+ #
3
+ # Option A: export these variables in your shell before starting Pi.
4
+ # Option B: copy this file to .env in the project root and fill values there.
5
+ # System environment variables override values from .env. Never commit .env.
6
+
7
+ # Core extension settings
8
+ OBSERVME_ENABLED=true
9
+ OBSERVME_ENVIRONMENT=development
10
+ OBSERVME_TENANT=local-dev
11
+
12
+ # Local OpenTelemetry Collector endpoint used by the bundled observability-stack.
13
+ OBSERVME_OTLP_ENDPOINT=http://localhost:4318
14
+ OBSERVME_OTLP_PROTOCOL=http/protobuf
15
+
16
+ # Optional OTLP bearer token for remote/secured collectors. Leave blank for local dev.
17
+ OBSERVME_OTLP_TOKEN=
18
+
19
+ # Grafana query settings for /obs health, /obs cost, /obs tools, /obs logs, /obs agents, and /obs trace.
20
+ OBSERVME_GRAFANA_URL=https://localhost:3000
21
+
22
+ # Choose one Grafana auth mode.
23
+ # Preferred: create a Grafana service-account token with Viewer access and set it here.
24
+ # OBSERVME_GRAFANA_TOKEN=glsa_your_service_account_token
25
+
26
+ # Local fallback: use Basic auth. For the bundled stack, copy the password from
27
+ # observability-stack/secrets/grafana_admin_password.
28
+ OBSERVME_GRAFANA_USERNAME=admin
29
+ OBSERVME_GRAFANA_PASSWORD=
30
+
31
+ # Bundled stack datasource UIDs. Change only if your Grafana datasource UIDs differ.
32
+ OBSERVME_GRAFANA_TEMPO_DATASOURCE_UID=tempo
33
+ OBSERVME_GRAFANA_LOKI_DATASOURCE_UID=loki
34
+ OBSERVME_GRAFANA_PROMETHEUS_DATASOURCE_UID=prometheus
35
+
36
+ # Required for the bundled local HTTPS endpoint with a self-signed certificate.
37
+ # Keep false for production CAs.
38
+ OBSERVME_GRAFANA_TLS_INSECURE_SKIP_VERIFY=true
39
+
40
+ # Avoid observability.local resolving to an unreachable IPv6 loopback first.
41
+ OBSERVME_GRAFANA_PREFER_IPV4=true
42
+
43
+ # Optional capture/debug toggles. Keep disabled unless you intentionally need local debugging.
44
+ OBSERVME_CAPTURE_PROMPTS=false
45
+ OBSERVME_CAPTURE_RESPONSES=false
46
+ OBSERVME_CAPTURE_THINKING=false
47
+ OBSERVME_CAPTURE_TOOL_ARGUMENTS=false
48
+ OBSERVME_CAPTURE_TOOL_RESULTS=false
49
+ OBSERVME_CAPTURE_BASH_COMMANDS=false
50
+ OBSERVME_CAPTURE_BASH_OUTPUT=false
51
+ OBSERVME_CAPTURE_FILE_PATHS=false
52
+ OBSERVME_REDACTION_ENABLED=true
53
+ # Required when redaction is enabled and any capture flag above is true.
54
+ # Generate a project-local value with: openssl rand -hex 32
55
+ OBSERVME_HASH_SALT=
56
+ OBSERVME_ALLOW_UNSAFE_CAPTURE=false
57
+ OBSERVME_ALLOW_INSECURE_TRANSPORT=true
package/CHANGELOG.md ADDED
@@ -0,0 +1,52 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ ### Added
6
+
7
+ - Expanded the Grafana suite with SLO Health, Trace Journey, Agent Node Graphs, and LLM Conversations dashboards, plus richer multi-agent, cost, latency, tool, model, log, and export-health views.
8
+ - Added correlated, content-safe telemetry for tool results, agent runs, workflows, subagent lifecycle events, interactive Bash executions, and configuration failures.
9
+ - Added W3C trace continuation for launcher-propagated parent contexts, with sanitized lineage validation and fail-safe span-link/log fallbacks.
10
+ - Added deterministic Pi runtime, Collector, Grafana-stack, dashboard, lifecycle, packaging, and configuration validation coverage.
11
+ - Added SonarQube-compatible LCOV output and focused tests for partial Pi runtimes, lifecycle races, fallback paths, privacy controls, and telemetry contracts.
12
+
13
+ ### Changed
14
+
15
+ - Split Pi event handling into focused lifecycle, agent/turn, LLM, tool/Bash, and session modules while preserving the `registerHandlers()` facade.
16
+ - Centralized telemetry conventions, content-capture policy, sensitive-value rejection, diagnostic sanitization, Grafana transport, `/obs` command plumbing, and trusted-project configuration bootstrap.
17
+ - Improved all dashboards with emitted-label-safe queries, selected-range calculations, zero/no-data states, bounded tables, canonical SLO formulas, and time-preserving Loki/Tempo drill-downs.
18
+ - Updated the Cost dashboard to aggregate spend across providers and models, preserve token totals from short-lived sessions, and display sub-cent values accurately.
19
+ - Updated README, dashboard, integration, and operator documentation to match the current command surface, package contents, privacy defaults, and validation workflows.
20
+ - Made strict TypeScript checks, offline coverage, deterministic fixtures, and Docker-backed integration validation more reliable in CI.
21
+
22
+ ### Fixed
23
+
24
+ - Fixed session, workflow, agent, turn, LLM, tool, Bash, histogram, active-span, failure/recovery, and session-count telemetry accuracy.
25
+ - Fixed lifecycle serialization, duplicate session replacement, bounded shutdown/flush behavior, backfill cancellation, parallel tool correlation, and bounded agent-tree state cleanup.
26
+ - Hardened configuration validation, project-root path confinement, endpoint security, custom redaction patterns, tenant-salted hashing, and environment propagation.
27
+ - Restored trusted-project redacted LLM capture and OpenAI Responses-style prompt capture while keeping capture disabled and redaction enabled by default.
28
+ - Remediated SonarQube maintainability and security findings across parsing, regexes, fallback handling, diagnostics, and default assignment.
29
+ - Fixed npm/CI dependency installation, package contents, README command drift, Grafana/Loki schema handling, and dashboard provisioning/query validation.
30
+
31
+ ## 0.1.0 - 2026-07-07
32
+
33
+ ### Added
34
+
35
+ - Bootstrapped the `@senad-d/observme` Pi extension with layered configuration, semantic conventions, session-scoped OpenTelemetry exporters, and bounded lifecycle management.
36
+ - Instrumented sessions, workflows, agents, turns, LLM requests, tools, interactive Bash, subagents, model/thinking changes, compaction, and branches with traces, metrics, and structured logs.
37
+ - Added privacy-first redaction, salted hashing, truncation, path scrubbing, secret detection, opt-in content capture, and trusted-project `.env`/`.pi/observme.yaml` support.
38
+ - Added `/obs` commands for status, health, session details, cost, traces, links, tools, errors, logs, agents, and bounded current-session backfill.
39
+ - Added Grafana clients for Prometheus, Loki, and Tempo with authenticated, timeout-bounded, secret-safe transport and query validation.
40
+ - Added dashboards for overview, cost, latency, tools, models, errors, branches/compactions, agents/subagents, export health, logs/LLM I/O, conversations, trace journeys, and agent node graphs.
41
+ - Added Prometheus alerts, SLO definitions, Collector/Grafana-stack examples, compatibility documentation, and production/operator guidance.
42
+ - Added unit, contract, cardinality, privacy, exporter-failure, Pi RPC, Collector, Grafana-stack, chaos, lifecycle, packaging, and synthetic performance tests.
43
+
44
+ ### Changed
45
+
46
+ - Reworked the original project specifications into session-sized tasks and reconciled production documentation with telemetry, privacy, lineage, validation, and packaging contracts.
47
+ - Replaced template scaffolding and metadata with the ObservMe extension factory, package identity, documentation, and shipped companion assets.
48
+
49
+ ### Fixed
50
+
51
+ - Hardened duplicate session startup, exporter timeout behavior, command parsing, query readiness, dashboard datasource UIDs, Loki labels, active-session trace guidance, and integration-test isolation.
52
+ - Corrected latency/size histogram emission, short-window PromQL, content-capture visibility, configuration diagnostics, and local Grafana authentication/TLS handling.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Senad Dizdarević
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,79 @@
1
+ # ObservMe Production Documentation
2
+
3
+ **ObservMe** is a production-grade Pi extension for observability. It captures Pi session, turn, tool, LLM, branch, compaction, and error events, translates them into OpenTelemetry telemetry, and exports them to a durable external observability stack such as OpenTelemetry Collector, Grafana Tempo, Grafana Loki, Prometheus, Mimir, or Grafana Cloud.
4
+
5
+ ObservMe is intentionally **not** a local analytics database. Pi agents are ephemeral. Observability data must leave the Pi agent process quickly, safely, and reliably. When multiple Pi agents or subagents are running, ObservMe must also preserve workflow and agent-tree lineage so operators can see which parent agent spawned each child agent and how the full orchestrated workload behaved.
6
+
7
+ ## Core Design
8
+
9
+ ```text
10
+ Pi Agent
11
+ └── ObservMe Pi Extension
12
+ ├── OTEL Traces ──► OTEL Collector ──► Tempo
13
+ ├── OTEL Metrics ──► OTEL Collector ──► Prometheus / Mimir
14
+ └── OTEL Logs ──► OTEL Collector ──► Loki
15
+
16
+ Grafana
17
+ ├── Tempo datasource
18
+ ├── Loki datasource
19
+ └── Prometheus/Mimir datasource
20
+ ```
21
+
22
+ ## Document Set
23
+
24
+ | File | Purpose |
25
+ |---|---|
26
+ | `01-requirements-and-scope.md` | Product goals, non-goals, personas, requirements, rollout phases |
27
+ | `02-reference-architecture.md` | Full system architecture and component responsibilities |
28
+ | `03-pi-event-and-session-model.md` | Pi session/event sources and how ObservMe interprets them |
29
+ | `04-telemetry-semantic-conventions.md` | ObservMe attribute, metric, log, and span naming specification |
30
+ | `05-otel-pipeline-and-collector.md` | OTLP exporter strategy and production Collector configurations |
31
+ | `06-security-privacy-redaction.md` | Prompt safety, secret redaction, PII handling, tenant isolation |
32
+ | `07-extension-implementation-blueprint.md` | TypeScript implementation architecture, modules, lifecycle, code patterns |
33
+ | `08-query-grafana-integration.md` | `/obs` commands, Grafana/Tempo/Loki/Prometheus query integration |
34
+ | `09-dashboards-alerts-slos.md` | Dashboard pack, PromQL, LogQL, TraceQL, alerts, SLOs |
35
+ | `10-testing-release-operations.md` | Test strategy, chaos testing, performance validation, release process |
36
+ | `11-deployment-runbooks.md` | Local, Docker Compose, Kubernetes, and production runbooks |
37
+ | `12-configuration-reference.md` | Complete ObservMe configuration schema and examples |
38
+ | `13-source-notes.md` | Official documentation cross-check notes and external assumptions |
39
+ | `pi-session-format.md` | Pi session JSONL reference copied and adapted from Pi's official session-format documentation |
40
+
41
+ ## Production Principles
42
+
43
+ 1. **OTLP-first.** ObservMe emits OpenTelemetry traces, metrics, and logs.
44
+ 2. **No durable local telemetry storage.** Only bounded in-memory queues are allowed.
45
+ 3. **Fail open.** If observability fails, Pi must continue operating.
46
+ 4. **Privacy by default.** Prompt and response content capture is disabled by default.
47
+ 5. **Pi-native and OTEL-compatible semantics.** ObservMe uses `observme.*` and `pi.*` for Pi-specific concepts and official OpenTelemetry `gen_ai.*` attributes where they fit; it does not depend on OpenInference.
48
+ 6. **Agent lineage by design.** Agent and subagent telemetry carries `pi.agent.*` lineage attributes and, where possible, W3C trace context so parent/child relationships survive process boundaries.
49
+ 7. **Workflow/tree observability.** Orchestrator workloads are modeled as agent trees with `pi.workflow.*` correlation, depth, fan-out, wait/join, orphan, and critical-path signals so operators can understand both single-agent and multi-agent execution.
50
+ 8. **Collector recommended.** Direct-to-backend export is allowed only for development or constrained environments.
51
+ 9. **Backend-neutral.** Tempo/Loki/Prometheus are reference backends, not hard dependencies.
52
+
53
+ ## Minimum Viable Production Release
54
+
55
+ A production-ready `1.0.0` release must include:
56
+
57
+ - Extension load and health checks
58
+ - Session, workflow, agent-run, turn, LLM, tool, subagent-spawn, agent wait/join, compaction, branch, model-change telemetry
59
+ - Multi-agent tree metrics for active agents, depth, fan-out, orphan agents, trace-context propagation failures, child failures, and workflow duration
60
+ - OTLP trace exporter
61
+ - OTLP metric exporter
62
+ - OTLP log exporter
63
+ - Configurable redaction and capture controls
64
+ - Bounded queues and exporter timeouts
65
+ - Grafana dashboard JSON
66
+ - Collector reference configs
67
+ - Tests for event mapping, redaction, exporter failure, and cardinality
68
+ - `/obs status`, `/obs health`, `/obs session`, `/obs cost`, `/obs trace`, `/obs agents` commands
69
+
70
+ ## Source References
71
+
72
+ This document set assumes:
73
+
74
+ - Pi extensions provide documented lifecycle hooks, commands, tools, custom entries, session events, and queryable session state.
75
+ - Pi can run multiple extension instances or spawn additional Pi processes through tools/subagent patterns; cross-process workflow and parent/child lineage requires explicit ObservMe correlation and trace-context propagation.
76
+ - Pi sessions are JSONL files with typed entries such as `message`, `compaction`, `branch_summary`, `model_change`, `thinking_level_change`, `custom`, `custom_message`, `label`, and `session_info`.
77
+ - OpenTelemetry Collector receives, processes, and exports telemetry via pipelines.
78
+ - OpenTelemetry GenAI semantic conventions are the official OTEL namespace for GenAI client/agent spans, attributes, and metrics, but many GenAI fields are still experimental/evolving in SDK packages; ObservMe extends them for Pi-specific workflow concepts.
79
+ - Grafana Tempo, Loki, and Prometheus/Mimir are reference storage systems for traces, logs, and metrics.
@@ -0,0 +1,207 @@
1
+ # ObservMe Requirements and Scope
2
+
3
+ ## 1. Product Definition
4
+
5
+ ObservMe is a Pi extension that instruments Pi agents and sends observability data to an external telemetry platform using OpenTelemetry.
6
+
7
+ ObservMe must answer questions such as:
8
+
9
+ - Which Pi sessions are running now?
10
+ - Which sessions are expensive?
11
+ - Which models are used most often?
12
+ - Which tools fail or run slowly?
13
+ - Which prompts or tool calls caused high latency?
14
+ - How often do agents branch or compact context?
15
+ - Which projects, users, or environments generate the most cost?
16
+ - What happened in an ephemeral agent after it disappeared?
17
+ - Which parent agent spawned a subagent, and what did the child agent do?
18
+ - How deep and wide did an orchestrated multi-agent workflow become?
19
+ - Which child or grandchild agent was on the critical path?
20
+ - Did any child agent become orphaned, fail to report lineage, or continue after the parent finished?
21
+ - Did one orchestrator prompt amplify cost, latency, or tool usage through excessive fan-out?
22
+
23
+ ## 2. Personas
24
+
25
+ ### Platform Engineering
26
+
27
+ Needs centralized observability, retention, SLOs, alerts, and tenant isolation.
28
+
29
+ ### AI Platform Owner
30
+
31
+ Needs cost, model usage, prompt efficiency, failure analysis, and quality signals.
32
+
33
+ ### Developer Using Pi
34
+
35
+ Needs quick session diagnostics from inside Pi via `/obs` commands.
36
+
37
+ ### Security / Compliance
38
+
39
+ Needs prompt capture off by default, redaction controls, audit trails, and safe handling of code and secrets.
40
+
41
+ ## 3. Hard Requirements
42
+
43
+ ### 3.1 External Durability
44
+
45
+ ObservMe must not depend on local Pi storage for telemetry durability. Pi sessions may be ephemeral or deleted. Telemetry must be exported to a central durable backend as close to real time as possible.
46
+
47
+ ### 3.2 No Durable Local Telemetry Database
48
+
49
+ ObservMe must not create SQLite, local JSONL telemetry archives, parquet files, or long-lived caches. Allowed local state:
50
+
51
+ - In-memory span registry
52
+ - In-memory metric instruments
53
+ - Bounded retry queue inside OTEL SDK/exporter
54
+ - Optional one-line session/agent correlation custom entry if explicitly enabled
55
+
56
+ ### 3.3 OTEL Native
57
+
58
+ ObservMe must use OpenTelemetry APIs and OTLP exporters for traces, metrics, and logs. Where OpenTelemetry GenAI semantic conventions apply, ObservMe should emit the official `gen_ai.*` attributes in addition to Pi-specific `pi.*` attributes.
59
+
60
+ ### 3.4 Collector First
61
+
62
+ The default topology is:
63
+
64
+ ```text
65
+ ObservMe -> OTEL Collector -> Backends
66
+ ```
67
+
68
+ Direct export to Tempo, Loki, Prometheus, or Grafana Cloud is allowed but not the default production recommendation.
69
+
70
+ ### 3.5 Fail Open
71
+
72
+ ObservMe must never block Pi agent execution because the collector or backend is down.
73
+
74
+ Required behavior:
75
+
76
+ - Export failures are logged locally only as minimal warnings through Pi UI when debug is enabled.
77
+ - Telemetry is dropped when queues are full.
78
+ - Tool calls, model calls, and sessions must continue.
79
+
80
+ ### 3.6 Privacy by Default
81
+
82
+ Default settings:
83
+
84
+ ```yaml
85
+ capture:
86
+ prompts: false
87
+ responses: false
88
+ thinking: false
89
+ toolArguments: false
90
+ toolResults: false
91
+ bashCommands: false
92
+ bashOutput: false
93
+ filePaths: false
94
+ ```
95
+
96
+ Metadata such as token counts, duration, status, model, provider, tool name, agent role, subagent depth, and error class is captured by default. High-cardinality identifiers such as `pi.workflow.id`, `pi.workflow.root_agent_id`, `pi.agent.id`, `pi.agent.parent_id`, `pi.agent.run.id`, `pi.session.id`, trace IDs, and tool-call IDs are allowed on spans/logs but must not be promoted to metric labels by default.
97
+
98
+ ### 3.7 Multi-Agent Workflow and Subagent Lineage
99
+
100
+ Adding a single `agent_id` is necessary but not sufficient for multi-agent observability. ObservMe must model the workflow and lineage explicitly:
101
+
102
+ ```text
103
+ pi.workflow.id # generated workflow/root execution id; high cardinality, traces/logs only
104
+ pi.workflow.root_agent_id
105
+ pi.agent.id # current logical Pi agent runtime
106
+ pi.agent.parent_id # parent agent when this is a subagent
107
+ pi.agent.root_id # root agent in the tree
108
+ pi.agent.depth # 0 for root, 1+ for subagents
109
+ pi.agent.spawn.id # individual spawn operation id when known
110
+ pi.agent.spawn.tool_call_id
111
+ ```
112
+
113
+ Preferred behavior:
114
+
115
+ 1. Generate `pi.agent.id` at session runtime startup unless supplied by trusted parent context.
116
+ 2. When a tool/extension spawns a subagent, pass W3C `traceparent`/`tracestate` plus ObservMe lineage environment variables to the child process.
117
+ 3. If trace context is propagated, make the subagent session span a descendant of the parent spawn/tool span.
118
+ 4. If trace context cannot be propagated, emit the child as a separate trace with span links and the `pi.agent.parent_id`/`pi.agent.root_id` attributes.
119
+ 5. Track agent-tree depth, fan-out, active children, orphaned children, trace-context propagation failures, child failures, and parent wait/join latency.
120
+ 6. Keep workflow IDs and agent IDs out of metric labels; use traces and logs for per-workflow/per-agent drill-down, and low-cardinality labels such as `agent_role`, `agent_capability`, `subagent_depth`, `spawn_type`, or `spawn_reason` for aggregate metrics.
121
+
122
+ ## 4. Non-Goals
123
+
124
+ ObservMe is not:
125
+
126
+ - A local trace database
127
+ - A replacement for Grafana
128
+ - A replacement for OTEL Collector
129
+ - An OpenInference implementation
130
+ - A replacement for official OpenTelemetry GenAI semantic conventions
131
+ - A vendor-specific AI observability SDK
132
+ - A prompt evaluation framework
133
+ - A policy enforcement extension
134
+ - A session replay system by default
135
+
136
+ Session replay can be enabled only with explicit content capture settings.
137
+
138
+ ## 5. Production Capabilities
139
+
140
+ ### Traces
141
+
142
+ - Session root span
143
+ - Agent-run spans
144
+ - Turn spans
145
+ - LLM request spans
146
+ - Tool call spans
147
+ - Subagent-spawn spans
148
+ - Agent wait/join spans for multi-agent critical-path analysis
149
+ - Bash execution spans
150
+ - Compaction spans
151
+ - Branch spans
152
+ - Extension error spans
153
+
154
+ ### Metrics
155
+
156
+ - Token counters
157
+ - Cost counters
158
+ - Turn counters
159
+ - Tool call counters
160
+ - Error counters
161
+ - Latency histograms
162
+ - Queue/drop counters
163
+ - Export health metrics
164
+ - Agent-run and subagent-spawn counters
165
+ - Workflow counters and duration histograms
166
+ - Active-agent gauges
167
+ - Agent-tree depth, width, and fan-out histograms
168
+ - Orphan-agent and trace-context propagation failure counters
169
+ - Parent wait/join duration histograms
170
+ - Child-agent failure and recovery counters
171
+
172
+ ### Logs
173
+
174
+ - Structured session events
175
+ - Structured tool events
176
+ - Structured model events
177
+ - Structured workflow, agent-run, subagent-spawn, wait/join, orphan-agent, and trace-context propagation events
178
+ - Redacted error logs
179
+ - Optional prompt and response logs
180
+
181
+ ### Query Commands
182
+
183
+ - `/obs status`
184
+ - `/obs health`
185
+ - `/obs session`
186
+ - `/obs cost`
187
+ - `/obs trace`
188
+ - `/obs tools`
189
+ - `/obs errors`
190
+ - `/obs logs`
191
+ - `/obs link`
192
+ - `/obs agents`
193
+
194
+ ## 6. Success Criteria
195
+
196
+ ObservMe is production ready when:
197
+
198
+ 1. Telemetry from an ephemeral Pi agent survives after the agent is deleted.
199
+ 2. Grafana shows session traces in Tempo.
200
+ 3. Loki contains structured event logs for sessions and tools.
201
+ 4. Prometheus/Mimir contains token, cost, latency, and failure metrics.
202
+ 5. The extension survives backend outages without breaking Pi.
203
+ 6. Redaction tests prevent secrets from leaving the agent.
204
+ 7. Cardinality limits prevent observability stack overload.
205
+ 8. Users can open a Grafana trace link from Pi.
206
+ 9. Parent agents and spawned subagents can be correlated without adding high-cardinality workflow IDs or agent IDs to metrics.
207
+ 10. Orchestrator workflows expose depth, fan-out, active-agent, orphan, cost-amplification, and critical-path signals without adding workflow IDs or agent IDs to metric labels.