-
Notifications
You must be signed in to change notification settings - Fork 117
feat: core telemetry functionality #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 47 commits
9cf0447
1b8ea02
af714b4
40aaef0
8adc20d
cff01e0
5336e4a
76e2a6f
1850676
3a5d4c1
23fff05
754ce8d
8301e43
994b698
3bfc9f2
6d92021
7997c54
f18b916
a9cd835
6813518
65fad1d
7e98c33
5209073
2e33584
d92adf1
8ec7d9c
6ad2a19
807109d
f9a46f9
599201d
7a889b4
eb360e2
710b131
a15eeb6
90caa25
89113a5
143f898
f751a30
0927d28
fb0b8af
9e625aa
a61d9b4
2bd00cf
3636fde
0df870c
4b7563d
6dd1f79
807b2ca
139c3ee
3a05d31
8505d91
024a3d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,16 @@ import argv from "yargs-parser"; | |
import packageJson from "../package.json" with { type: "json" }; | ||
import { ReadConcernLevel, ReadPreferenceMode, W } from "mongodb"; | ||
|
||
export const SERVER_NAME = "MdbMcpServer"; | ||
export const SERVER_VERSION = packageJson.version; | ||
|
||
// If we decide to support non-string config options, we'll need to extend the mechanism for parsing | ||
// env variables. | ||
interface UserConfig { | ||
apiBaseUrl?: string; | ||
apiClientId?: string; | ||
apiClientSecret?: string; | ||
telemetry?: "enabled" | "disabled"; | ||
blva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
logPath: string; | ||
connectionString?: string; | ||
connectOptions: { | ||
|
@@ -41,7 +45,8 @@ const mergedUserConfig = { | |
|
||
const config = { | ||
...mergedUserConfig, | ||
version: packageJson.version, | ||
version: SERVER_VERSION, | ||
mcpServerName: SERVER_NAME, | ||
|
||
}; | ||
|
||
export default config; | ||
gagik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import pkg from "../../package.json" with { type: "json" }; | ||
import config from "../config.js"; | ||
import { getMachineIdSync } from "native-machine-id"; | ||
|
||
/** | ||
* Machine-specific metadata formatted for telemetry | ||
*/ | ||
export const MACHINE_METADATA = { | ||
device_id: getMachineIdSync(), | ||
mcp_server_version: pkg.version, | ||
mcp_server_name: config.mcpServerName, | ||
|
||
platform: process.platform, | ||
arch: process.arch, | ||
os_type: process.platform, | ||
os_version: process.version, | ||
} as const; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { BaseEvent } from "./types.js"; | ||
import { LRUCache } from "lru-cache"; | ||
|
||
/** | ||
* Singleton class for in-memory telemetry event caching | ||
* Provides a central storage for telemetry events that couldn't be sent | ||
* Uses LRU cache to automatically drop oldest events when limit is exceeded | ||
*/ | ||
export class EventCache { | ||
private static instance: EventCache; | ||
private static readonly MAX_EVENTS = 1000; | ||
|
||
private cache: LRUCache<number, BaseEvent>; | ||
private nextId = 0; | ||
|
||
private constructor() { | ||
this.cache = new LRUCache({ | ||
max: EventCache.MAX_EVENTS, | ||
// Using FIFO eviction strategy for events | ||
allowStale: false, | ||
updateAgeOnGet: false, | ||
}); | ||
} | ||
|
||
/** | ||
* Gets the singleton instance of EventCache | ||
* @returns The EventCache instance | ||
*/ | ||
public static getInstance(): EventCache { | ||
blva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!EventCache.instance) { | ||
EventCache.instance = new EventCache(); | ||
} | ||
return EventCache.instance; | ||
} | ||
|
||
/** | ||
* Gets a copy of the currently cached events | ||
* @returns Array of cached BaseEvent objects | ||
*/ | ||
public getEvents(): BaseEvent[] { | ||
return Array.from(this.cache.values()); | ||
} | ||
|
||
/** | ||
* Appends new events to the cached events | ||
* LRU cache automatically handles dropping oldest events when limit is exceeded | ||
* @param events - The events to append | ||
*/ | ||
public appendEvents(events: BaseEvent[]): void { | ||
for (const event of events) { | ||
this.cache.set(this.nextId++, event); | ||
} | ||
} | ||
|
||
/** | ||
* Clears all cached events | ||
*/ | ||
public clearEvents(): void { | ||
this.cache.clear(); | ||
this.nextId = 0; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.