@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
@@ -0,0 +1,261 @@
1
+ import type { Counter, Histogram, Meter, Span, Tracer, UpDownCounter } from "@opentelemetry/api";
2
+ import type { Logger } from "@opentelemetry/api-logs";
3
+ import type { EnsureProjectConfig as BootstrapEnsureProjectConfig } from "../config/bootstrap-project-config.ts";
4
+ import type {
5
+ LoadSessionConfigOptions,
6
+ LoadSessionConfigResult,
7
+ SessionConfigDiagnostics,
8
+ } from "../config/load-config.ts";
9
+ import type { ObservMeConfig } from "../config/schema.ts";
10
+ import type { ObservMeLogSdk } from "../otel/logs.ts";
11
+ import type { ObservMeMetricSdk } from "../otel/metrics.ts";
12
+ import type { ObservMeOtelSdkController } from "../otel/sdk.ts";
13
+ import type { ObservMeTraceSdk } from "../otel/traces.ts";
14
+ import type { BoundedMap } from "../util/bounded-map.ts";
15
+ import type { AgentLineageContext } from "./agent-lineage.ts";
16
+ import type { AgentTreeTracker } from "./agent-tree-tracker.ts";
17
+ import type {
18
+ AgentWaitJoinState,
19
+ ChildFailureAccountingState,
20
+ SubagentSpawnState,
21
+ } from "./subagent-types.ts";
22
+
23
+ export type AttributePrimitive = boolean | number | string | string[];
24
+ export type AttributeMap = Record<string, AttributePrimitive>;
25
+ export type TelemetryMeter = Pick<Meter, "createCounter" | "createHistogram" | "createUpDownCounter">;
26
+ export type TelemetryTracer = Pick<Tracer, "startSpan">;
27
+ export type TelemetryLogger = Pick<Logger, "emit">;
28
+ export type Handler = (event: unknown, ctx: ObservMeHandlerContext) => Promise<void> | void;
29
+ export type HandlerErrorRecorder = (name: string, error: unknown) => void;
30
+ export type LoadSessionConfig = (
31
+ options: LoadSessionConfigOptions,
32
+ ) => Promise<ObservMeConfig | LoadSessionConfigResult>;
33
+ export type StartSessionTelemetry = (options: StartSessionTelemetryOptions) => Promise<ObservMeTelemetrySession>;
34
+ export type ReadSessionHeader = (sessionFile: string) => Promise<SessionRecoveryHeader | undefined>;
35
+ export type EnsureProjectConfig = BootstrapEnsureProjectConfig;
36
+
37
+ export interface MinimalSessionCorrelation {
38
+ readonly workflowId?: string;
39
+ readonly agentId?: string;
40
+ readonly parentAgentId?: string;
41
+ readonly rootAgentId?: string;
42
+ readonly parentSessionId?: string;
43
+ readonly depth?: number;
44
+ readonly spawnId?: string;
45
+ readonly capability?: string;
46
+ }
47
+
48
+ export interface SessionRecoveryHeader {
49
+ readonly type?: string;
50
+ readonly version?: number | string;
51
+ readonly id?: string;
52
+ readonly timestamp?: string;
53
+ readonly cwd?: string;
54
+ readonly parentSession?: string;
55
+ readonly correlation?: MinimalSessionCorrelation;
56
+ }
57
+
58
+ export interface StartupRecoveryState {
59
+ readonly resumed: boolean;
60
+ readonly sessionFile?: string;
61
+ readonly header?: SessionRecoveryHeader;
62
+ readonly customCorrelation?: MinimalSessionCorrelation;
63
+ }
64
+
65
+ export interface ObservMeHandlerContext {
66
+ readonly cwd?: string;
67
+ readonly hasUI?: boolean;
68
+ readonly sessionFile?: string;
69
+ readonly session_file?: string;
70
+ readonly sessionId?: string;
71
+ readonly session_id?: string;
72
+ readonly model?: unknown;
73
+ readonly thinking?: unknown;
74
+ readonly ui?: {
75
+ notify?: (message: string, level?: "warning" | "info" | "error") => Promise<void> | void;
76
+ setStatus?: (key: string, value: string | undefined) => Promise<void> | void;
77
+ };
78
+ readonly isProjectTrusted?: () => boolean | Promise<boolean>;
79
+ readonly [key: string]: unknown;
80
+ }
81
+
82
+ export interface ObservMePiApi {
83
+ on: (eventName: string, handler: Handler) => void;
84
+ }
85
+
86
+ export interface RegisterHandlersOptions {
87
+ readonly loadConfig?: LoadSessionConfig;
88
+ readonly startTelemetry?: StartSessionTelemetry;
89
+ readonly env?: NodeJS.ProcessEnv;
90
+ readonly now?: () => number;
91
+ readonly configDirName?: string;
92
+ readonly trustedParentContext?: boolean;
93
+ readonly requireCompleteParentEnvelope?: boolean;
94
+ readonly readSessionHeader?: ReadSessionHeader;
95
+ readonly ensureProjectConfig?: EnsureProjectConfig;
96
+ readonly onHandlerError?: HandlerErrorRecorder;
97
+ }
98
+
99
+ export interface StartSessionTelemetryOptions {
100
+ readonly config: ObservMeConfig;
101
+ readonly lineage: AgentLineageContext;
102
+ readonly now?: () => number;
103
+ }
104
+
105
+ export interface TurnSequenceRegistry {
106
+ readonly size: number;
107
+ get: (runId: string) => number | undefined;
108
+ set: (runId: string, sequence: number) => unknown;
109
+ delete: (runId: string) => boolean;
110
+ clear: () => void;
111
+ }
112
+
113
+ export interface ObservMeTelemetrySession {
114
+ readonly config: ObservMeConfig;
115
+ readonly lineage: AgentLineageContext;
116
+ readonly controller: Pick<ObservMeOtelSdkController, "flush" | "shutdown">;
117
+ readonly tracer: TelemetryTracer;
118
+ readonly meter: TelemetryMeter;
119
+ readonly logger: TelemetryLogger;
120
+ readonly metrics: ObservMeMetrics;
121
+ readonly spans: SpanRegistry;
122
+ agentTree: AgentTreeTracker;
123
+ sessionSpan?: Span;
124
+ sessionAttributes?: AttributeMap;
125
+ workflowStartedAtMs?: number;
126
+ now?: () => number;
127
+ activeAgentRecorded: boolean;
128
+ currentAgentRunId?: string;
129
+ currentTurnId?: string;
130
+ currentLlmRequestId?: string;
131
+ currentToolCallId?: string;
132
+ pendingUserBash?: PendingBashOperationState;
133
+ currentBranchPreparation?: BranchPreparationState;
134
+ agentRunSequence: number;
135
+ llmRequestSequence: number;
136
+ toolCallSequence: number;
137
+ turnSequences: TurnSequenceRegistry;
138
+ childFailureAccounting?: BoundedMap<string, ChildFailureAccountingState>;
139
+ }
140
+
141
+ export interface ObservMeMetrics {
142
+ readonly handlerErrors: Counter;
143
+ readonly telemetryDropped: Counter;
144
+ readonly exportErrors: Counter;
145
+ readonly sessionsStarted: Counter;
146
+ readonly sessionsShutdown: Counter;
147
+ readonly workflowsStarted: Counter;
148
+ readonly workflowsCompleted: Counter;
149
+ readonly workflowErrors: Counter;
150
+ readonly agentRuns: Counter;
151
+ readonly agentRunErrors: Counter;
152
+ readonly turnsStarted: Counter;
153
+ readonly turnsCompleted: Counter;
154
+ readonly llmRequests: Counter;
155
+ readonly llmErrors: Counter;
156
+ readonly llmInputTokens: Counter;
157
+ readonly llmOutputTokens: Counter;
158
+ readonly llmCacheReadTokens: Counter;
159
+ readonly llmCacheWriteTokens: Counter;
160
+ readonly llmCacheWrite1hTokens: Counter;
161
+ readonly llmReasoningTokens: Counter;
162
+ readonly llmTotalTokens: Counter;
163
+ readonly llmCostUsd: Counter;
164
+ readonly toolCalls: Counter;
165
+ readonly toolFailures: Counter;
166
+ readonly bashExecutions: Counter;
167
+ readonly bashFailures: Counter;
168
+ readonly modelChanges: Counter;
169
+ readonly thinkingLevelChanges: Counter;
170
+ readonly compactions: Counter;
171
+ readonly branches: Counter;
172
+ readonly subagentsSpawned: Counter;
173
+ readonly subagentSpawnFailures: Counter;
174
+ readonly orphanAgents: Counter;
175
+ readonly traceContextPropagationFailures: Counter;
176
+ readonly childAgentFailures: Counter;
177
+ readonly parentRecoveredFromChildFailure: Counter;
178
+ readonly redactionFailures: Counter;
179
+ readonly eventsObserved: Counter;
180
+ readonly activeSpans: UpDownCounter;
181
+ readonly activeAgents: UpDownCounter;
182
+ readonly workflowDurationMs: Histogram;
183
+ readonly agentRunDurationMs: Histogram;
184
+ readonly agentLifetimeDurationMs: Histogram;
185
+ readonly subagentSpawnDurationMs: Histogram;
186
+ readonly agentFanoutCount: Histogram;
187
+ readonly agentTreeDepth: Histogram;
188
+ readonly agentTreeWidth: Histogram;
189
+ readonly agentWaitDurationMs: Histogram;
190
+ readonly agentJoinDurationMs: Histogram;
191
+ readonly turnDurationMs: Histogram;
192
+ readonly llmRequestDurationMs: Histogram;
193
+ readonly toolDurationMs: Histogram;
194
+ readonly bashDurationMs: Histogram;
195
+ readonly compactionTokensBefore: Histogram;
196
+ readonly promptSizeChars: Histogram;
197
+ readonly responseSizeChars: Histogram;
198
+ readonly toolResultSizeChars: Histogram;
199
+ readonly handlerDurationMs: Histogram;
200
+ readonly genAiClientTokenUsage: Histogram;
201
+ readonly genAiClientOperationDuration: Histogram;
202
+ }
203
+
204
+ export interface SpanRegistry {
205
+ readonly activeAgentRuns: BoundedMap<string, Span>;
206
+ readonly activeTurns: BoundedMap<string, Span>;
207
+ readonly activeLlmRequests: BoundedMap<string, Span>;
208
+ readonly activeToolCalls: BoundedMap<string, ToolCallState>;
209
+ readonly activeSubagentSpawns: BoundedMap<string, SubagentSpawnState>;
210
+ readonly activeAgentWaits: BoundedMap<string, AgentWaitJoinState>;
211
+ readonly activeAgentJoins: BoundedMap<string, AgentWaitJoinState>;
212
+ }
213
+
214
+ export interface CapturedContent {
215
+ readonly value: string;
216
+ readonly truncated: boolean;
217
+ readonly originalLength?: number;
218
+ }
219
+
220
+ export interface ToolCallState {
221
+ readonly span: Span;
222
+ labels: Record<string, string>;
223
+ completionLogAttributes: AttributeMap;
224
+ capturedResult?: CapturedContent;
225
+ }
226
+
227
+ export interface PendingBashOperationState {
228
+ readonly span: Span;
229
+ readonly startedAtMs: number;
230
+ readonly eventStartedAtMs?: number;
231
+ }
232
+
233
+ export interface BranchPreparationState {
234
+ readonly targetId?: string;
235
+ readonly oldLeafId?: string;
236
+ readonly commonAncestorId?: string;
237
+ readonly pathHash?: string;
238
+ }
239
+
240
+ export interface CompositeOtelSignalSdk {
241
+ readonly traceSdk: ObservMeTraceSdk;
242
+ readonly metricSdk: ObservMeMetricSdk;
243
+ readonly logSdk: ObservMeLogSdk;
244
+ start: () => void;
245
+ forceFlush: () => Promise<void>;
246
+ shutdown: () => Promise<void>;
247
+ }
248
+
249
+ export interface HandlerSessionState {
250
+ session?: ObservMeTelemetrySession;
251
+ }
252
+
253
+ export interface HandlerRegistration {
254
+ readonly eventName: string;
255
+ readonly handler: Handler;
256
+ }
257
+
258
+ export interface SessionConfigLoadResult {
259
+ readonly config: ObservMeConfig;
260
+ readonly diagnostics?: SessionConfigDiagnostics;
261
+ }
@@ -0,0 +1,75 @@
1
+ import { registerAgentTurnHandlers } from "./event-handlers/agent-turn.ts";
2
+ import { registerLifecycleHandlers } from "./event-handlers/lifecycle.ts";
3
+ import { registerLlmHandlers } from "./event-handlers/llm.ts";
4
+ import { registerSessionEventHandlers } from "./event-handlers/session-events.ts";
5
+ import { registerToolBashHandlers } from "./event-handlers/tool-bash.ts";
6
+ import {
7
+ HandlerRegistrar,
8
+ SerializedLifecycleQueue,
9
+ createStatefulHandlerErrorRecorder,
10
+ resolveObservMePiApi,
11
+ setDefaultHandlerErrorRecorder,
12
+ } from "./handler-runtime.ts";
13
+ import type { HandlerSessionState, RegisterHandlersOptions } from "./handler-types.ts";
14
+
15
+ export { buildSessionAttributes, readSessionHeaderFromFile } from "./event-handlers/lifecycle.ts";
16
+ export { deriveTurnId, emitLifecycleLog } from "./handler-internals.ts";
17
+ export {
18
+ OBSERVME_SEMCONV_VERSION,
19
+ buildTelemetryInstanceResourceAttributes,
20
+ createAgentTreeTracker,
21
+ createCompositeOtelSignalSdk,
22
+ createHistogram,
23
+ createObservMeMetrics,
24
+ createSpanRegistry,
25
+ createTurnSequenceRegistry,
26
+ isRootWorkflow,
27
+ safeHandler,
28
+ startSessionTelemetry,
29
+ withTelemetrySessionResourceAttributes,
30
+ workflowFailed,
31
+ } from "./handler-runtime.ts";
32
+ export type {
33
+ AttributeMap,
34
+ AttributePrimitive,
35
+ BranchPreparationState,
36
+ CompositeOtelSignalSdk,
37
+ EnsureProjectConfig,
38
+ Handler,
39
+ HandlerErrorRecorder,
40
+ LoadSessionConfig,
41
+ MinimalSessionCorrelation,
42
+ ObservMeHandlerContext,
43
+ ObservMeMetrics,
44
+ ObservMePiApi,
45
+ ObservMeTelemetrySession,
46
+ PendingBashOperationState,
47
+ ReadSessionHeader,
48
+ RegisterHandlersOptions,
49
+ SessionRecoveryHeader,
50
+ SpanRegistry,
51
+ StartSessionTelemetry,
52
+ StartSessionTelemetryOptions,
53
+ StartupRecoveryState,
54
+ TelemetryLogger,
55
+ TelemetryMeter,
56
+ TelemetryTracer,
57
+ ToolCallState,
58
+ TurnSequenceRegistry,
59
+ } from "./handler-types.ts";
60
+
61
+ export function registerHandlers(pi: unknown, options: RegisterHandlersOptions = {}): void {
62
+ const api = resolveObservMePiApi(pi);
63
+ const state: HandlerSessionState = {};
64
+ const errorRecorder = createStatefulHandlerErrorRecorder(state, options.onHandlerError);
65
+ const registrar = new HandlerRegistrar(api, state, errorRecorder);
66
+ const lifecycleQueue = new SerializedLifecycleQueue();
67
+
68
+ setDefaultHandlerErrorRecorder(errorRecorder);
69
+ registerLifecycleHandlers(registrar, state, options, lifecycleQueue);
70
+ registerAgentTurnHandlers(registrar, state);
71
+ registerLlmHandlers(registrar, state);
72
+ registerToolBashHandlers(registrar, state);
73
+ registerSessionEventHandlers(registrar, state);
74
+ registrar.commit();
75
+ }