UNPKG

@ogcio/o11y-sdk-node

Version:

Opentelemetry standard instrumentation SDK for NodeJS based project

26 lines (25 loc) 1.04 kB
import { SamplingDecision, } from "@opentelemetry/sdk-trace-base"; export class UrlSampler { _samplerCondition; _nextSampler; constructor(samplerCondition = [], nextSampler) { this._samplerCondition = samplerCondition; this._nextSampler = nextSampler; } shouldSample(_context, traceId, _spanName, _spanKind, attributes, _links) { const url = attributes["http.target"]?.toString(); if (url) { for (const condition of this._samplerCondition) { if ((condition.type === "equals" && url === condition.url) || (condition.type === "endsWith" && url.endsWith(condition.url)) || (condition.type === "includes" && url.includes(condition.url))) { return { decision: SamplingDecision.NOT_RECORD }; } } } return this._nextSampler.shouldSample(_context, traceId, _spanName, _spanKind, attributes, _links); } toString() { return "UrlSampler"; } }