Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions src/instrumentation/libraries/http/Instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,20 +256,6 @@ export class HttpInstrumentation extends TdInstrumentationBase {
return originalHandler.call(this);
}

if (
!shouldSample({
samplingRate: this.tuskDrift.getSamplingRate(),
isAppReady: this.tuskDrift.isAppReady(),
})
) {
logger.debug(
`Skipping server span due to sampling rate`,
url,
this.tuskDrift.getSamplingRate(),
);
return originalHandler.call(this);
}

logger.debug(`[HttpInstrumentation] Creating server span for ${method} ${url}`);
return handleRecordMode({
originalFunctionCall: () => originalHandler.call(this),
Expand Down Expand Up @@ -1313,6 +1299,18 @@ export class HttpInstrumentation extends TdInstrumentationBase {
return (originalEmit: Function) => {
return function (this: Server, eventName: string, ...args: any[]) {
if (eventName === "request") {
// Sample as soon as we can to avoid additional overhead if this request is not sampled
if (self.mode === TuskDriftMode.RECORD) {
if (
!shouldSample({
samplingRate: self.tuskDrift.getSamplingRate(),
isAppReady: self.tuskDrift.isAppReady(),
})
) {
return originalEmit.apply(this, [eventName, ...args]);
}
}

const req = args[0];
const res = args[1];

Expand Down
24 changes: 12 additions & 12 deletions src/instrumentation/libraries/nextjs/Instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ export class NextjsInstrumentation extends TdInstrumentationBase {

return (originalHandleRequest: Function) => {
return async function (this: any, req: any, res: any, parsedUrl?: any) {
// Sample as soon as we can to avoid additional overhead if this request is not sampled
if (self.mode === TuskDriftMode.RECORD) {
if (
!shouldSample({
samplingRate: self.tuskDrift.getSamplingRate(),
isAppReady: self.tuskDrift.isAppReady(),
})
) {
return originalHandleRequest.call(this, req, res, parsedUrl);
}
}

const method = req.method || "GET";
const url = req.url || "/";

Expand Down Expand Up @@ -193,18 +205,6 @@ export class NextjsInstrumentation extends TdInstrumentationBase {
return originalHandleRequest.call(this, req, res, parsedUrl);
}

if (
!shouldSample({
samplingRate: self.tuskDrift.getSamplingRate(),
isAppReady: self.tuskDrift.isAppReady(),
})
) {
logger.debug(
`[NextjsInstrumentation] Skipping server span due to sampling rate: ${url}`,
);
return originalHandleRequest.call(this, req, res, parsedUrl);
}

logger.debug(`[NextjsInstrumentation] Creating server span for ${method} ${url}`);
return handleRecordMode({
originalFunctionCall: () => originalHandleRequest.call(this, req, res, parsedUrl),
Expand Down