Skip to content

Commit

Permalink
ignoreUrls config in docload instrumentation (signalfx#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
t2t2 authored and sfishel-splunk committed Jun 25, 2022
1 parent 7b99dfe commit 568549e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
19 changes: 19 additions & 0 deletions integration-tests/tests/docload/docload-ignored.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test init</title>

<%- renderAgent({}, true) %>
<script>
window.SplunkRumOptions.ignoreUrls = [
window.location.origin + '/non-impactful-resource.jpg'
];
window.SplunkRum && window.SplunkRum.init(window.SplunkRumOptions);
</script>
</head>
<body>
<p>Docload</p>
<img src="/non-impactful-resource.jpg">
</body>
</html>
9 changes: 9 additions & 0 deletions integration-tests/tests/docload/docload.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ module.exports = {

await browser.globals.assertNoErrorSpans();
},
'ignoring resource URLs': async function(browser) {
await browser.url(browser.globals.getUrl('/docload/docload-ignored.ejs'));

await browser.globals.findSpan(span => span.name === 'documentFetch');
const url = browser.globals.getUrl('/', []);
await browser.assert.not.ok(browser.globals.getReceivedSpans().find(
span => span.tags['http.url'] === url + 'non-impactful-resource.jpg'
));
},
'module can be disabled': async function(browser) {
await browser.url(browser.globals.getUrl('/docload/docload.ejs?disableInstrumentation=document'));
await browser.globals.waitForTestToFinish();
Expand Down
6 changes: 6 additions & 0 deletions integration-tests/tests/errors/views/unhandled-error.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
<title>Errors test</title>
<%- renderAgent({}) %>
<script id="scenario">
window.testing = true;
var test = null;
setTimeout(function() {
setTimeout(function () {
window.testing = false;
});
test.prop1 = true;
});
</script>
Expand Down
9 changes: 7 additions & 2 deletions src/SplunkDocumentLoadInstrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import * as api from '@opentelemetry/api';
import { captureTraceParentFromPerformanceEntries } from './servertiming';
import { PerformanceEntries } from '@opentelemetry/sdk-trace-web';
import { Span } from '@opentelemetry/sdk-trace-base';
import { isUrlIgnored } from '@opentelemetry/core';

export interface SplunkDocLoadInstrumentationConfig extends InstrumentationConfig {
ignoreUrls?: (string|RegExp)[];
}

const excludedInitiatorTypes = ['beacon', 'fetch', 'xmlhttprequest'];

Expand All @@ -40,7 +45,7 @@ type ExposedSuper = {
}

export class SplunkDocumentLoadInstrumentation extends DocumentLoadInstrumentation {
constructor(config: InstrumentationConfig = {}) {
constructor(config: SplunkDocLoadInstrumentationConfig = {}) {
super(config);

const exposedSuper = this as any as ExposedSuper;
Expand Down Expand Up @@ -75,7 +80,7 @@ export class SplunkDocumentLoadInstrumentation extends DocumentLoadInstrumentati

const _superInitResourceSpan: ExposedSuper['_initResourceSpan'] = exposedSuper._initResourceSpan.bind(this);
exposedSuper._initResourceSpan = (resource, parentSpan) => {
if (excludedInitiatorTypes.indexOf(resource.initiatorType) !== -1) {
if (excludedInitiatorTypes.indexOf(resource.initiatorType) !== -1 || isUrlIgnored(resource.name, config.ignoreUrls)) {
return;
}
_superInitResourceSpan(resource, parentSpan);
Expand Down

0 comments on commit 568549e

Please sign in to comment.