Skip to content

Commit

Permalink
feat: add referrer attribute to entry_page resource (#54)
Browse files Browse the repository at this point in the history
Follow-up to #30: adds the referrer to `entry_page` attributes; provides
visibility into what url (if any) provided the link into your
instrumented page.
  • Loading branch information
ahrbnsn authored Jan 30, 2024
1 parent 85dd311 commit 5638cc2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,22 @@ You can also [add your own instrumentation](https://docs.honeycomb.io/getting-da

The SDK adds these fields to all telemetry:

| name | status | static? | description | example |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| user_agent.original | [stable](https://github.com/scheler/opentelemetry-specification/blob/browser-events/specification/resource/semantic_conventions/browser.md) | static | window.user_agent | `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36` |
| browser.height | planned | per-span | `[window.innerHeight](https://developer.mozilla.org/en-US/docs/Web/API/Window/innerHeight)`, the height of the layout viewport in pixels | 287 |
| browser.brands | stable | static | [NavigatorUAData: brands](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/brands) | ["Not_A Brand 8", "Chromium 120", "Google Chrome 120"] |
| browser.platform | stable | static | [NavigatorUAData: platform](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/platform) | "Windows" |
| browser.mobile | stable | static | [NavigatorUAData: mobile](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/mobile) | true |
| browser.language | stable | static | [Navigator: language](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language) | "fr-FR" |
| honeycomb.distro.version | stable | static | package version | "1.2.3" |
| honeycomb.distro.runtime_version | stable | static | | "browser" |
| `entry_page.url` | custom | static | | `https://docs.honeycomb.io/getting-data-in/data-best-practices/#datasets-group-data-together?page=2` |
| `entry_page.path` | custom | static | | `/getting-data-in/data-best-practices/` |
| `entry_page.search` | custom | static | | `?page=2` |
| `entry_page.hash` | custom | static | | `#datasets-group-data-together` |
| `entry_page.hostname` | custom | static | | `docs.honeycomb.io` |
| name | status | static? | description | example |
|------|--------|---------|-------------|---------|
| user_agent.original | [stable](https://github.com/scheler/opentelemetry-specification/blob/browser-events/specification/resource/semantic_conventions/browser.md) | static | window.user_agent | `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36` |
| browser.height | planned | per-span | `[window.innerHeight](https://developer.mozilla.org/en-US/docs/Web/API/Window/innerHeight)`, the height of the layout viewport in pixels | 287 |
| browser.brands | stable | static | [NavigatorUAData: brands](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/brands) | ["Not_A Brand 8", "Chromium 120", "Google Chrome 120"] |
| browser.platform | stable | static | [NavigatorUAData: platform](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/platform) | "Windows" |
| browser.mobile | stable | static | [NavigatorUAData: mobile](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/mobile) | true |
| browser.language | stable | static | [Navigator: language](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language) | "fr-FR" |
| honeycomb.distro.version | stable | static | package version | "1.2.3" |
| honeycomb.distro.runtime_version | stable | static | | "browser"
| `entry_page.url` | custom | static | | `https://docs.honeycomb.io/getting-data-in/data-best-practices/#datasets-group-data-together?page=2` |
| `entry_page.path` | custom | static | | `/getting-data-in/data-best-practices/` |
| `entry_page.search` | custom | static | | `?page=2` |
| `entry_page.hash` | custom | static | | `#datasets-group-data-together` |
| `entry_page.hostname` | custom | static | | `docs.honeycomb.io` |
| `entry_page.referrer` | custom | static | [Document: referrer](https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer) | `https://honeycomb.io` |

Static fields are added to the [Resource](https://opentelemetry.io/docs/concepts/resources/), so they are same for every span emitted for the loaded page.

Expand Down
1 change: 1 addition & 0 deletions src/entry-page-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function configureEntryPageResource(): Resource {
'entry_page.search': search,
'entry_page.hash': hash,
'entry_page.hostname': hostname,
'entry_page.referrer': document.referrer,
};
}

Expand Down
9 changes: 9 additions & 0 deletions test/entry-page-resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
import { configureEntryPageResource } from '../src/entry-page-resource';
import { Resource } from '@opentelemetry/resources';

afterEach(() => {
jest.resetAllMocks();
});

test('it should return a Resource', () => {
const resource = configureEntryPageResource();
expect(resource).toBeInstanceOf(Resource);
});

test('it should have location attributes', () => {
jest
.spyOn(document, 'referrer', 'get')
.mockReturnValue('http://fan-site.com');

const resource = configureEntryPageResource();
expect(resource.attributes).toEqual({
'entry_page.url':
Expand All @@ -18,5 +26,6 @@ test('it should have location attributes', () => {
'entry_page.search': '?search_params=yes&hello=hi',
'entry_page.hash': '#the-hash',
'entry_page.hostname': 'something-something.com',
'entry_page.referrer': 'http://fan-site.com',
});
});

0 comments on commit 5638cc2

Please sign in to comment.