Skip to content

Commit 30899e6

Browse files
author
vishal veerareddy
committed
Added telemetry
1 parent 337447c commit 30899e6

4 files changed

Lines changed: 36 additions & 10 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lynkr",
3-
"version": "9.7.2",
3+
"version": "9.7.3",
44
"description": "Self-hosted LLM gateway and tier-routing proxy for Claude Code, Cursor, and Codex. Routes across Ollama, AWS Bedrock, OpenRouter, Databricks, Azure OpenAI, llama.cpp, and LM Studio with prompt caching, MCP tools, and 60-80% cost savings.",
55
"main": "index.js",
66
"bin": {

src/clients/databricks.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,7 +2708,7 @@ async function invokeModel(body, options = {}) {
27082708
message_count: Array.isArray(body?.messages) ? body.messages.length : 0,
27092709
request_type: routingResult.analysis?.requestType || null,
27102710
provider: initialProvider,
2711-
model: routingDecision.model,
2711+
model: routingDecision.model ?? body._tierModel ?? null,
27122712
routing_method: routingDecision.method,
27132713
was_fallback: false,
27142714
output_tokens: outputTokens || null,
@@ -2826,7 +2826,7 @@ async function invokeModel(body, options = {}) {
28262826
message_count: Array.isArray(body?.messages) ? body.messages.length : 0,
28272827
request_type: routingResult.analysis?.requestType || null,
28282828
provider: initialProvider,
2829-
model: routingDecision.model,
2829+
model: routingDecision.model ?? body._tierModel ?? null,
28302830
routing_method: routingDecision.method,
28312831
was_fallback: false,
28322832
latency_ms: failLatency,
@@ -2934,7 +2934,7 @@ async function invokeModel(body, options = {}) {
29342934
message_count: Array.isArray(body?.messages) ? body.messages.length : 0,
29352935
request_type: routingResult.analysis?.requestType || null,
29362936
provider: fallbackProvider,
2937-
model: routingDecision.model,
2937+
model: routingDecision.model ?? body._tierModel ?? null,
29382938
routing_method: "fallback",
29392939
was_fallback: true,
29402940
output_tokens: fbOutputTokens || null,
@@ -2980,7 +2980,7 @@ async function invokeModel(body, options = {}) {
29802980
complexity_score: routingResult.score ?? null,
29812981
tier: routingDecision.tier,
29822982
provider: fallbackProvider,
2983-
model: routingDecision.model,
2983+
model: routingDecision.model ?? body._tierModel ?? null,
29842984
routing_method: "fallback",
29852985
was_fallback: true,
29862986
latency_ms: Date.now() - startTime,

src/routing/telemetry.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,27 @@ function init() {
4949
}
5050

5151
try {
52-
const dbDir = path.resolve(process.cwd(), ".lynkr");
53-
if (!fs.existsSync(dbDir)) {
54-
fs.mkdirSync(dbDir, { recursive: true });
52+
// Allow tests to redirect telemetry to an isolated DB so unit/integration
53+
// runs never pollute the production .lynkr/telemetry.db that build-knn-index.js
54+
// reads from. Empty string disables telemetry entirely.
55+
const override = process.env.LYNKR_TELEMETRY_DB_PATH;
56+
let dbPath;
57+
if (override === "") {
58+
logger.debug("Telemetry: LYNKR_TELEMETRY_DB_PATH is empty, telemetry disabled");
59+
return false;
60+
} else if (override) {
61+
dbPath = path.resolve(override);
62+
const overrideDir = path.dirname(dbPath);
63+
if (!fs.existsSync(overrideDir)) {
64+
fs.mkdirSync(overrideDir, { recursive: true });
65+
}
66+
} else {
67+
const dbDir = path.resolve(process.cwd(), ".lynkr");
68+
if (!fs.existsSync(dbDir)) {
69+
fs.mkdirSync(dbDir, { recursive: true });
70+
}
71+
dbPath = path.join(dbDir, "telemetry.db");
5572
}
56-
57-
const dbPath = path.join(dbDir, "telemetry.db");
5873
db = new Database(dbPath, {
5974
verbose: process.env.DEBUG_SQL ? console.log : null,
6075
fileMustExist: false,

test/telemetry-routing.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
const assert = require("assert");
2+
const os = require("os");
3+
const path = require("path");
24
const { describe, it, beforeEach, afterEach, mock } = require("node:test");
35

6+
// Redirect telemetry writes to an isolated temp DB before requiring the
7+
// telemetry module. Otherwise this suite pollutes .lynkr/telemetry.db with
8+
// fixtures like "stats-provider-...", which then end up in build-knn-index.js
9+
// output and the kNN index.
10+
process.env.LYNKR_TELEMETRY_DB_PATH = path.join(
11+
os.tmpdir(),
12+
`lynkr-telemetry-test-${process.pid}.db`
13+
);
14+
415
// ============================================================================
516
// Module imports
617
// ============================================================================

0 commit comments

Comments
 (0)