@smthrs/observability 0.33.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.
- package/LICENSE +21 -0
- package/docker-compose.otel.yml +104 -0
- package/grafana/dashboards/smithers-dashboard.json +453 -0
- package/grafana/provisioning/dashboards/dashboards.yml +12 -0
- package/grafana/provisioning/datasources/datasources.yml +49 -0
- package/loki/loki-config.yaml +35 -0
- package/otel-collector-config.yml +38 -0
- package/package.json +47 -0
- package/prometheus/prometheus.yml +8 -0
- package/src/MetricName.ts +1 -0
- package/src/MetricsServiceLive.js +9 -0
- package/src/README.md +28 -0
- package/src/ResolvedSmithersObservabilityOptions.ts +12 -0
- package/src/SmithersEvent.ts +773 -0
- package/src/SmithersLogFormat.ts +1 -0
- package/src/SmithersMetricDefinition.ts +15 -0
- package/src/SmithersMetricType.ts +1 -0
- package/src/SmithersMetricUnit.ts +1 -0
- package/src/SmithersObservability.js +15 -0
- package/src/SmithersObservabilityOptions.ts +12 -0
- package/src/SmithersObservabilityService.ts +13 -0
- package/src/_coreCorrelation/CorrelationContext.ts +10 -0
- package/src/_coreCorrelation/CorrelationContextLive.js +11 -0
- package/src/_coreCorrelation/CorrelationContextService.js +15 -0
- package/src/_coreCorrelation/CorrelationContextServiceShape.ts +12 -0
- package/src/_coreCorrelation/CorrelationPatch.ts +3 -0
- package/src/_coreCorrelation/README.md +20 -0
- package/src/_coreCorrelation/_correlationStorage.js +4 -0
- package/src/_coreCorrelation/correlationContextFiberRef.js +5 -0
- package/src/_coreCorrelation/correlationContextToLogAnnotations.js +18 -0
- package/src/_coreCorrelation/getCurrentCorrelationContext.js +9 -0
- package/src/_coreCorrelation/getCurrentCorrelationContextEffect.js +11 -0
- package/src/_coreCorrelation/index.js +14 -0
- package/src/_coreCorrelation/mergeCorrelationContext.js +51 -0
- package/src/_coreCorrelation/runWithCorrelationContext.js +14 -0
- package/src/_coreCorrelation/updateCurrentCorrelationContext.js +17 -0
- package/src/_coreCorrelation/withCorrelationContext.js +38 -0
- package/src/_coreCorrelation/withCurrentCorrelationContext.js +11 -0
- package/src/_coreMetrics.js +14 -0
- package/src/_coreMetricsShape.ts +44 -0
- package/src/_corePrometheus.js +91 -0
- package/src/_corePrometheusShape.ts +11 -0
- package/src/_coreTracing.js +132 -0
- package/src/_coreTracingShape.ts +17 -0
- package/src/_otelLogBuilders.js +102 -0
- package/src/_sessionFileResolvers.js +164 -0
- package/src/_smithersSpanAttributeAliases.js +19 -0
- package/src/_smithersTraceSpanStorage.js +3 -0
- package/src/_traceEventNormalizers.js +499 -0
- package/src/_traceRedaction.js +162 -0
- package/src/agentSessionEventToOtelLogRecord.js +55 -0
- package/src/agentTrace.ts +144 -0
- package/src/agentTraceCapabilities.js +151 -0
- package/src/annotateSmithersTrace.js +11 -0
- package/src/canonicalTraceEventToOtelLogRecord.js +55 -0
- package/src/correlation.js +56 -0
- package/src/createSmithersObservabilityLayer.js +59 -0
- package/src/createSmithersOtelLayer.js +23 -0
- package/src/createSmithersRuntimeLayer.js +2 -0
- package/src/detectAgentFamily.js +26 -0
- package/src/detectCaptureMode.js +24 -0
- package/src/emitOtelLogRecord.js +19 -0
- package/src/getCurrentSmithersTraceAnnotations.js +14 -0
- package/src/getCurrentSmithersTraceSpan.js +7 -0
- package/src/index.d.ts +1321 -0
- package/src/index.js +136 -0
- package/src/kindPhase.js +17 -0
- package/src/logging.js +248 -0
- package/src/makeSmithersSpanAttributes.js +20 -0
- package/src/metrics/README.md +22 -0
- package/src/metrics/SmithersMetricDefinition.ts +17 -0
- package/src/metrics/SmithersMetricType.ts +1 -0
- package/src/metrics/SmithersMetricUnit.ts +1 -0
- package/src/metrics/_asyncExternalWaitCounts.js +4 -0
- package/src/metrics/_buckets.js +37 -0
- package/src/metrics/_incrementGauge.js +11 -0
- package/src/metrics/_processStartMs.js +1 -0
- package/src/metrics/activeNodes.js +2 -0
- package/src/metrics/activeRuns.js +2 -0
- package/src/metrics/agentActionsTotal.js +2 -0
- package/src/metrics/agentDurationMs.js +3 -0
- package/src/metrics/agentErrorsTotal.js +2 -0
- package/src/metrics/agentEventsTotal.js +2 -0
- package/src/metrics/agentInvocationsTotal.js +2 -0
- package/src/metrics/agentRetriesTotal.js +2 -0
- package/src/metrics/agentSessionsTotal.js +2 -0
- package/src/metrics/agentTokensTotal.js +2 -0
- package/src/metrics/alertDeliveriesAttempted.js +2 -0
- package/src/metrics/alertDeliveriesSuppressed.js +2 -0
- package/src/metrics/alertsAcknowledgedTotal.js +2 -0
- package/src/metrics/alertsActive.js +2 -0
- package/src/metrics/alertsEscalatedTotal.js +2 -0
- package/src/metrics/alertsFiredTotal.js +2 -0
- package/src/metrics/alertsReopenedTotal.js +2 -0
- package/src/metrics/alertsResolvedTotal.js +2 -0
- package/src/metrics/alertsSilencedTotal.js +2 -0
- package/src/metrics/approvalPending.js +2 -0
- package/src/metrics/approvalWaitDuration.js +5 -0
- package/src/metrics/approvalsDenied.js +2 -0
- package/src/metrics/approvalsGranted.js +2 -0
- package/src/metrics/approvalsRequested.js +2 -0
- package/src/metrics/attemptDuration.js +3 -0
- package/src/metrics/attentionBacklog.js +2 -0
- package/src/metrics/cacheHits.js +2 -0
- package/src/metrics/cacheMisses.js +2 -0
- package/src/metrics/dbQueryDuration.js +3 -0
- package/src/metrics/dbRetries.js +2 -0
- package/src/metrics/dbTransactionDuration.js +3 -0
- package/src/metrics/dbTransactionRetries.js +2 -0
- package/src/metrics/dbTransactionRollbacks.js +2 -0
- package/src/metrics/devtoolsActiveSubscribers.js +2 -0
- package/src/metrics/devtoolsBackpressureDisconnectTotal.js +2 -0
- package/src/metrics/devtoolsDeltaBuildMs.js +3 -0
- package/src/metrics/devtoolsEventBytes.js +3 -0
- package/src/metrics/devtoolsEventTotal.js +2 -0
- package/src/metrics/devtoolsSnapshotBuildMs.js +5 -0
- package/src/metrics/devtoolsSubscribeTotal.js +2 -0
- package/src/metrics/errorsTotal.js +2 -0
- package/src/metrics/eventsEmittedTotal.js +2 -0
- package/src/metrics/externalWaitAsyncPending.js +2 -0
- package/src/metrics/gatewayApprovalDecisionsTotal.js +2 -0
- package/src/metrics/gatewayAuthEventsTotal.js +2 -0
- package/src/metrics/gatewayConnectionsActive.js +2 -0
- package/src/metrics/gatewayConnectionsClosedTotal.js +2 -0
- package/src/metrics/gatewayConnectionsTotal.js +2 -0
- package/src/metrics/gatewayCronTriggersTotal.js +2 -0
- package/src/metrics/gatewayErrorsTotal.js +2 -0
- package/src/metrics/gatewayHeartbeatTicksTotal.js +2 -0
- package/src/metrics/gatewayMessagesReceivedTotal.js +2 -0
- package/src/metrics/gatewayMessagesSentTotal.js +2 -0
- package/src/metrics/gatewayRpcCallsTotal.js +2 -0
- package/src/metrics/gatewayRpcDuration.js +3 -0
- package/src/metrics/gatewayRunEventBackpressureDisconnectTotal.js +4 -0
- package/src/metrics/gatewayRunsCompletedTotal.js +2 -0
- package/src/metrics/gatewayRunsStartedTotal.js +2 -0
- package/src/metrics/gatewaySignalsTotal.js +2 -0
- package/src/metrics/gatewayWebhooksReceivedTotal.js +2 -0
- package/src/metrics/gatewayWebhooksRejectedTotal.js +2 -0
- package/src/metrics/gatewayWebhooksVerifiedTotal.js +2 -0
- package/src/metrics/heartbeatDataSizeBytes.js +5 -0
- package/src/metrics/heartbeatIntervalMs.js +3 -0
- package/src/metrics/hotReloadDuration.js +3 -0
- package/src/metrics/hotReloadFailures.js +2 -0
- package/src/metrics/hotReloads.js +2 -0
- package/src/metrics/httpRequestDuration.js +3 -0
- package/src/metrics/httpRequests.js +2 -0
- package/src/metrics/index.d.ts +1163 -0
- package/src/metrics/index.js +168 -0
- package/src/metrics/memoryFactReads.js +3 -0
- package/src/metrics/memoryFactWrites.js +3 -0
- package/src/metrics/memoryMessageSaves.js +3 -0
- package/src/metrics/memoryRecallDuration.js +11 -0
- package/src/metrics/memoryRecallQueries.js +3 -0
- package/src/metrics/metricsServiceAdapter.js +181 -0
- package/src/metrics/nodeDuration.js +3 -0
- package/src/metrics/nodeRetriesTotal.js +2 -0
- package/src/metrics/nodesFailed.js +2 -0
- package/src/metrics/nodesFinished.js +2 -0
- package/src/metrics/nodesStarted.js +2 -0
- package/src/metrics/openApiToolCallErrorsTotal.js +3 -0
- package/src/metrics/openApiToolCallsTotal.js +3 -0
- package/src/metrics/openApiToolDuration.js +9 -0
- package/src/metrics/processHeapUsedBytes.js +2 -0
- package/src/metrics/processMemoryRssBytes.js +2 -0
- package/src/metrics/processUptimeSeconds.js +2 -0
- package/src/metrics/promptSizeBytes.js +3 -0
- package/src/metrics/replaysStarted.js +3 -0
- package/src/metrics/responseSizeBytes.js +3 -0
- package/src/metrics/rewindDurationMs.js +3 -0
- package/src/metrics/rewindFramesDeleted.js +3 -0
- package/src/metrics/rewindRollbackTotal.js +2 -0
- package/src/metrics/rewindSandboxesReverted.js +3 -0
- package/src/metrics/rewindTotal.js +2 -0
- package/src/metrics/runDuration.js +3 -0
- package/src/metrics/runForksCreated.js +3 -0
- package/src/metrics/runsAncestryDepth.js +3 -0
- package/src/metrics/runsCancelledTotal.js +2 -0
- package/src/metrics/runsCarriedStateBytes.js +5 -0
- package/src/metrics/runsContinuedTotal.js +2 -0
- package/src/metrics/runsFailedTotal.js +2 -0
- package/src/metrics/runsFinishedTotal.js +2 -0
- package/src/metrics/runsResumedTotal.js +2 -0
- package/src/metrics/runsTotal.js +2 -0
- package/src/metrics/sandboxActive.js +2 -0
- package/src/metrics/sandboxBundleSizeBytes.js +5 -0
- package/src/metrics/sandboxCompletedTotal.js +2 -0
- package/src/metrics/sandboxCreatedTotal.js +2 -0
- package/src/metrics/sandboxDurationMs.js +3 -0
- package/src/metrics/sandboxPatchCount.js +3 -0
- package/src/metrics/sandboxTransportDurationMs.js +5 -0
- package/src/metrics/schedulerConcurrencyUtilization.js +2 -0
- package/src/metrics/schedulerQueueDepth.js +2 -0
- package/src/metrics/schedulerWaitDuration.js +5 -0
- package/src/metrics/scorerDuration.js +9 -0
- package/src/metrics/scorerEventsFailed.js +2 -0
- package/src/metrics/scorerEventsFinished.js +2 -0
- package/src/metrics/scorerEventsStarted.js +2 -0
- package/src/metrics/scorersFailed.js +3 -0
- package/src/metrics/scorersFinished.js +3 -0
- package/src/metrics/scorersStarted.js +3 -0
- package/src/metrics/smithersMetricCatalog.js +893 -0
- package/src/metrics/smithersMetricCatalogByKey.js +2 -0
- package/src/metrics/smithersMetricCatalogByName.js +2 -0
- package/src/metrics/smithersMetricCatalogByPrometheusName.js +4 -0
- package/src/metrics/snapshotDuration.js +9 -0
- package/src/metrics/snapshotsCaptured.js +3 -0
- package/src/metrics/supervisorPollDuration.js +5 -0
- package/src/metrics/supervisorPollsTotal.js +2 -0
- package/src/metrics/supervisorResumeLag.js +5 -0
- package/src/metrics/supervisorResumedTotal.js +2 -0
- package/src/metrics/supervisorSkippedTotal.js +2 -0
- package/src/metrics/supervisorStaleDetected.js +2 -0
- package/src/metrics/taskHeartbeatTimeoutTotal.js +2 -0
- package/src/metrics/taskHeartbeatsTotal.js +2 -0
- package/src/metrics/timerDelayDuration.js +3 -0
- package/src/metrics/timersCancelled.js +2 -0
- package/src/metrics/timersCreated.js +2 -0
- package/src/metrics/timersFired.js +2 -0
- package/src/metrics/timersPending.js +2 -0
- package/src/metrics/toPrometheusMetricName.js +8 -0
- package/src/metrics/tokensCacheReadTotal.js +2 -0
- package/src/metrics/tokensCacheWriteTotal.js +2 -0
- package/src/metrics/tokensContextWindowBucketTotal.js +2 -0
- package/src/metrics/tokensContextWindowPerCall.js +5 -0
- package/src/metrics/tokensInputPerCall.js +3 -0
- package/src/metrics/tokensInputTotal.js +2 -0
- package/src/metrics/tokensOutputPerCall.js +3 -0
- package/src/metrics/tokensOutputTotal.js +2 -0
- package/src/metrics/tokensReasoningTotal.js +2 -0
- package/src/metrics/toolCallErrorsTotal.js +2 -0
- package/src/metrics/toolCallsTotal.js +2 -0
- package/src/metrics/toolDuration.js +3 -0
- package/src/metrics/toolOutputTruncatedTotal.js +2 -0
- package/src/metrics/trackEvent.js +608 -0
- package/src/metrics/updateAsyncExternalWaitPending.js +18 -0
- package/src/metrics/updateProcessMetrics.js +20 -0
- package/src/metrics/vcsDuration.js +3 -0
- package/src/normalizeStructuredEvent.js +15 -0
- package/src/prometheusContentType.js +1 -0
- package/src/renderPrometheusMetrics.js +212 -0
- package/src/resolveAgentTraceCapabilities.js +59 -0
- package/src/resolveSmithersObservabilityOptions.js +109 -0
- package/src/smithersMetrics.js +2 -0
- package/src/smithersSpanNames.js +6 -0
- package/src/unsupportedKindsForCapabilities.js +32 -0
- package/src/withSmithersSpan.js +17 -0
- package/tempo/tempo.yml +17 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { buildOtelAttributes, buildOtelLogRecord, inferSessionSeverity } from "./_otelLogBuilders.js";
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {import('./agentTrace.ts').AgentSessionTranscriptEvent} AgentSessionTranscriptEvent
|
|
4
|
+
* @typedef {import('./_otelLogBuilders.js').OtelLogRecord} OtelLogRecord
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {AgentSessionTranscriptEvent} event
|
|
9
|
+
* @param {{ agentId?: string; model?: string }} [context]
|
|
10
|
+
* @returns {OtelLogRecord}
|
|
11
|
+
*/
|
|
12
|
+
export function agentSessionEventToOtelLogRecord(event, context) {
|
|
13
|
+
const attributes = buildOtelAttributes(
|
|
14
|
+
{
|
|
15
|
+
"smithers.event.category": "agent-session",
|
|
16
|
+
"smithers.trace.version": undefined,
|
|
17
|
+
"smithers.transcript.version": event.transcriptVersion,
|
|
18
|
+
"run.id": event.runId,
|
|
19
|
+
"workflow.path": event.workflowPath,
|
|
20
|
+
"workflow.hash": event.workflowHash,
|
|
21
|
+
"node.id": event.nodeId,
|
|
22
|
+
"node.iteration": event.iteration,
|
|
23
|
+
"node.attempt": event.attempt,
|
|
24
|
+
"agent.family": event.source.agentFamily,
|
|
25
|
+
"agent.id": context?.agentId,
|
|
26
|
+
"agent.model": context?.model,
|
|
27
|
+
"agent.capture_mode": event.source.captureMode,
|
|
28
|
+
"trace.completeness": undefined,
|
|
29
|
+
"event.kind": undefined,
|
|
30
|
+
"event.phase": undefined,
|
|
31
|
+
"event.sequence": undefined,
|
|
32
|
+
"source.raw_type": undefined,
|
|
33
|
+
"source.raw_event_id": undefined,
|
|
34
|
+
"source.observed": undefined,
|
|
35
|
+
"provider.session_id": event.source.providerSessionId,
|
|
36
|
+
"provider.thread_id": event.source.providerThreadId,
|
|
37
|
+
"session.ingest_source": event.source.ingestSource,
|
|
38
|
+
"session.observed_live": event.source.observedLive,
|
|
39
|
+
"session.row_type": event.event.rowType,
|
|
40
|
+
"session.row_sequence": event.event.sequence,
|
|
41
|
+
},
|
|
42
|
+
event.annotations,
|
|
43
|
+
);
|
|
44
|
+
return buildOtelLogRecord(
|
|
45
|
+
{
|
|
46
|
+
category: "agent-session",
|
|
47
|
+
payload: undefined,
|
|
48
|
+
raw: event.raw,
|
|
49
|
+
redaction: event.redaction,
|
|
50
|
+
annotations: event.annotations,
|
|
51
|
+
},
|
|
52
|
+
attributes,
|
|
53
|
+
inferSessionSeverity(event.raw),
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
export type AgentFamily =
|
|
2
|
+
| "pi"
|
|
3
|
+
| "codex"
|
|
4
|
+
| "claude-code"
|
|
5
|
+
| "antigravity"
|
|
6
|
+
| "gemini"
|
|
7
|
+
| "kimi"
|
|
8
|
+
| "openai"
|
|
9
|
+
| "anthropic"
|
|
10
|
+
| "amp"
|
|
11
|
+
| "forge"
|
|
12
|
+
| "unknown";
|
|
13
|
+
|
|
14
|
+
export type AgentCaptureMode =
|
|
15
|
+
| "sdk-events"
|
|
16
|
+
| "rpc-events"
|
|
17
|
+
| "cli-json-stream"
|
|
18
|
+
| "cli-json"
|
|
19
|
+
| "cli-text"
|
|
20
|
+
| "artifact-import";
|
|
21
|
+
|
|
22
|
+
export type TraceCompleteness = "full-observed" | "partial-observed" | "final-only" | "capture-failed";
|
|
23
|
+
|
|
24
|
+
export type CanonicalAgentTraceEventKind =
|
|
25
|
+
| "session.start"
|
|
26
|
+
| "session.end"
|
|
27
|
+
| "turn.start"
|
|
28
|
+
| "turn.end"
|
|
29
|
+
| "message.start"
|
|
30
|
+
| "message.update"
|
|
31
|
+
| "message.end"
|
|
32
|
+
| "assistant.text.delta"
|
|
33
|
+
| "assistant.thinking.delta"
|
|
34
|
+
| "assistant.message.final"
|
|
35
|
+
| "tool.execution.start"
|
|
36
|
+
| "tool.execution.update"
|
|
37
|
+
| "tool.execution.end"
|
|
38
|
+
| "tool.result"
|
|
39
|
+
| "retry.start"
|
|
40
|
+
| "retry.end"
|
|
41
|
+
| "compaction.start"
|
|
42
|
+
| "compaction.end"
|
|
43
|
+
| "stderr"
|
|
44
|
+
| "stdout"
|
|
45
|
+
| "usage"
|
|
46
|
+
| "capture.warning"
|
|
47
|
+
| "capture.error"
|
|
48
|
+
| "artifact.created";
|
|
49
|
+
|
|
50
|
+
export type CanonicalAgentTraceEventPhase = "agent" | "turn" | "message" | "tool" | "session" | "capture" | "artifact";
|
|
51
|
+
|
|
52
|
+
export type CanonicalAgentTraceEvent = {
|
|
53
|
+
traceVersion: "1";
|
|
54
|
+
runId: string;
|
|
55
|
+
workflowPath?: string;
|
|
56
|
+
workflowHash?: string;
|
|
57
|
+
nodeId: string;
|
|
58
|
+
iteration: number;
|
|
59
|
+
attempt: number;
|
|
60
|
+
timestampMs: number;
|
|
61
|
+
event: {
|
|
62
|
+
sequence: number;
|
|
63
|
+
kind: CanonicalAgentTraceEventKind;
|
|
64
|
+
phase: CanonicalAgentTraceEventPhase;
|
|
65
|
+
};
|
|
66
|
+
source: {
|
|
67
|
+
agentFamily: AgentFamily;
|
|
68
|
+
captureMode: AgentCaptureMode;
|
|
69
|
+
rawType?: string;
|
|
70
|
+
rawEventId?: string;
|
|
71
|
+
observed: boolean;
|
|
72
|
+
};
|
|
73
|
+
traceCompleteness: TraceCompleteness;
|
|
74
|
+
payload: Record<string, unknown> | null;
|
|
75
|
+
raw: unknown;
|
|
76
|
+
redaction: {
|
|
77
|
+
applied: boolean;
|
|
78
|
+
ruleIds: string[];
|
|
79
|
+
};
|
|
80
|
+
annotations: Record<string, string | number | boolean>;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export type AgentTraceSummary = {
|
|
84
|
+
traceVersion: "1";
|
|
85
|
+
runId: string;
|
|
86
|
+
workflowPath?: string;
|
|
87
|
+
workflowHash?: string;
|
|
88
|
+
nodeId: string;
|
|
89
|
+
iteration: number;
|
|
90
|
+
attempt: number;
|
|
91
|
+
traceStartedAtMs: number;
|
|
92
|
+
traceFinishedAtMs: number;
|
|
93
|
+
agentFamily: AgentFamily;
|
|
94
|
+
agentId?: string;
|
|
95
|
+
model?: string;
|
|
96
|
+
captureMode: AgentCaptureMode;
|
|
97
|
+
traceCompleteness: TraceCompleteness;
|
|
98
|
+
unsupportedEventKinds: CanonicalAgentTraceEventKind[];
|
|
99
|
+
missingExpectedEventKinds: CanonicalAgentTraceEventKind[];
|
|
100
|
+
rawArtifactRefs: string[];
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export type AgentSessionTranscriptEvent = {
|
|
104
|
+
transcriptVersion: "1";
|
|
105
|
+
runId: string;
|
|
106
|
+
workflowPath?: string;
|
|
107
|
+
workflowHash?: string;
|
|
108
|
+
nodeId: string;
|
|
109
|
+
iteration: number;
|
|
110
|
+
attempt: number;
|
|
111
|
+
timestampMs: number;
|
|
112
|
+
event: {
|
|
113
|
+
sequence: number;
|
|
114
|
+
rowType: string;
|
|
115
|
+
};
|
|
116
|
+
source: {
|
|
117
|
+
agentFamily: AgentFamily;
|
|
118
|
+
captureMode: AgentCaptureMode;
|
|
119
|
+
ingestSource: "live" | "artifact";
|
|
120
|
+
observedLive: boolean;
|
|
121
|
+
providerSessionId?: string;
|
|
122
|
+
providerThreadId?: string;
|
|
123
|
+
};
|
|
124
|
+
raw: unknown;
|
|
125
|
+
redaction: {
|
|
126
|
+
applied: boolean;
|
|
127
|
+
ruleIds: string[];
|
|
128
|
+
};
|
|
129
|
+
annotations: Record<string, string | number | boolean>;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export type AgentTraceCapabilityProfile = {
|
|
133
|
+
sessionMetadata: boolean;
|
|
134
|
+
assistantTextDeltas: boolean;
|
|
135
|
+
visibleThinkingDeltas: boolean;
|
|
136
|
+
finalAssistantMessage: boolean;
|
|
137
|
+
toolExecutionStart: boolean;
|
|
138
|
+
toolExecutionUpdate: boolean;
|
|
139
|
+
toolExecutionEnd: boolean;
|
|
140
|
+
retryEvents: boolean;
|
|
141
|
+
compactionEvents: boolean;
|
|
142
|
+
rawStderrDiagnostics: boolean;
|
|
143
|
+
persistedSessionArtifact: boolean;
|
|
144
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('./agentTrace.ts').AgentFamily} AgentFamily
|
|
3
|
+
* @typedef {import('./agentTrace.ts').AgentTraceCapabilityProfile} AgentTraceCapabilityProfile
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** @type {Record<AgentFamily, AgentTraceCapabilityProfile>} */
|
|
7
|
+
export const agentTraceCapabilities = {
|
|
8
|
+
pi: {
|
|
9
|
+
sessionMetadata: true,
|
|
10
|
+
assistantTextDeltas: true,
|
|
11
|
+
visibleThinkingDeltas: true,
|
|
12
|
+
finalAssistantMessage: true,
|
|
13
|
+
toolExecutionStart: true,
|
|
14
|
+
toolExecutionUpdate: true,
|
|
15
|
+
toolExecutionEnd: true,
|
|
16
|
+
retryEvents: true,
|
|
17
|
+
compactionEvents: true,
|
|
18
|
+
rawStderrDiagnostics: true,
|
|
19
|
+
persistedSessionArtifact: true,
|
|
20
|
+
},
|
|
21
|
+
codex: {
|
|
22
|
+
sessionMetadata: false,
|
|
23
|
+
assistantTextDeltas: false,
|
|
24
|
+
visibleThinkingDeltas: false,
|
|
25
|
+
finalAssistantMessage: true,
|
|
26
|
+
toolExecutionStart: false,
|
|
27
|
+
toolExecutionUpdate: false,
|
|
28
|
+
toolExecutionEnd: false,
|
|
29
|
+
retryEvents: false,
|
|
30
|
+
compactionEvents: false,
|
|
31
|
+
rawStderrDiagnostics: true,
|
|
32
|
+
persistedSessionArtifact: false,
|
|
33
|
+
},
|
|
34
|
+
"claude-code": {
|
|
35
|
+
sessionMetadata: false,
|
|
36
|
+
assistantTextDeltas: true,
|
|
37
|
+
visibleThinkingDeltas: false,
|
|
38
|
+
finalAssistantMessage: true,
|
|
39
|
+
toolExecutionStart: false,
|
|
40
|
+
toolExecutionUpdate: false,
|
|
41
|
+
toolExecutionEnd: false,
|
|
42
|
+
retryEvents: false,
|
|
43
|
+
compactionEvents: false,
|
|
44
|
+
rawStderrDiagnostics: true,
|
|
45
|
+
persistedSessionArtifact: false,
|
|
46
|
+
},
|
|
47
|
+
antigravity: {
|
|
48
|
+
sessionMetadata: false,
|
|
49
|
+
assistantTextDeltas: false,
|
|
50
|
+
visibleThinkingDeltas: false,
|
|
51
|
+
finalAssistantMessage: true,
|
|
52
|
+
toolExecutionStart: false,
|
|
53
|
+
toolExecutionUpdate: false,
|
|
54
|
+
toolExecutionEnd: false,
|
|
55
|
+
retryEvents: false,
|
|
56
|
+
compactionEvents: false,
|
|
57
|
+
rawStderrDiagnostics: true,
|
|
58
|
+
persistedSessionArtifact: false,
|
|
59
|
+
},
|
|
60
|
+
gemini: {
|
|
61
|
+
sessionMetadata: false,
|
|
62
|
+
assistantTextDeltas: false,
|
|
63
|
+
visibleThinkingDeltas: false,
|
|
64
|
+
finalAssistantMessage: true,
|
|
65
|
+
toolExecutionStart: false,
|
|
66
|
+
toolExecutionUpdate: false,
|
|
67
|
+
toolExecutionEnd: false,
|
|
68
|
+
retryEvents: false,
|
|
69
|
+
compactionEvents: false,
|
|
70
|
+
rawStderrDiagnostics: true,
|
|
71
|
+
persistedSessionArtifact: false,
|
|
72
|
+
},
|
|
73
|
+
kimi: {
|
|
74
|
+
sessionMetadata: false,
|
|
75
|
+
assistantTextDeltas: false,
|
|
76
|
+
visibleThinkingDeltas: false,
|
|
77
|
+
finalAssistantMessage: true,
|
|
78
|
+
toolExecutionStart: false,
|
|
79
|
+
toolExecutionUpdate: false,
|
|
80
|
+
toolExecutionEnd: false,
|
|
81
|
+
retryEvents: false,
|
|
82
|
+
compactionEvents: false,
|
|
83
|
+
rawStderrDiagnostics: true,
|
|
84
|
+
persistedSessionArtifact: false,
|
|
85
|
+
},
|
|
86
|
+
openai: {
|
|
87
|
+
sessionMetadata: false,
|
|
88
|
+
assistantTextDeltas: false,
|
|
89
|
+
visibleThinkingDeltas: false,
|
|
90
|
+
finalAssistantMessage: true,
|
|
91
|
+
toolExecutionStart: true,
|
|
92
|
+
toolExecutionUpdate: false,
|
|
93
|
+
toolExecutionEnd: true,
|
|
94
|
+
retryEvents: false,
|
|
95
|
+
compactionEvents: false,
|
|
96
|
+
rawStderrDiagnostics: false,
|
|
97
|
+
persistedSessionArtifact: false,
|
|
98
|
+
},
|
|
99
|
+
anthropic: {
|
|
100
|
+
sessionMetadata: false,
|
|
101
|
+
assistantTextDeltas: false,
|
|
102
|
+
visibleThinkingDeltas: false,
|
|
103
|
+
finalAssistantMessage: true,
|
|
104
|
+
toolExecutionStart: true,
|
|
105
|
+
toolExecutionUpdate: false,
|
|
106
|
+
toolExecutionEnd: true,
|
|
107
|
+
retryEvents: false,
|
|
108
|
+
compactionEvents: false,
|
|
109
|
+
rawStderrDiagnostics: false,
|
|
110
|
+
persistedSessionArtifact: false,
|
|
111
|
+
},
|
|
112
|
+
amp: {
|
|
113
|
+
sessionMetadata: false,
|
|
114
|
+
assistantTextDeltas: false,
|
|
115
|
+
visibleThinkingDeltas: false,
|
|
116
|
+
finalAssistantMessage: true,
|
|
117
|
+
toolExecutionStart: true,
|
|
118
|
+
toolExecutionUpdate: false,
|
|
119
|
+
toolExecutionEnd: true,
|
|
120
|
+
retryEvents: false,
|
|
121
|
+
compactionEvents: false,
|
|
122
|
+
rawStderrDiagnostics: true,
|
|
123
|
+
persistedSessionArtifact: false,
|
|
124
|
+
},
|
|
125
|
+
forge: {
|
|
126
|
+
sessionMetadata: false,
|
|
127
|
+
assistantTextDeltas: false,
|
|
128
|
+
visibleThinkingDeltas: false,
|
|
129
|
+
finalAssistantMessage: true,
|
|
130
|
+
toolExecutionStart: true,
|
|
131
|
+
toolExecutionUpdate: false,
|
|
132
|
+
toolExecutionEnd: true,
|
|
133
|
+
retryEvents: false,
|
|
134
|
+
compactionEvents: false,
|
|
135
|
+
rawStderrDiagnostics: true,
|
|
136
|
+
persistedSessionArtifact: false,
|
|
137
|
+
},
|
|
138
|
+
unknown: {
|
|
139
|
+
sessionMetadata: false,
|
|
140
|
+
assistantTextDeltas: false,
|
|
141
|
+
visibleThinkingDeltas: false,
|
|
142
|
+
finalAssistantMessage: true,
|
|
143
|
+
toolExecutionStart: true,
|
|
144
|
+
toolExecutionUpdate: false,
|
|
145
|
+
toolExecutionEnd: true,
|
|
146
|
+
retryEvents: false,
|
|
147
|
+
compactionEvents: false,
|
|
148
|
+
rawStderrDiagnostics: true,
|
|
149
|
+
persistedSessionArtifact: false,
|
|
150
|
+
},
|
|
151
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TracingService, annotateSmithersTrace as annotateCoreSmithersTrace } from "./_coreTracing.js";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
/**
|
|
4
|
+
* @param {Readonly<Record<string, unknown>>} [attributes]
|
|
5
|
+
* @returns {Effect.Effect<void>}
|
|
6
|
+
*/
|
|
7
|
+
export function annotateSmithersTrace(attributes = {}) {
|
|
8
|
+
return Effect.flatMap(Effect.serviceOption(TracingService), (service) =>
|
|
9
|
+
service._tag === "Some" ? service.value.annotate({ ...attributes }) : annotateCoreSmithersTrace(attributes),
|
|
10
|
+
);
|
|
11
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { buildOtelAttributes, buildOtelLogRecord, inferCanonicalSeverity } from "./_otelLogBuilders.js";
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {import('./agentTrace.ts').CanonicalAgentTraceEvent} CanonicalAgentTraceEvent
|
|
4
|
+
* @typedef {import('./_otelLogBuilders.js').OtelLogRecord} OtelLogRecord
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {CanonicalAgentTraceEvent} event
|
|
9
|
+
* @param {{ agentId?: string; model?: string }} [context]
|
|
10
|
+
* @returns {OtelLogRecord}
|
|
11
|
+
*/
|
|
12
|
+
export function canonicalTraceEventToOtelLogRecord(event, context) {
|
|
13
|
+
const attributes = buildOtelAttributes(
|
|
14
|
+
{
|
|
15
|
+
"smithers.event.category": "agent-trace",
|
|
16
|
+
"smithers.trace.version": event.traceVersion,
|
|
17
|
+
"smithers.transcript.version": undefined,
|
|
18
|
+
"run.id": event.runId,
|
|
19
|
+
"workflow.path": event.workflowPath,
|
|
20
|
+
"workflow.hash": event.workflowHash,
|
|
21
|
+
"node.id": event.nodeId,
|
|
22
|
+
"node.iteration": event.iteration,
|
|
23
|
+
"node.attempt": event.attempt,
|
|
24
|
+
"agent.family": event.source.agentFamily,
|
|
25
|
+
"agent.id": context?.agentId,
|
|
26
|
+
"agent.model": context?.model,
|
|
27
|
+
"agent.capture_mode": event.source.captureMode,
|
|
28
|
+
"trace.completeness": event.traceCompleteness,
|
|
29
|
+
"event.kind": event.event.kind,
|
|
30
|
+
"event.phase": event.event.phase,
|
|
31
|
+
"event.sequence": event.event.sequence,
|
|
32
|
+
"source.raw_type": event.source.rawType,
|
|
33
|
+
"source.raw_event_id": event.source.rawEventId,
|
|
34
|
+
"source.observed": event.source.observed,
|
|
35
|
+
"session.row_type": undefined,
|
|
36
|
+
"session.row_sequence": undefined,
|
|
37
|
+
"session.ingest_source": undefined,
|
|
38
|
+
"session.observed_live": undefined,
|
|
39
|
+
"provider.session_id": undefined,
|
|
40
|
+
"provider.thread_id": undefined,
|
|
41
|
+
},
|
|
42
|
+
event.annotations,
|
|
43
|
+
);
|
|
44
|
+
return buildOtelLogRecord(
|
|
45
|
+
{
|
|
46
|
+
category: "agent-trace",
|
|
47
|
+
payload: event.payload,
|
|
48
|
+
raw: event.raw,
|
|
49
|
+
redaction: event.redaction,
|
|
50
|
+
annotations: event.annotations,
|
|
51
|
+
},
|
|
52
|
+
attributes,
|
|
53
|
+
inferCanonicalSeverity(event),
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCurrentCorrelationContext as getCoreCurrentCorrelationContext,
|
|
3
|
+
mergeCorrelationContext as mergeCoreCorrelationContext,
|
|
4
|
+
} from "./_coreCorrelation/index.js";
|
|
5
|
+
/** @typedef {import("./_coreCorrelation/CorrelationContext.ts").CorrelationContext} CorrelationContext */
|
|
6
|
+
/** @typedef {import("./_coreCorrelation/CorrelationPatch.ts").CorrelationPatch} CorrelationPatch */
|
|
7
|
+
/** @typedef {CorrelationPatch} CorrelationContextPatch */
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
correlationContextFiberRef,
|
|
11
|
+
correlationContextToLogAnnotations,
|
|
12
|
+
CorrelationContextLive,
|
|
13
|
+
CorrelationContextService,
|
|
14
|
+
getCurrentCorrelationContext,
|
|
15
|
+
getCurrentCorrelationContextEffect,
|
|
16
|
+
mergeCorrelationContext,
|
|
17
|
+
runWithCorrelationContext,
|
|
18
|
+
withCorrelationContext,
|
|
19
|
+
withCurrentCorrelationContext,
|
|
20
|
+
} from "./_coreCorrelation/index.js";
|
|
21
|
+
/**
|
|
22
|
+
* Temporary compatibility shim for legacy, non-Effect callers.
|
|
23
|
+
*
|
|
24
|
+
* Unlike the FiberRef-based core implementation
|
|
25
|
+
* ({@link import("./_coreCorrelation/updateCurrentCorrelationContext.js").updateCurrentCorrelationContext}),
|
|
26
|
+
* which returns an Effect and sets a fresh merged context on the
|
|
27
|
+
* `correlationContextFiberRef`, this shim runs synchronously and applies the
|
|
28
|
+
* patch by **mutating the current context object in place** via
|
|
29
|
+
* `Object.assign(current, next)`. Any references already holding the current
|
|
30
|
+
* context object will observe the mutation. This in-place semantics is
|
|
31
|
+
* intentional and exists only to preserve behavior for callers that captured a
|
|
32
|
+
* context reference before the Effect-based API existed.
|
|
33
|
+
*
|
|
34
|
+
* If there is no current context, the patch is a no-op (nothing is created).
|
|
35
|
+
*
|
|
36
|
+
* @deprecated Prefer the Effect-returning
|
|
37
|
+
* `updateCurrentCorrelationContext` from
|
|
38
|
+
* `@smthrs/observability` (the `_coreCorrelation` version),
|
|
39
|
+
* which does not mutate shared state. This shim will be removed once legacy
|
|
40
|
+
* callers migrate.
|
|
41
|
+
*
|
|
42
|
+
* @param {CorrelationPatch} patch
|
|
43
|
+
* @returns {void}
|
|
44
|
+
*/
|
|
45
|
+
export function updateCurrentCorrelationContext(patch) {
|
|
46
|
+
const current = getCoreCurrentCorrelationContext();
|
|
47
|
+
if (!current) return;
|
|
48
|
+
// Compatibility shim: mutate the current context in place rather than
|
|
49
|
+
// setting a new FiberRef value. See the JSDoc above — this preserves
|
|
50
|
+
// behavior for legacy callers and is intentional, not a bug. Remove once
|
|
51
|
+
// those callers adopt the Effect-returning core
|
|
52
|
+
// updateCurrentCorrelationContext.
|
|
53
|
+
const next = mergeCoreCorrelationContext(current, patch);
|
|
54
|
+
if (!next) return;
|
|
55
|
+
Object.assign(current, next);
|
|
56
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as BunContext from "@effect/platform-bun/BunServices";
|
|
2
|
+
import { TracingServiceLive } from "./_coreTracing.js";
|
|
3
|
+
import { Effect, Layer, Logger, References } from "effect";
|
|
4
|
+
import { SmithersObservability } from "./SmithersObservability.js";
|
|
5
|
+
import { resolveSmithersObservabilityOptions } from "./resolveSmithersObservabilityOptions.js";
|
|
6
|
+
import { createSmithersOtelLayer } from "./createSmithersOtelLayer.js";
|
|
7
|
+
import { MetricsServiceLive } from "./MetricsServiceLive.js";
|
|
8
|
+
import { annotateSmithersTrace } from "./annotateSmithersTrace.js";
|
|
9
|
+
import { withSmithersSpan } from "./withSmithersSpan.js";
|
|
10
|
+
/** @typedef {import("./ResolvedSmithersObservabilityOptions.ts").ResolvedSmithersObservabilityOptions} ResolvedSmithersObservabilityOptions */
|
|
11
|
+
/** @typedef {import("./SmithersLogFormat.ts").SmithersLogFormat} SmithersLogFormat */
|
|
12
|
+
/** @typedef {import("./SmithersObservabilityService.ts").SmithersObservabilityService} SmithersObservabilityService */
|
|
13
|
+
|
|
14
|
+
/** @typedef {import("./SmithersObservabilityOptions.ts").SmithersObservabilityOptions} SmithersObservabilityOptions */
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {SmithersLogFormat} format
|
|
18
|
+
*/
|
|
19
|
+
function resolveLogger(format) {
|
|
20
|
+
switch (format) {
|
|
21
|
+
case "json":
|
|
22
|
+
return Logger.consoleJson;
|
|
23
|
+
case "pretty":
|
|
24
|
+
return Logger.consolePretty();
|
|
25
|
+
case "string":
|
|
26
|
+
return Logger.consolePretty({ colors: false });
|
|
27
|
+
case "logfmt":
|
|
28
|
+
default:
|
|
29
|
+
return Logger.consoleLogFmt;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @param {ResolvedSmithersObservabilityOptions} options
|
|
34
|
+
* @returns {SmithersObservabilityService}
|
|
35
|
+
*/
|
|
36
|
+
function makeService(options) {
|
|
37
|
+
return {
|
|
38
|
+
options,
|
|
39
|
+
annotate: (attributes) => annotateSmithersTrace(attributes),
|
|
40
|
+
withSpan: (name, effect, attributes) => withSmithersSpan(name, effect, attributes),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @param {SmithersObservabilityOptions} [options]
|
|
45
|
+
*/
|
|
46
|
+
export function createSmithersObservabilityLayer(options = {}) {
|
|
47
|
+
const resolved = resolveSmithersObservabilityOptions(options);
|
|
48
|
+
const loggerLayers = resolved.installLogger
|
|
49
|
+
? [Logger.layer([resolveLogger(resolved.logFormat)]), Layer.succeed(References.MinimumLogLevel, resolved.logLevel)]
|
|
50
|
+
: [];
|
|
51
|
+
return Layer.mergeAll(
|
|
52
|
+
BunContext.layer,
|
|
53
|
+
...loggerLayers,
|
|
54
|
+
createSmithersOtelLayer(resolved),
|
|
55
|
+
MetricsServiceLive,
|
|
56
|
+
TracingServiceLive,
|
|
57
|
+
Layer.succeed(SmithersObservability, makeService(resolved)),
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient";
|
|
2
|
+
import * as Otlp from "effect/unstable/observability/Otlp";
|
|
3
|
+
import { Fiber, Layer } from "effect";
|
|
4
|
+
import { smithersTraceSpanStorage } from "./_smithersTraceSpanStorage.js";
|
|
5
|
+
import { resolveSmithersObservabilityOptions } from "./resolveSmithersObservabilityOptions.js";
|
|
6
|
+
/** @typedef {import("./SmithersObservabilityOptions.ts").SmithersObservabilityOptions} SmithersObservabilityOptions */
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {SmithersObservabilityOptions} [options]
|
|
10
|
+
*/
|
|
11
|
+
export function createSmithersOtelLayer(options = {}) {
|
|
12
|
+
const resolved = resolveSmithersObservabilityOptions(options);
|
|
13
|
+
if (!resolved.enabled) {
|
|
14
|
+
return Layer.empty;
|
|
15
|
+
}
|
|
16
|
+
return Otlp.layerJson({
|
|
17
|
+
baseUrl: resolved.endpoint,
|
|
18
|
+
...(resolved.headers && Object.keys(resolved.headers).length > 0 ? { headers: resolved.headers } : {}),
|
|
19
|
+
resource: { serviceName: resolved.serviceName },
|
|
20
|
+
tracerContext: (primitive, span) =>
|
|
21
|
+
smithersTraceSpanStorage.run(span, () => primitive["~effect/Effect/evaluate"](Fiber.getCurrent())),
|
|
22
|
+
}).pipe(Layer.provide(FetchHttpClient.layer));
|
|
23
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('./agentTrace.ts').AgentFamily} AgentFamily
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {any} agent
|
|
7
|
+
* @returns {AgentFamily}
|
|
8
|
+
*/
|
|
9
|
+
export function detectAgentFamily(agent) {
|
|
10
|
+
const constructorName = String(agent?.constructor?.name ?? "").toLowerCase();
|
|
11
|
+
const idName = String(agent?.id ?? "").toLowerCase();
|
|
12
|
+
const name = constructorName && constructorName !== "object" ? `${constructorName} ${idName}` : idName;
|
|
13
|
+
if (name.includes("antigravity") || name.includes("agy")) return "antigravity";
|
|
14
|
+
if (name.includes("codex")) return "codex";
|
|
15
|
+
if (name.includes("claude")) return "claude-code";
|
|
16
|
+
if (name.includes("gemini")) return "gemini";
|
|
17
|
+
if (name.includes("kimi")) return "kimi";
|
|
18
|
+
if (name.includes("openai")) return "openai";
|
|
19
|
+
if (name.includes("anthropic")) return "anthropic";
|
|
20
|
+
if (name.includes("amp")) return "amp";
|
|
21
|
+
if (name.includes("forge")) return "forge";
|
|
22
|
+
if (constructorName.includes("piagent") || /(?:^|[-_\s])pi(?:$|[-_\s])/.test(idName)) {
|
|
23
|
+
return "pi";
|
|
24
|
+
}
|
|
25
|
+
return "unknown";
|
|
26
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { detectAgentFamily } from "./detectAgentFamily.js";
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {import('./agentTrace.ts').AgentCaptureMode} AgentCaptureMode
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {any} agent
|
|
8
|
+
* @returns {AgentCaptureMode}
|
|
9
|
+
*/
|
|
10
|
+
export function detectCaptureMode(agent) {
|
|
11
|
+
const family = detectAgentFamily(agent);
|
|
12
|
+
const mode = agent?.opts?.mode ?? agent?.mode;
|
|
13
|
+
if (family === "pi") {
|
|
14
|
+
if (mode === "rpc") return "rpc-events";
|
|
15
|
+
if (mode === "json") return "cli-json-stream";
|
|
16
|
+
return "cli-text";
|
|
17
|
+
}
|
|
18
|
+
if (family === "codex") return "cli-json-stream";
|
|
19
|
+
const outputFormat = agent?.opts?.outputFormat ?? agent?.outputFormat;
|
|
20
|
+
if (family === "openai" || family === "anthropic") return "sdk-events";
|
|
21
|
+
if (outputFormat === "stream-json") return "cli-json-stream";
|
|
22
|
+
if (outputFormat === "json" || agent?.opts?.json) return "cli-json";
|
|
23
|
+
return "cli-text";
|
|
24
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { logErrorAwait, logInfoAwait, logWarningAwait } from "./logging.js";
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {import('./_otelLogBuilders.js').OtelLogRecord} OtelLogRecord
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {"agent-trace" | "agent-session"} category
|
|
8
|
+
* @param {OtelLogRecord} record
|
|
9
|
+
* @returns {Promise<void>}
|
|
10
|
+
*/
|
|
11
|
+
export async function emitOtelLogRecord(category, record) {
|
|
12
|
+
if (record.severity === "ERROR") {
|
|
13
|
+
await logErrorAwait(record.body, record.attributes, category);
|
|
14
|
+
} else if (record.severity === "WARN") {
|
|
15
|
+
await logWarningAwait(record.body, record.attributes, category);
|
|
16
|
+
} else {
|
|
17
|
+
await logInfoAwait(record.body, record.attributes, category);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { getCurrentSmithersTraceSpan } from "./getCurrentSmithersTraceSpan.js";
|
|
2
|
+
/**
|
|
3
|
+
* @returns {| Readonly<Record<string, string>> | undefined}
|
|
4
|
+
*/
|
|
5
|
+
export function getCurrentSmithersTraceAnnotations() {
|
|
6
|
+
const span = getCurrentSmithersTraceSpan();
|
|
7
|
+
if (!span) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
traceId: span.traceId,
|
|
12
|
+
spanId: span.spanId,
|
|
13
|
+
};
|
|
14
|
+
}
|