MCPcopy Index your code
hub / github.com/simstudioai/sim / createBusinessSpanSampler

Function createBusinessSpanSampler

apps/sim/instrumentation-node.ts:188–226  ·  view source on GitHub ↗
(rootRatioSampler: Sampler)

Source from the content-addressed store, hash-verified

186 // parents, and re-samples business roots fresh (don't delegate to
187 // ParentBased — its unsampled-parent path is AlwaysOff by default).
188 const createBusinessSpanSampler = (rootRatioSampler: Sampler): Sampler => ({
189 shouldSample(
190 context: Context,
191 traceId: string,
192 spanName: string,
193 spanKind: SpanKind,
194 attributes: Attributes,
195 links: Link[]
196 ): SamplingResult {
197 if (attributes['next.span_type']) {
198 return { decision: SamplingDecision.NOT_RECORD }
199 }
200
201 const parentSpanContext = trace.getSpanContext(context)
202 const parentIsSampled =
203 !!parentSpanContext &&
204 (parentSpanContext.traceFlags & TraceFlags.SAMPLED) === TraceFlags.SAMPLED
205
206 if (parentIsSampled) {
207 return { decision: SamplingDecision.RECORD_AND_SAMPLED }
208 }
209
210 if (isBusinessSpan(spanName)) {
211 return rootRatioSampler.shouldSample(
212 context,
213 traceId,
214 spanName,
215 spanKind,
216 attributes,
217 links
218 )
219 }
220
221 return { decision: SamplingDecision.NOT_RECORD }
222 },
223 toString(): string {
224 return `BusinessSpanSampler{rootSampler=${rootRatioSampler.toString()}}`
225 },
226 })
227
228 const otlpHeaders = parseOtlpHeaders(process.env.OTEL_EXPORTER_OTLP_HEADERS || '')
229 const exporterUrl = normalizeOtlpTracesUrl(telemetryConfig.endpoint)

Callers 1

initializeOpenTelemetryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected