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

feat(publish-metrics): implement smartSampling for Playwright tracing #2453

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,29 @@ class OutlierDetectionBatchSpanProcessor extends BatchSpanProcessor {
}

onEnd(span) {
if (span.instrumentationLibrary.name === 'artillery-playwright') {
super.onEnd(span);
} else {
const traceId = span.spanContext().traceId;

// When an outlier span is recognised the whole trace it belongs to is exported, so all the spans that belong to the trace need to be grouped and held until the trace finishes.
if (!this._traces.has(traceId)) {
this._traces.set(traceId, {
spans: [],
hasOutlier: false
});
}
const traceData = this._traces.get(traceId);
traceData.spans.push(span);
const traceId = span.spanContext().traceId;

// When an outlier span is recognised the whole trace it belongs to is exported, so all the spans that belong to the trace need to be grouped and held until the trace finishes.
if (!this._traces.has(traceId)) {
this._traces.set(traceId, {
spans: [],
hasOutlier: false
});
}
const traceData = this._traces.get(traceId);
traceData.spans.push(span);

// Since only request level spans are screened for outliers, the outlier check is performed only if the span is a request level span - has 'http.url' attribute
if (span.attributes['http.url'] && this._isOutlier(span)) {
traceData.hasOutlier = true;
}
if (this._isOutlier(span)) {
traceData.hasOutlier = true;
}

// The trace ends when the root span ends, so we only filter and send data when the span that ended is the root span
// The traces that do not have outlier spans are dropped and the rest is sent to buffer/export
if (!span.parentSpanId) {
if (traceData.hasOutlier) {
traceData.spans.forEach(super.onEnd, this);
}
this._traces.delete(traceId);
// The trace ends when the root span ends, so we only filter and send data when the span that ended is the root span
// The traces that do not have outlier spans are dropped and the rest is sent to buffer/export
if (!span.parentSpanId) {
if (traceData.hasOutlier) {
traceData.spans.forEach(super.onEnd, this);
}
this._traces.delete(traceId);
}
}
// Export only outliers on shut down as well for http engine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {
class OTelHTTPTraceReporter extends OTelTraceBase {
constructor(config, script) {
super(config, script);
this.outlierCriteria = config.smartSampling;
this.outlierCriteria = config.smartSampling?.http;
this.statusAsErrorThreshold = 400;
}
run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class OTelPlaywrightTraceReporter extends OTelTraceBase {
code: SpanStatusCode.ERROR,
message: err.message
});
scenarioSpan.setAttribute('outlier', true);
throw err;
} finally {
if (pageSpan && !pageSpan.endTime[0]) {
Expand Down Expand Up @@ -180,6 +181,7 @@ class OTelPlaywrightTraceReporter extends OTelTraceBase {
code: SpanStatusCode.ERROR,
message: err.message
});
span.setAttribute('outlier', true);
debug('There has been an error during step execution:');
throw err;
} finally {
Expand Down
Loading