MCPcopy
hub / github.com/colbymchenry/codegraph / send

Method send

src/telemetry/index.ts:468–515  ·  view source on GitHub ↗

Returns the lines that did NOT make it out (to be re-queued).

(lines: BufferLine[], timeoutMs: number)

Source from the content-addressed store, hash-verified

466
467 /** Returns the lines that did NOT make it out (to be re-queued). */
468 private async send(lines: BufferLine[], timeoutMs: number): Promise<BufferLine[]> {
469 const config = this.readConfig();
470 if (!config) return [];
471 const events = lines.map((line) =>
472 'ev' in line
473 ? { event: line.ev, ts: line.ts, props: line.props }
474 : {
475 event: 'usage_rollup',
476 ts: `${line.d}T12:00:00.000Z`,
477 props: {
478 kind: line.k,
479 name: line.n,
480 count: line.c,
481 error_count: line.e,
482 ...(line.cn ? { client_name: line.cn } : {}),
483 ...(line.cv ? { client_version: line.cv } : {}),
484 },
485 },
486 );
487 const envelope = {
488 machine_id: config.machine_id,
489 codegraph_version: this.packageVersion(),
490 os: process.platform,
491 arch: process.arch,
492 node_major: parseInt(process.versions.node.split('.')[0] ?? '0', 10),
493 ci: this.env.CI !== undefined && this.env.CI !== '' && this.env.CI !== '0' && this.env.CI !== 'false',
494 schema_version: SCHEMA_VERSION,
495 };
496 const endpoint = this.env.CODEGRAPH_TELEMETRY_ENDPOINT || TELEMETRY_ENDPOINT;
497 for (let i = 0; i < events.length; i += MAX_EVENTS_PER_REQUEST) {
498 const chunk = events.slice(i, i + MAX_EVENTS_PER_REQUEST);
499 const body = JSON.stringify({ ...envelope, events: chunk });
500 this.debug(`POST ${endpoint} (${chunk.length} events)`);
501 try {
502 // Any response — 204, 4xx, anything — is final. No retries.
503 await this.fetchImpl(endpoint, {
504 method: 'POST',
505 headers: { 'content-type': 'application/json' },
506 body,
507 signal: AbortSignal.timeout(timeoutMs),
508 });
509 } catch (err) {
510 this.debug(`send failed: ${String(err)}`);
511 return lines.slice(i); // network failure: re-queue this chunk + the rest
512 }
513 }
514 return [];
515 }
516
517 private packageVersion(): string {
518 try {

Callers 1

flushNowMethod · 0.95

Calls 3

readConfigMethod · 0.95
packageVersionMethod · 0.95
debugMethod · 0.95

Tested by

no test coverage detected