Fix duplicate startSession logs and duplicate logging events over the wire (#1357)
This commit is contained in:
parent
335802f4dd
commit
3012684469
|
@ -85,12 +85,15 @@ export class ClearcutLogger {
|
|||
if (this.config?.getDebugMode()) {
|
||||
console.log('Flushing log events to Clearcut.');
|
||||
}
|
||||
const eventsToSend = [...this.events];
|
||||
this.events.length = 0;
|
||||
|
||||
return new Promise<Buffer>((resolve, reject) => {
|
||||
const request = [
|
||||
{
|
||||
log_source_name: 'CONCORD',
|
||||
request_time_ms: Date.now(),
|
||||
log_event: this.events,
|
||||
log_event: eventsToSend,
|
||||
},
|
||||
];
|
||||
const body = JSON.stringify(request);
|
||||
|
@ -114,12 +117,13 @@ export class ClearcutLogger {
|
|||
if (this.config?.getDebugMode()) {
|
||||
console.log('Clearcut POST request error: ', e);
|
||||
}
|
||||
// Add the events back to the front of the queue to be retried.
|
||||
this.events.unshift(...eventsToSend);
|
||||
reject(e);
|
||||
});
|
||||
req.end(body);
|
||||
}).then((buf: Buffer) => {
|
||||
try {
|
||||
this.events.length = 0;
|
||||
this.last_flush_time = Date.now();
|
||||
return this.decodeLogResponse(buf) || {};
|
||||
} catch (error: unknown) {
|
||||
|
|
|
@ -28,8 +28,6 @@ import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
|
|||
import { Config } from '../config/config.js';
|
||||
import { SERVICE_NAME } from './constants.js';
|
||||
import { initializeMetrics } from './metrics.js';
|
||||
import { logCliConfiguration } from './loggers.js';
|
||||
import { StartSessionEvent } from './types.js';
|
||||
import { ClearcutLogger } from './clearcut-logger/clearcut-logger.js';
|
||||
|
||||
// For troubleshooting, set the log level to DiagLogLevel.DEBUG
|
||||
|
@ -115,7 +113,6 @@ export function initializeTelemetry(config: Config): void {
|
|||
console.log('OpenTelemetry SDK started successfully.');
|
||||
telemetryInitialized = true;
|
||||
initializeMetrics(config);
|
||||
logCliConfiguration(config, new StartSessionEvent(config));
|
||||
} catch (error) {
|
||||
console.error('Error starting OpenTelemetry SDK:', error);
|
||||
}
|
||||
|
|
|
@ -12,12 +12,9 @@ import {
|
|||
} from './sdk.js';
|
||||
import { Config } from '../config/config.js';
|
||||
import { NodeSDK } from '@opentelemetry/sdk-node';
|
||||
import * as loggers from './loggers.js';
|
||||
import { StartSessionEvent } from './types.js';
|
||||
|
||||
vi.mock('@opentelemetry/sdk-node');
|
||||
vi.mock('../config/config.js');
|
||||
vi.mock('./loggers.js');
|
||||
|
||||
describe('telemetry', () => {
|
||||
let mockConfig: Config;
|
||||
|
@ -38,8 +35,6 @@ describe('telemetry', () => {
|
|||
'http://localhost:4317',
|
||||
);
|
||||
vi.spyOn(mockConfig, 'getSessionId').mockReturnValue('test-session-id');
|
||||
vi.spyOn(loggers, 'logCliConfiguration').mockImplementation(() => {});
|
||||
|
||||
mockNodeSdk = {
|
||||
start: vi.fn(),
|
||||
shutdown: vi.fn().mockResolvedValue(undefined),
|
||||
|
@ -56,11 +51,8 @@ describe('telemetry', () => {
|
|||
|
||||
it('should initialize the telemetry service', () => {
|
||||
initializeTelemetry(mockConfig);
|
||||
const event = new StartSessionEvent(mockConfig);
|
||||
|
||||
expect(NodeSDK).toHaveBeenCalled();
|
||||
expect(mockNodeSdk.start).toHaveBeenCalled();
|
||||
expect(loggers.logCliConfiguration).toHaveBeenCalledWith(mockConfig, event);
|
||||
});
|
||||
|
||||
it('should shutdown the telemetry service', async () => {
|
||||
|
|
Loading…
Reference in New Issue