Skip to content

Commit

Permalink
Remove sampling decision from runtime & only create tracing spans whe…
Browse files Browse the repository at this point in the history
…n they come from router
  • Loading branch information
Jeymisson committed Aug 30, 2023
1 parent 1b3c549 commit 928ceb1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 0 additions & 6 deletions src/service/tracing/TracerSingleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ export class TracerSingleton {
reporter: {
agentHost: process.env.VTEX_OWN_NODE_IP,
},
sampler: {
host: process.env.VTEX_OWN_NODE_IP,
param: 0.05,
refreshIntervalMs: 60 * 1000,
type: 'remote',
},
serviceName,
}

Expand Down
9 changes: 7 additions & 2 deletions src/service/tracing/tracingMiddlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ export const addTracingMiddleware = (tracer: Tracer) => {
return async function addTracing(ctx: ServiceContext, next: () => Promise<void>) {
const start = process.hrtime()
concurrentRequests.inc(1)
const rootSpan = tracer.extract(FORMAT_HTTP_HEADERS, ctx.request.headers) as undefined | SpanContext

if (PATHS_BLACKLISTED_FOR_TRACING.includes(ctx.request.path)) {
if (!shouldTrace(ctx, rootSpan)) {
await next()
concurrentRequests.dec(1)
return
}

const rootSpan = tracer.extract(FORMAT_HTTP_HEADERS, ctx.request.headers) as undefined | SpanContext
const currentSpan = tracer.startSpan('unknown-operation', {
childOf: rootSpan,
tags: { [OpentracingTags.SPAN_KIND]: OpentracingTags.SPAN_KIND_RPC_SERVER },
Expand Down Expand Up @@ -150,3 +150,8 @@ export const traceUserLandRemainingPipelineMiddleware = () => {
}
}
}
function shouldTrace(ctx: ServiceContext, rootSpan: SpanContext | undefined) {
// Should trace if path isnt blacklisted and tracing decision came from the edge
return !PATHS_BLACKLISTED_FOR_TRACING.includes(ctx.request.path) && rootSpan
}

0 comments on commit 928ceb1

Please sign in to comment.