Skip to content

Commit

Permalink
Merge branch 'main' into rrweb
Browse files Browse the repository at this point in the history
  • Loading branch information
t2t2 committed Aug 31, 2022
2 parents a36fc19 + fd2c002 commit 3fbdfd6
Show file tree
Hide file tree
Showing 31 changed files with 597 additions and 107 deletions.
9 changes: 9 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
default:
image: 'cimg/node:current-browsers'

include:
- project: 'ci-cd/templates'
ref: master
file: '/prodsec/.oss-scan.yml'

cache:
key:
files:
Expand Down Expand Up @@ -67,6 +72,10 @@ unit_test:
script:
- npm run test:unit:ci

oss-scan:
stage: test
extends: .oss-scan

release_production:
artifacts:
paths:
Expand Down
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ If the version of Open Telemetry is unspecified for a version, then it is the sa

## Unreleased

## 0.12.1

- Add app version configuration option ([#419](https://github.com/signalfx/splunk-otel-js-web/pull/419))
- Add http method to {document,resource}Fetch spans ([#424](https://github.com/signalfx/splunk-otel-js-web/pull/424))
- Filter out invalid CORS network timings ([#422](https://github.com/signalfx/splunk-otel-js-web/pull/422))

## 0.12.0

- make SplunkPostDocLoadResourceInstrumentation aware of upstream context ([#398](https://github.com/signalfx/splunk-otel-js-web/pull/398))
- Graduate experimental APIs ([#403](https://github.com/signalfx/splunk-otel-js-web/pull/403))

## 0.11.4

- add ignoreUrls config in docload instrumentation ([#392](https://github.com/signalfx/splunk-otel-js-web/pull/392))

## 0.11.3

- Fix polyfilled fetch in IE ([#383](https://github.com/signalfx/splunk-otel-js-web/pull/383))
Expand All @@ -14,7 +29,7 @@ If the version of Open Telemetry is unspecified for a version, then it is the sa

## 0.11.1

- Hotfix: Fix event listeners throwing when useCapture = null ([#374](https://github.com/signalfx/splunk-otel-js-web/pull/374))
- Hotfix: Fix event listeners throwing when useCapture = null ([#374](https://github.com/signalfx/splunk-otel-js-web/pull/374))

## 0.11.0

Expand Down
107 changes: 107 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
When using the API with CDN installation, usage of try...catch blocks is encouraged to not break your app in case RUM library isn't loaded for some reason. This does not apply when bundling RUM with your application (using a npm installation).

# setGlobalAttributes

```ts
SplunkRum.setGlobalAttributes(attributes?: Attributes): void;
```

Update attributes that will be set on every new span. For example this can be used to [update user information on logging in](./IdentifyingUsers.md#providing-it-after-initialisation-using-api)

* `attributes`: [Attributes](https://open-telemetry.github.io/opentelemetry-js-api/interfaces/attributes.html) - Object of attributes that will be set on every span. If undefined, all currently set global attributes will be deleted and no longer added to any new spans.

Returns nothing

**Example:**

```js
SplunkRum.setGlobalAttributes({
'enduser.id': 'Test User',
});
// All new spans now include enduser.id

SplunkRum.setGlobalAttributes({
'dark_mode.enabled': darkModeToggle.status,
});
// All new spans now include enduser.id and dark_mode.enabled

SplunkRum.setGlobalAttributes()
// New spans no longer include those attributes
```

# getGlobalAttributes

```ts
SplunkRum.getGlobalAttributes(): Attributes;
```

Get current set global attributes

No parameters

Returns [Attributes](https://open-telemetry.github.io/opentelemetry-js-api/interfaces/attributes.html) object with attributes that are set on all new spans

**Example:**

```js
SplunkRum.setGlobalAttributes({
'enduser.id': 'Test User',
});
SplunkRum.setGlobalAttributes({
'dark_mode.enabled': darkModeToggle.status,
});

const attrs = SplunkRum.getGlobalAttributes();
/* console.log(attrs)
{
'enduser.id': 'Test User',
'dark_mode.enabled': true
}
*/
```

# getSessionId

```ts
SplunkRum.getSessionId(): string;
```

Get current session ID

No parameters

Returns string

**Example:**

```js
LiveChat.onChatStarted(() => {
LiveChat.setMetadata('splunk.sessionId', SplunkRum.getSessionId());
});
```

# Events

Event listeners can be registered with `addEventListener` and removed with `removeEventListener`. Event listeners receive an object `{ payload: { /* Depending on event */ }}` as the first parameter

```ts
SplunkRum.addEventListener(type: string, listener: Function): void
SplunkRum.removeEventListener(type: string, listener: Function): void
```

Events:

* `'session-changed'` - Emitted when session ID changes
* Payload:
* `sessionId`: string - New session ID
* `'global-attributes-changed'` - Emitted when setGlobalAttributes is called
* Payload:
* `attributes`: [Attributes](https://open-telemetry.github.io/opentelemetry-js-api/interfaces/attributes.html) - New global attributes

**Example:**

```js
SplunkRum.addEventListener('session-changed', (event) => {
LiveChat.setMetadata('splunk.sessionId', event.payload.sessionId);
});
```
1 change: 1 addition & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Below are the different initialization options available for the Agent:
|`rumAuth`|`string [required]`|Provided by installation wizard|Defines a token authorizing the Agent to send the telemetry to the backend. You can find (or generate) the token [here](https://app.signalfx.com/o11y/#/organization/current?selectedKeyValue=sf_section:accesstokens). Notice that RUM and APM auth tokens are different.|
|`app`|`string`|`"unknown-browser-app"`|Application name, used to distinguish the telemetry from different applications.|
|`environment`|`string`|`(none)`|Sets environment for all the spans, used to distinguish between different environments such as `dev`, `test` or `prod`. |
|`version`|`string`|`(none)`|Sets app version for all the spans, used to distinguish between different version deployments. For example: `1.0.1` or `20220820` |
|`globalAttributes`|`object`|`{} empty object`|Sets additional attributes added to all spans (such as version, user id, ...)|
|`allowInsecureBeacon`|`boolean`|`false`|Allows sending data to insecure endpoints not using `https`. It is not recommended to enable this. |
|`debug`|`boolean`|`false`|Enables debug logging in developer console|
Expand Down
4 changes: 4 additions & 0 deletions integration-tests/otel-api-globals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable header/header */
import { trace, context } from '@opentelemetry/api';

export { trace, context };
4 changes: 2 additions & 2 deletions integration-tests/tests/cdn/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = {
}

const rumScriptFetchSpan = await browser.globals.findSpan(
(s) => s.name === 'resourceFetch'
(s) => s.name === 'resourceFetch' && s.tags['http.url'].includes('cdn.signalfx.com')
);
await browser.assert.ok(
!!rumScriptFetchSpan,
Expand All @@ -64,7 +64,7 @@ module.exports = {
);
await browser.assert.strictEqual(
rumScriptFetchSpan.tags['splunk.rumVersion'],
'0.11.2'
'0.12.1'
);
},
};
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
20 changes: 10 additions & 10 deletions integration-tests/tests/errors/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ module.exports = {
await browser.assert.strictEqual(tags['error.message'], ERROR_MESSAGE_MAP[browserName]);

const ERROR_STACK_MAP = {
safari: `global code@${url}:61:15`,
chrome: `TypeError: Cannot set properties of null (setting 'anyField')\n at ${url}:61:25`,
microsoftedge: `TypeError: Cannot set properties of null (setting 'anyField')\n at ${url}:61:25`,
firefox: `@${url}:61:7\n`,
'internet explorer': `TypeError: Unable to set property 'anyField' of undefined or null reference\n at Global code (${url}:61:7)`,
safari: `global code@${url}:62:15`,
chrome: `TypeError: Cannot set properties of null (setting 'anyField')\n at ${url}:62:25`,
microsoftedge: `TypeError: Cannot set properties of null (setting 'anyField')\n at ${url}:62:25`,
firefox: `@${url}:62:7\n`,
'internet explorer': `TypeError: Unable to set property 'anyField' of undefined or null reference\n at Global code (${url}:62:7)`,
};
await browser.assert.strictEqual(tags['error.stack'], ERROR_STACK_MAP[browserName]);
},
Expand Down Expand Up @@ -156,11 +156,11 @@ module.exports = {
await browser.assert.strictEqual(tags['error.message'], ERROR_MESSAGE_MAP[browserName]);

const ERROR_STACK_MAP = {
safari: `global code@${url}:61:15`,
microsoftedge: `TypeError: Cannot set properties of null (setting 'anyField')\n at ${url}:61:25`,
chrome: `TypeError: Cannot set properties of null (setting 'anyField')\n at ${url}:61:25`,
firefox: `@${url}:61:7\n`,
'internet explorer': `TypeError: Unable to set property 'anyField' of undefined or null reference\n at Global code (${url}:61:7)`,
safari: `global code@${url}:62:15`,
microsoftedge: `TypeError: Cannot set properties of null (setting 'anyField')\n at ${url}:62:25`,
chrome: `TypeError: Cannot set properties of null (setting 'anyField')\n at ${url}:62:25`,
firefox: `@${url}:62:7\n`,
'internet explorer': `TypeError: Unable to set property 'anyField' of undefined or null reference\n at Global code (${url}:62:7)`,
};
await browser.assert.strictEqual(tags['error.stack'], ERROR_STACK_MAP[browserName]);
},
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
51 changes: 51 additions & 0 deletions integration-tests/tests/resource-observer/resource-obs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,56 @@ module.exports = {
const afterLoadImage = imageSpans.find( span => span.tags['component'] === 'splunk-post-doc-load-resource');

await browser.assert.notEqual(docLoadImage.traceId, afterLoadImage.traceId);
},
'should propagate tracing context to created spans': async function(browser) {
if (isBrowser(browser, {
safari: true,
edge: true,
ie: true,
})) {
return;
}
await browser.url(browser.globals.getUrl('/resource-observer/resources-custom-context.ejs'));
await browser.globals.findSpan(span => span.name === 'guard-span');

const plImageRootSpan = await browser.globals.getReceivedSpans().find(
span => span.tags['http.url'] && span.tags['http.url'].endsWith('splunk-black.png')
&& span.tags['component'] === 'splunk-post-doc-load-resource'
);
const plImageParentSpan = await browser.globals.getReceivedSpans().find(
span => span.name === 'image-parent'
);
const plImageChildSpan = await browser.globals.getReceivedSpans().find(
span => span.tags['http.url'] && span.tags['http.url'].endsWith('splunk-black.svg')
&& span.tags['component'] === 'splunk-post-doc-load-resource'
);
await browser.assert.ok(plImageRootSpan);
await browser.assert.ok(plImageParentSpan);
await browser.assert.ok(plImageChildSpan);

await browser.assert.notEqual(plImageRootSpan.traceId, plImageParentSpan.traceId);
await browser.assert.not.ok(plImageRootSpan.parentId);
await browser.assert.equal(plImageParentSpan.traceId, plImageChildSpan.traceId);
await browser.assert.equal(plImageChildSpan.parentId, plImageParentSpan.id);

const plScriptRootSpan = await browser.globals.getReceivedSpans().find(
span => span.tags['http.url'] && span.tags['http.url'].endsWith('test.js')
&& span.tags['component'] === 'splunk-post-doc-load-resource'
);
const plScriptParentSpan = await browser.globals.getReceivedSpans().find(
span => span.name === 'script-parent'
);
const plScriptChildSpan = await browser.globals.getReceivedSpans().find(
span => span.tags['http.url'] && span.tags['http.url'].endsWith('test-alt.js')
&& span.tags['component'] === 'splunk-post-doc-load-resource'
);
await browser.assert.ok(plScriptRootSpan);
await browser.assert.ok(plScriptParentSpan);
await browser.assert.ok(plScriptChildSpan);

await browser.assert.notEqual(plScriptRootSpan.traceId, plScriptParentSpan.traceId);
await browser.assert.not.ok(plScriptRootSpan.parentId);
await browser.assert.equal(plScriptParentSpan.traceId, plScriptChildSpan.traceId);
await browser.assert.equal(plScriptChildSpan.parentId, plScriptParentSpan.id);
}
};
Loading

0 comments on commit 3fbdfd6

Please sign in to comment.