From 928ceb1246d28d78823dbd70b758df7c7b48a053 Mon Sep 17 00:00:00 2001 From: Jeymisson Oliveira Date: Wed, 30 Aug 2023 15:16:36 -0300 Subject: [PATCH] Remove sampling decision from runtime & only create tracing spans when they come from router --- src/service/tracing/TracerSingleton.ts | 6 ------ src/service/tracing/tracingMiddlewares.ts | 9 +++++++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/service/tracing/TracerSingleton.ts b/src/service/tracing/TracerSingleton.ts index 671361755..30031568f 100644 --- a/src/service/tracing/TracerSingleton.ts +++ b/src/service/tracing/TracerSingleton.ts @@ -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, } diff --git a/src/service/tracing/tracingMiddlewares.ts b/src/service/tracing/tracingMiddlewares.ts index 9e9a0093b..de1793777 100644 --- a/src/service/tracing/tracingMiddlewares.ts +++ b/src/service/tracing/tracingMiddlewares.ts @@ -30,14 +30,14 @@ export const addTracingMiddleware = (tracer: Tracer) => { return async function addTracing(ctx: ServiceContext, next: () => Promise) { 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 }, @@ -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 +} +