From 6ffb5948f2f1719c34db30a4aab1cf5f01f522b9 Mon Sep 17 00:00:00 2001 From: Nidhi Work Date: Tue, 30 Jan 2024 18:29:44 +0000 Subject: [PATCH 1/2] feat(publish-metrics): implement smartSampling for Playwright tracing --- .../outlier-detection-processor.js | 45 +++++++++---------- .../lib/open-telemetry/tracing/playwright.js | 2 + 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/packages/artillery-plugin-publish-metrics/lib/open-telemetry/outlier-detection-processor.js b/packages/artillery-plugin-publish-metrics/lib/open-telemetry/outlier-detection-processor.js index 7611a24a89..7edb145a79 100644 --- a/packages/artillery-plugin-publish-metrics/lib/open-telemetry/outlier-detection-processor.js +++ b/packages/artillery-plugin-publish-metrics/lib/open-telemetry/outlier-detection-processor.js @@ -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 diff --git a/packages/artillery-plugin-publish-metrics/lib/open-telemetry/tracing/playwright.js b/packages/artillery-plugin-publish-metrics/lib/open-telemetry/tracing/playwright.js index f45af9c373..3995d98b7c 100644 --- a/packages/artillery-plugin-publish-metrics/lib/open-telemetry/tracing/playwright.js +++ b/packages/artillery-plugin-publish-metrics/lib/open-telemetry/tracing/playwright.js @@ -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]) { @@ -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 { From 49202a03273a1c60c0270d34a779ff2d1a8715c4 Mon Sep 17 00:00:00 2001 From: Nidhi Work Date: Tue, 30 Jan 2024 18:48:31 +0000 Subject: [PATCH 2/2] refactor: adjust to new configuration design --- .../lib/open-telemetry/tracing/http.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/artillery-plugin-publish-metrics/lib/open-telemetry/tracing/http.js b/packages/artillery-plugin-publish-metrics/lib/open-telemetry/tracing/http.js index cbf07b898a..120a6cab7a 100644 --- a/packages/artillery-plugin-publish-metrics/lib/open-telemetry/tracing/http.js +++ b/packages/artillery-plugin-publish-metrics/lib/open-telemetry/tracing/http.js @@ -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() {