@pepys/source-telemetry 0.0.0-stage → 0.0.1
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 +33 -2
- package/package.json +30 -4
- package/src/consumers/products/find-claude-code-model-request.ts +41 -0
- package/src/consumers/products/find-codex-model-request.ts +34 -0
- package/src/consumers/products/find-codex-turn-cost.ts +21 -0
- package/src/consumers/products/find-record-number.ts +101 -0
- package/src/consumers/products/parse-fact-type.ts +21 -0
- package/src/consumers/products/types.ts +34 -0
- package/src/consumers/telemetry-model-request.ts +91 -0
- package/src/consumers/telemetry-turn-cost.ts +85 -0
- package/src/generated/telemetry-model-request-boundary.ts +368 -0
- package/src/generated/telemetry-model-request.sql +35 -0
- package/src/generated/telemetry-turn-cost-boundary.ts +361 -0
- package/src/generated/telemetry-turn-cost.sql +26 -0
- package/src/index.ts +25 -0
- package/src/log-record-family.ts +41 -0
- package/src/otlp/format-canonical-json.ts +24 -0
- package/src/otlp/parse-logs-export.ts +71 -0
- package/src/otlp/read-otlp-facts.ts +226 -0
- package/src/otlp/receive-otlp-logs.ts +130 -0
- package/src/otlp/to-attribute-map.ts +63 -0
- package/src/otlp/types.ts +36 -0
- package/src/products/claude-code/claude-code-product.ts +45 -0
- package/src/products/codex/codex-product.ts +37 -0
- package/src/products/define-telemetry-product.ts +7 -0
- package/src/products/find-attribute-text.ts +12 -0
- package/src/products/products.ts +8 -0
- package/src/products/types.ts +21 -0
- package/src/telemetry-model-request-consumer.ts +59 -0
- package/src/telemetry-plugin.ts +42 -0
- package/src/telemetry-turn-cost-consumer.ts +42 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { definePlugin, defineSource } from '@pepys/kit';
|
|
2
|
+
import { logRecordFamily } from './log-record-family.ts';
|
|
3
|
+
import { receiveOtlpLogs } from './otlp/receive-otlp-logs.ts';
|
|
4
|
+
import { products } from './products/products.ts';
|
|
5
|
+
import { telemetryModelRequestConsumer } from './telemetry-model-request-consumer.ts';
|
|
6
|
+
import { telemetryTurnCostConsumer } from './telemetry-turn-cost-consumer.ts';
|
|
7
|
+
|
|
8
|
+
export const telemetrySource = defineSource({
|
|
9
|
+
name: 'telemetry',
|
|
10
|
+
families: [logRecordFamily],
|
|
11
|
+
|
|
12
|
+
// Push only. An OTLP exporter cannot sign a body, so the check is a token, and the route needs a
|
|
13
|
+
// proven sender, whom each fact then holds as its `origin`.
|
|
14
|
+
live: receiveOtlpLogs({
|
|
15
|
+
route: '/v1/logs',
|
|
16
|
+
|
|
17
|
+
// An exporter that gets a bare origin adds these paths itself, and retries a refusal for ever.
|
|
18
|
+
ignoredRoutes: ['/v1/metrics', '/v1/traces'],
|
|
19
|
+
check: { kind: 'token', header: 'authorization', secretEnv: 'PEPYS_TELEMETRY_TOKEN' },
|
|
20
|
+
sender: {
|
|
21
|
+
kind: 'imp-identity',
|
|
22
|
+
audienceEnv: 'PEPYS_IMP_IDENTITY_AUDIENCE',
|
|
23
|
+
issuersEnv: 'PEPYS_IMP_IDENTITY_ISSUERS',
|
|
24
|
+
},
|
|
25
|
+
products,
|
|
26
|
+
|
|
27
|
+
// atc stamps it on every record of a session it runs
|
|
28
|
+
sessionAttribute: 'atc.session.id',
|
|
29
|
+
factLimit: 1000,
|
|
30
|
+
bodyByteLimit: 4_194_304,
|
|
31
|
+
encodings: ['gzip'],
|
|
32
|
+
answer: 'empty',
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// `telemetry:session` is a kind of this plug-in, from the family, with no table: a link may point
|
|
37
|
+
// at a session, and no entity view finds one.
|
|
38
|
+
export const telemetryPlugin = definePlugin({
|
|
39
|
+
name: 'telemetry',
|
|
40
|
+
sources: [telemetrySource],
|
|
41
|
+
consumers: [telemetryModelRequestConsumer, telemetryTurnCostConsumer],
|
|
42
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { defineConsumer, defineTable } from '@pepys/kit';
|
|
2
|
+
import { logRecordFamily } from './log-record-family.ts';
|
|
3
|
+
|
|
4
|
+
// The cost a product reports per turn: a second consumer on the same stream.
|
|
5
|
+
export const telemetryTurnCostConsumer = defineConsumer({
|
|
6
|
+
name: 'telemetry_turn_cost',
|
|
7
|
+
entry: new URL('consumers/telemetry-turn-cost.ts', import.meta.url),
|
|
8
|
+
input: { mode: 'fact', streams: [logRecordFamily.stream] },
|
|
9
|
+
tables: {
|
|
10
|
+
telemetry_turn_cost: defineTable({
|
|
11
|
+
columns: {
|
|
12
|
+
// `telemetry:turn_cost:<product>.<event>:<key>`
|
|
13
|
+
id: { kind: 'entityID' },
|
|
14
|
+
session_id: { kind: 'entityID' },
|
|
15
|
+
agent_session: { kind: 'text', nullable: true },
|
|
16
|
+
product: { kind: 'text' },
|
|
17
|
+
|
|
18
|
+
// the model the record names, so a report can group turn costs by model; null when absent
|
|
19
|
+
model: { kind: 'text', nullable: true },
|
|
20
|
+
cost_usd: { kind: 'real' },
|
|
21
|
+
origin_issuer: { kind: 'text' },
|
|
22
|
+
origin_subject: { kind: 'text' },
|
|
23
|
+
at: { kind: 'timestamp' },
|
|
24
|
+
},
|
|
25
|
+
primaryKey: ['id'],
|
|
26
|
+
indexes: [{ columns: ['session_id'] }],
|
|
27
|
+
}),
|
|
28
|
+
},
|
|
29
|
+
entityViews: [
|
|
30
|
+
{
|
|
31
|
+
table: 'telemetry_turn_cost',
|
|
32
|
+
kind: 'telemetry:turn_cost',
|
|
33
|
+
id: 'id',
|
|
34
|
+
title: 'product',
|
|
35
|
+
url: null,
|
|
36
|
+
actor: null,
|
|
37
|
+
updatedAt: 'at',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
reads: [],
|
|
41
|
+
links: [],
|
|
42
|
+
});
|