opencode-otel-plugin 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.
- package/README.md +208 -0
- package/dist/hooks/chat-params.d.ts +21 -0
- package/dist/hooks/event.d.ts +14 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/message-handler.d.ts +14 -0
- package/dist/hooks/tool-execute.d.ts +27 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +12123 -0
- package/dist/signals/index.d.ts +3 -0
- package/dist/signals/metrics.d.ts +10 -0
- package/dist/signals/spans.d.ts +26 -0
- package/dist/telemetry/index.d.ts +5 -0
- package/dist/telemetry/provider.d.ts +8 -0
- package/dist/telemetry/resources.d.ts +12 -0
- package/dist/telemetry/shutdown.d.ts +3 -0
- package/dist/types.d.ts +31 -0
- package/dist/utils/diff.d.ts +8 -0
- package/dist/utils/git.d.ts +7 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/language.d.ts +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Counter, Histogram, Meter } from "@opentelemetry/api";
|
|
2
|
+
export interface MetricInstruments {
|
|
3
|
+
tokenUsage: Histogram;
|
|
4
|
+
operationDuration: Histogram;
|
|
5
|
+
requestCount: Counter;
|
|
6
|
+
compactionCount: Counter;
|
|
7
|
+
fileChanges: Counter;
|
|
8
|
+
toolInvocations: Counter;
|
|
9
|
+
}
|
|
10
|
+
export declare function createMetricInstruments(meter: Meter): MetricInstruments;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Context, type Span, type Tracer } from "@opentelemetry/api";
|
|
2
|
+
export declare function startSessionSpan(tracer: Tracer, sessionID: string): {
|
|
3
|
+
span: Span;
|
|
4
|
+
context: Context;
|
|
5
|
+
};
|
|
6
|
+
export declare function startChatSpan(tracer: Tracer, opts: {
|
|
7
|
+
model: string;
|
|
8
|
+
provider: string;
|
|
9
|
+
sessionID: string;
|
|
10
|
+
branch?: string;
|
|
11
|
+
}, parentContext?: Context): Span;
|
|
12
|
+
export declare function startToolSpan(tracer: Tracer, opts: {
|
|
13
|
+
toolName: string;
|
|
14
|
+
callID: string;
|
|
15
|
+
sessionID: string;
|
|
16
|
+
branch?: string;
|
|
17
|
+
}, parentContext?: Context): Span;
|
|
18
|
+
export declare function startFileEditSpan(tracer: Tracer, opts: {
|
|
19
|
+
filepath: string;
|
|
20
|
+
language: string;
|
|
21
|
+
linesAdded: number;
|
|
22
|
+
linesRemoved: number;
|
|
23
|
+
sessionID: string;
|
|
24
|
+
branch?: string;
|
|
25
|
+
}, parentContext?: Context): Span;
|
|
26
|
+
export declare function startCompactionSpan(tracer: Tracer, sessionID: string, parentContext?: Context, branch?: string): Span;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { buildResourceAttributes, createResource } from "./resources";
|
|
2
|
+
export type { ResourceInput } from "./resources";
|
|
3
|
+
export { initProviders } from "./provider";
|
|
4
|
+
export type { Providers } from "./provider";
|
|
5
|
+
export { shutdownProviders, flushProviders } from "./shutdown";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BasicTracerProvider } from "@opentelemetry/sdk-trace-base";
|
|
2
|
+
import { MeterProvider } from "@opentelemetry/sdk-metrics";
|
|
3
|
+
import type { Resource } from "@opentelemetry/resources";
|
|
4
|
+
export interface Providers {
|
|
5
|
+
tracerProvider: BasicTracerProvider;
|
|
6
|
+
meterProvider: MeterProvider;
|
|
7
|
+
}
|
|
8
|
+
export declare function initProviders(resource: Resource): Providers;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Resource } from "@opentelemetry/resources";
|
|
2
|
+
export interface ResourceInput {
|
|
3
|
+
author: string;
|
|
4
|
+
hostname: string;
|
|
5
|
+
projectName: string;
|
|
6
|
+
repoUrl: string;
|
|
7
|
+
branch: string;
|
|
8
|
+
worktree: string;
|
|
9
|
+
directory: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function buildResourceAttributes(input: ResourceInput): Record<string, string>;
|
|
12
|
+
export declare function createResource(input: ResourceInput): Resource;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Context, Span } from "@opentelemetry/api";
|
|
2
|
+
/** Tracks the active OTel span for a session root. */
|
|
3
|
+
export interface SessionSpanState {
|
|
4
|
+
span: Span;
|
|
5
|
+
context: Context;
|
|
6
|
+
sessionID: string;
|
|
7
|
+
requestCount: number;
|
|
8
|
+
}
|
|
9
|
+
/** Model/provider info captured in chat.params, used when ending chat spans. */
|
|
10
|
+
export interface ChatRequestInfo {
|
|
11
|
+
model: string;
|
|
12
|
+
provider: string;
|
|
13
|
+
startTime: number;
|
|
14
|
+
}
|
|
15
|
+
/** Accumulated file change stats from session.diff events. */
|
|
16
|
+
export interface FileChangeStats {
|
|
17
|
+
linesAdded: number;
|
|
18
|
+
linesRemoved: number;
|
|
19
|
+
filepath: string;
|
|
20
|
+
language: string;
|
|
21
|
+
}
|
|
22
|
+
/** In-flight tool span keyed by callID. */
|
|
23
|
+
export type ToolSpanMap = Map<string, Span>;
|
|
24
|
+
/** Plugin-wide mutable state shared across hooks. */
|
|
25
|
+
export interface PluginState {
|
|
26
|
+
sessionSpans: Map<string, SessionSpanState>;
|
|
27
|
+
toolSpans: ToolSpanMap;
|
|
28
|
+
pendingChatRequests: Map<string, ChatRequestInfo>;
|
|
29
|
+
currentBranch: string | undefined;
|
|
30
|
+
opencodeVersion: string | undefined;
|
|
31
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PluginInput } from "@opencode-ai/plugin";
|
|
2
|
+
type Shell = PluginInput["$"];
|
|
3
|
+
export declare function getGitAuthor($: Shell): Promise<string>;
|
|
4
|
+
export declare function getRepoUrl($: Shell): Promise<string>;
|
|
5
|
+
export declare function getCurrentBranch($: Shell): Promise<string>;
|
|
6
|
+
export declare function getHostname(): string;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function detectLanguage(filepath: string): string;
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "opencode-otel-plugin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "OpenTelemetry instrumentation plugin for OpenCode — traces and metrics for AI coding sessions via OTLP/HTTP",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "bun build ./src/index.ts --outdir dist --target bun && tsc --emitDeclarationOnly --outDir dist",
|
|
13
|
+
"prepublishOnly": "bun run build",
|
|
14
|
+
"test": "bun test",
|
|
15
|
+
"typecheck": "tsc --noEmit"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"opencode",
|
|
19
|
+
"opentelemetry",
|
|
20
|
+
"otel",
|
|
21
|
+
"tracing",
|
|
22
|
+
"metrics",
|
|
23
|
+
"observability",
|
|
24
|
+
"ai",
|
|
25
|
+
"llm",
|
|
26
|
+
"plugin"
|
|
27
|
+
],
|
|
28
|
+
"author": "felixti",
|
|
29
|
+
"homepage": "https://github.com/felixti/opencode-otel-plugin#readme",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/felixti/opencode-otel-plugin.git"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/felixti/opencode-otel-plugin/issues"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@opencode-ai/plugin": ">=0.1.0"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@opentelemetry/api": "1.9.0",
|
|
42
|
+
"@opentelemetry/sdk-trace-base": "2.6.0",
|
|
43
|
+
"@opentelemetry/sdk-metrics": "2.6.0",
|
|
44
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.213.0",
|
|
45
|
+
"@opentelemetry/exporter-metrics-otlp-http": "0.213.0",
|
|
46
|
+
"@opentelemetry/resources": "2.6.0",
|
|
47
|
+
"@opentelemetry/semantic-conventions": "1.40.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@opencode-ai/plugin": "latest",
|
|
51
|
+
"@types/bun": "latest",
|
|
52
|
+
"typescript": "latest"
|
|
53
|
+
},
|
|
54
|
+
"license": "MIT"
|
|
55
|
+
}
|