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. -->
This commit is contained in:
Adam
2025-08-10 10:24:46 -07:00
committed by GitHub
parent 496b600679
commit 79ebdd721d
3 changed files with 27 additions and 31 deletions

View File

@@ -305,10 +305,10 @@ export const modifyThreadLabelsInDB = async (
const threadResult = await getThread(connectionId, threadId);
const shard = await getShardClient(connectionId, threadResult.shardId);
await shard.stub.modifyThreadLabelsInDB(threadId, addLabels, removeLabels);
const agent = await getZeroSocketAgent(connectionId);
await agent.invalidateDoStateCache();
await sendDoState(connectionId);
};
@@ -402,8 +402,8 @@ export const getThreadsFromDB = async (
},
): Promise<IGetThreadsResponse> => {
// Fire and forget - don't block the thread query on state updates
const agent = await getZeroSocketAgent(connectionId);
await agent.invalidateDoStateCache();
// const agent = await getZeroSocketAgent(connectionId);
// await agent.invalidateDoStateCache();
void sendDoState(connectionId);
const maxResults = params.maxResults ?? defaultPageSize;

View File

@@ -22,7 +22,7 @@ import {
} from './lib/attachments';
import { SyncThreadsCoordinatorWorkflow } from './workflows/sync-threads-coordinator-workflow';
import { WorkerEntrypoint, DurableObject, RpcTarget } from 'cloudflare:workers';
import { instrument, type ResolveConfigFn } from '@microlabs/otel-cf-workers';
// import { instrument, type ResolveConfigFn } from '@microlabs/otel-cf-workers';
import { getZeroAgent, getZeroDB, verifyToken } from './lib/server-utils';
import { SyncThreadsWorkflow } from './workflows/sync-threads-workflow';
import { ShardRegistry, ZeroAgent, ZeroDriver } from './routes/agent';
@@ -824,32 +824,28 @@ const handler = {
},
};
const config: ResolveConfigFn = (env: ZeroEnv) => {
return {
exporter: {
url: env.OTEL_EXPORTER_OTLP_ENDPOINT || 'https://api.axiom.co/v1/traces',
headers: env.OTEL_EXPORTER_OTLP_HEADERS
? Object.fromEntries(
env.OTEL_EXPORTER_OTLP_HEADERS.split(',').map((header: string) => {
const [key, value] = header.split('=');
return [key.trim(), value.trim()];
}),
)
: {},
},
service: {
name: env.OTEL_SERVICE_NAME || 'zero-email-server',
version: '1.0.0',
},
};
};
// const config: ResolveConfigFn = (env: ZeroEnv) => {
// return {
// exporter: {
// url: env.OTEL_EXPORTER_OTLP_ENDPOINT || 'https://api.axiom.co/v1/traces',
// headers: env.OTEL_EXPORTER_OTLP_HEADERS
// ? Object.fromEntries(
// env.OTEL_EXPORTER_OTLP_HEADERS.split(',').map((header: string) => {
// const [key, value] = header.split('=');
// return [key.trim(), value.trim()];
// }),
// )
// : {},
// },
// service: {
// name: env.OTEL_SERVICE_NAME || 'zero-email-server',
// version: '1.0.0',
// },
// };
// };
export default class Entry extends WorkerEntrypoint<ZeroEnv> {
async fetch(request: Request): Promise<Response> {
const instrumentedHandler = instrument(handler, config);
if (instrumentedHandler && instrumentedHandler.fetch) {
return instrumentedHandler.fetch(request as any, this.env, this.ctx);
}
return handler.fetch(request, this.env, this.ctx);
}
async queue(

View File

@@ -13,7 +13,7 @@
*
* Reuse or distribution of this file requires a license from Zero Email Inc.
*/
import { getZeroAgent, connectionToDriver, sendDoState } from '../lib/server-utils';
import { getZeroAgent, connectionToDriver } from '../lib/server-utils';
import { WorkflowEntrypoint, WorkflowStep } from 'cloudflare:workers';
import type { WorkflowEvent } from 'cloudflare:workers';
import { connection } from '../db/schema';
@@ -179,8 +179,8 @@ export class SyncThreadsWorkflow extends WorkflowEntrypoint<ZeroEnv, SyncThreads
const syncEffects = listResult.threads.map(syncSingleThread);
await Promise.allSettled(syncEffects);
await agent.invalidateDoStateCache();
await sendDoState(connectionId);
// await agent.invalidateDoStateCache();
// await sendDoState(connectionId);
await agent.reloadFolder(folder);
console.log(`[SyncThreadsWorkflow] Completed single page ${pageNumber}`);