Skip to content

Commit 79ebdd7

Browse files
authored
Disable OpenTelemetry instrumentation and reduce state cache invalidations (#1975)
# READ CAREFULLY THEN REMOVE Remove bullet points that are not relevant. PLEASE REFRAIN FROM USING AI TO WRITE YOUR CODE AND PR DESCRIPTION. IF YOU DO USE AI TO WRITE YOUR CODE PLEASE PROVIDE A DESCRIPTION AND REVIEW IT CAREFULLY. MAKE SURE YOU UNDERSTAND THE CODE YOU ARE SUBMITTING USING AI. - Pull requests that do not follow these guidelines will be closed without review or comment. - If you use AI to write your PR description your pr will be close without review or comment. - If you are unsure about anything, feel free to ask for clarification. ## Description Please provide a clear description of your changes. --- ## Type of Change Please delete options that are not relevant. - [ ] 🐛 Bug fix (non-breaking change which fixes an issue) - [ ] ✨ New feature (non-breaking change which adds functionality) - [ ] 💥 Breaking change (fix or feature with breaking changes) - [ ] 📝 Documentation update - [ ] 🎨 UI/UX improvement - [ ] 🔒 Security enhancement - [ ] ⚡ Performance improvement ## Areas Affected Please check all that apply: - [ ] Email Integration (Gmail, IMAP, etc.) - [ ] User Interface/Experience - [ ] Authentication/Authorization - [ ] Data Storage/Management - [ ] API Endpoints - [ ] Documentation - [ ] Testing Infrastructure - [ ] Development Workflow - [ ] Deployment/Infrastructure ## Testing Done Describe the tests you've done: - [ ] Unit tests added/updated - [ ] Integration tests added/updated - [ ] Manual testing performed - [ ] Cross-browser testing (if UI changes) - [ ] Mobile responsiveness verified (if UI changes) ## Security Considerations For changes involving data or authentication: - [ ] No sensitive data is exposed - [ ] Authentication checks are in place - [ ] Input validation is implemented - [ ] Rate limiting is considered (if applicable) ## Checklist - [ ] I have read the [CONTRIBUTING](https://github.com/Mail-0/Zero/blob/staging/.github/CONTRIBUTING.md) document - [ ] My code follows the project's style guidelines - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in complex areas - [ ] I have updated the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix/feature works - [ ] All tests pass locally - [ ] Any dependent changes are merged and published ## Additional Notes Add any other context about the pull request here. ## Screenshots/Recordings Add screenshots or recordings here if applicable. --- _By submitting this pull request, I confirm that my contribution is made under the terms of the project's license._ <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Disabled OpenTelemetry instrumentation and reduced unnecessary state cache invalidations to improve server performance. - **Refactors** - Commented out OpenTelemetry setup and usage in the server entrypoint. - Limited calls to invalidate and send state cache in thread and workflow logic. <!-- End of auto-generated description by cubic. -->
1 parent 496b600 commit 79ebdd7

File tree

3 files changed

+27
-31
lines changed

3 files changed

+27
-31
lines changed

apps/server/src/lib/server-utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,10 @@ export const modifyThreadLabelsInDB = async (
305305
const threadResult = await getThread(connectionId, threadId);
306306
const shard = await getShardClient(connectionId, threadResult.shardId);
307307
await shard.stub.modifyThreadLabelsInDB(threadId, addLabels, removeLabels);
308-
308+
309309
const agent = await getZeroSocketAgent(connectionId);
310310
await agent.invalidateDoStateCache();
311-
311+
312312
await sendDoState(connectionId);
313313
};
314314

@@ -402,8 +402,8 @@ export const getThreadsFromDB = async (
402402
},
403403
): Promise<IGetThreadsResponse> => {
404404
// Fire and forget - don't block the thread query on state updates
405-
const agent = await getZeroSocketAgent(connectionId);
406-
await agent.invalidateDoStateCache();
405+
// const agent = await getZeroSocketAgent(connectionId);
406+
// await agent.invalidateDoStateCache();
407407
void sendDoState(connectionId);
408408

409409
const maxResults = params.maxResults ?? defaultPageSize;

apps/server/src/main.ts

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from './lib/attachments';
2323
import { SyncThreadsCoordinatorWorkflow } from './workflows/sync-threads-coordinator-workflow';
2424
import { WorkerEntrypoint, DurableObject, RpcTarget } from 'cloudflare:workers';
25-
import { instrument, type ResolveConfigFn } from '@microlabs/otel-cf-workers';
25+
// import { instrument, type ResolveConfigFn } from '@microlabs/otel-cf-workers';
2626
import { getZeroAgent, getZeroDB, verifyToken } from './lib/server-utils';
2727
import { SyncThreadsWorkflow } from './workflows/sync-threads-workflow';
2828
import { ShardRegistry, ZeroAgent, ZeroDriver } from './routes/agent';
@@ -824,32 +824,28 @@ const handler = {
824824
},
825825
};
826826

827-
const config: ResolveConfigFn = (env: ZeroEnv) => {
828-
return {
829-
exporter: {
830-
url: env.OTEL_EXPORTER_OTLP_ENDPOINT || 'https://api.axiom.co/v1/traces',
831-
headers: env.OTEL_EXPORTER_OTLP_HEADERS
832-
? Object.fromEntries(
833-
env.OTEL_EXPORTER_OTLP_HEADERS.split(',').map((header: string) => {
834-
const [key, value] = header.split('=');
835-
return [key.trim(), value.trim()];
836-
}),
837-
)
838-
: {},
839-
},
840-
service: {
841-
name: env.OTEL_SERVICE_NAME || 'zero-email-server',
842-
version: '1.0.0',
843-
},
844-
};
845-
};
827+
// const config: ResolveConfigFn = (env: ZeroEnv) => {
828+
// return {
829+
// exporter: {
830+
// url: env.OTEL_EXPORTER_OTLP_ENDPOINT || 'https://api.axiom.co/v1/traces',
831+
// headers: env.OTEL_EXPORTER_OTLP_HEADERS
832+
// ? Object.fromEntries(
833+
// env.OTEL_EXPORTER_OTLP_HEADERS.split(',').map((header: string) => {
834+
// const [key, value] = header.split('=');
835+
// return [key.trim(), value.trim()];
836+
// }),
837+
// )
838+
// : {},
839+
// },
840+
// service: {
841+
// name: env.OTEL_SERVICE_NAME || 'zero-email-server',
842+
// version: '1.0.0',
843+
// },
844+
// };
845+
// };
846846

847847
export default class Entry extends WorkerEntrypoint<ZeroEnv> {
848848
async fetch(request: Request): Promise<Response> {
849-
const instrumentedHandler = instrument(handler, config);
850-
if (instrumentedHandler && instrumentedHandler.fetch) {
851-
return instrumentedHandler.fetch(request as any, this.env, this.ctx);
852-
}
853849
return handler.fetch(request, this.env, this.ctx);
854850
}
855851
async queue(

apps/server/src/workflows/sync-threads-workflow.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* Reuse or distribution of this file requires a license from Zero Email Inc.
1515
*/
16-
import { getZeroAgent, connectionToDriver, sendDoState } from '../lib/server-utils';
16+
import { getZeroAgent, connectionToDriver } from '../lib/server-utils';
1717
import { WorkflowEntrypoint, WorkflowStep } from 'cloudflare:workers';
1818
import type { WorkflowEvent } from 'cloudflare:workers';
1919
import { connection } from '../db/schema';
@@ -179,8 +179,8 @@ export class SyncThreadsWorkflow extends WorkflowEntrypoint<ZeroEnv, SyncThreads
179179
const syncEffects = listResult.threads.map(syncSingleThread);
180180
await Promise.allSettled(syncEffects);
181181

182-
await agent.invalidateDoStateCache();
183-
await sendDoState(connectionId);
182+
// await agent.invalidateDoStateCache();
183+
// await sendDoState(connectionId);
184184
await agent.reloadFolder(folder);
185185

186186
console.log(`[SyncThreadsWorkflow] Completed single page ${pageNumber}`);

0 commit comments

Comments
 (0)