Skip to content

Commit 7551adf

Browse files
committed
Add ability to disable tracing to test if it’s the cause of the memory leak
1 parent 69117e8 commit 7551adf

File tree

3 files changed

+7
-35
lines changed

3 files changed

+7
-35
lines changed

apps/webapp/app/env.server.ts

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ const EnvironmentSchema = z.object({
139139
// this means 1/20 traces or 5% of traces will be sampled (sampled = recorded)
140140
INTERNAL_OTEL_TRACE_SAMPLING_RATE: z.string().default("20"),
141141
INTERNAL_OTEL_TRACE_INSTRUMENT_PRISMA_ENABLED: z.string().default("0"),
142+
INTERNAL_OTEL_TRACE_DISABLED: z.string().default("0"),
142143
});
143144

144145
export type Environment = z.infer<typeof EnvironmentSchema>;

apps/webapp/app/v3/marqs/sharedQueueConsumer.server.ts

-35
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export class SharedQueueConsumer {
7777
private _currentSpan: Span | undefined;
7878
private _endSpanInNextIteration = false;
7979
private _tasks = sharedQueueTasks;
80-
private _inProgressAttempts: Map<string, string> = new Map(); // Keys are task attempt friendly IDs, values are TaskRun ids/queue message ids
8180

8281
constructor(
8382
private _sender: ZodMessageSender<typeof serverWebsocketMessages>,
@@ -151,38 +150,6 @@ export class SharedQueueConsumer {
151150
}
152151
}
153152

154-
async #cancelInProgressAttempts(reason: string) {
155-
const service = new CancelAttemptService();
156-
157-
const cancelledAt = new Date();
158-
159-
const inProgressAttempts = new Map(this._inProgressAttempts);
160-
161-
this._inProgressAttempts.clear();
162-
163-
for (const [attemptId, messageId] of inProgressAttempts) {
164-
await this.#cancelInProgressAttempt(attemptId, messageId, service, cancelledAt, reason);
165-
}
166-
}
167-
168-
async #cancelInProgressAttempt(
169-
attemptId: string,
170-
messageId: string,
171-
cancelAttemptService: CancelAttemptService,
172-
cancelledAt: Date,
173-
reason: string
174-
) {
175-
try {
176-
await cancelAttemptService.call(attemptId, messageId, cancelledAt, reason);
177-
} catch (e) {
178-
logger.error("Failed to cancel in progress attempt", {
179-
attemptId,
180-
messageId,
181-
error: e,
182-
});
183-
}
184-
}
185-
186153
#enable() {
187154
if (this._enabled) {
188155
return;
@@ -495,8 +462,6 @@ export class SharedQueueConsumer {
495462
},
496463
});
497464
}
498-
499-
this._inProgressAttempts.set(taskRunAttempt.friendlyId, message.messageId);
500465
} catch (e) {
501466
if (e instanceof Error) {
502467
this._currentSpan?.recordException(e);

apps/webapp/app/v3/tracer.server.ts

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ class CustomWebappSampler implements Sampler {
7777
export const tracer = singleton("tracer", getTracer);
7878

7979
function getTracer() {
80+
if (env.INTERNAL_OTEL_TRACE_DISABLED === "1") {
81+
console.log(`🔦 Tracer disabled, returning a noop tracer`);
82+
83+
return trace.getTracer("trigger.dev", "3.0.0.dp.1");
84+
}
85+
8086
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ERROR);
8187

8288
const samplingRate = 1.0 / Math.max(parseInt(env.INTERNAL_OTEL_TRACE_SAMPLING_RATE, 10), 1);

0 commit comments

Comments
 (0)