Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRACING-4435 BETA 4.6.1-2 #106

Merged
merged 2 commits into from
Dec 9, 2024
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
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export const initialize = ({
dropSingleUserInteractionTraces,
getOverriddenServiceName,
defaultServiceName,
ignoreUrls,
}),
);

Expand Down
31 changes: 31 additions & 0 deletions src/sumologic-span-processor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface SumoLogicSpanProcessorConfig
dropSingleUserInteractionTraces?: boolean;
getOverriddenServiceName?: (span: SdkTraceSpan) => string;
defaultServiceName: string;
ignoreUrls?: (string | RegExp)[]; // Allow both strings and RegExp
}

export class SumoLogicSpanProcessor extends BatchSpanProcessor {
Expand All @@ -31,6 +32,8 @@ export class SumoLogicSpanProcessor extends BatchSpanProcessor {

private traceProcessor: ReturnType<typeof createTraceProcessor>;

private static ignoreUrls: RegExp[] = [];

constructor(exporter: SpanExporter, config: SumoLogicSpanProcessorConfig) {
super(exporter, config);
this.shouldCollectSessionId = config.collectSessionId ?? true;
Expand All @@ -41,9 +44,31 @@ export class SumoLogicSpanProcessor extends BatchSpanProcessor {
this.defaultServiceName = config.defaultServiceName;

this.traceProcessor = createTraceProcessor(this);
if (config.ignoreUrls) {
const normalizedUrls = config.ignoreUrls.map((url) =>
typeof url === 'string'
? new RegExp(url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
: url,
);
SumoLogicSpanProcessor.ignoreUrls.push(...normalizedUrls);
}
}

private shouldIgnoreSpan(span: SdkTraceSpan | ReadableSpan): boolean {
const url = span.attributes['http.url'] as string;
if (!url) return false;
return SumoLogicSpanProcessor.ignoreUrls.some((pattern) =>
pattern.test(url),
);
}

onStart(span: SdkTraceSpan, context: Context = ROOT_CONTEXT): void {
// Check if the span should be ignored
if (this.shouldIgnoreSpan(span)) {
// Skip processing this span
return;
}

documentVisibilityState.onStart(span, context);
rootToChildEnrichment.onStart(span, context);
this.traceProcessor.onStart(span, context);
Expand All @@ -62,6 +87,12 @@ export class SumoLogicSpanProcessor extends BatchSpanProcessor {
}

onEnd(span: ReadableSpan): void {
// Check if the span should be ignored
if (this.shouldIgnoreSpan(span)) {
// Skip processing this span
return;
}

documentVisibilityState.onEnd(span);

// we use callbacks instead of Promises, because even immediately resolved Promise won't be executed synchronously
Expand Down
Loading