Skip to content

Commit 9551a84

Browse files
authored
Change content script -> background script communication mechanism (#19)
* Changes from relying on externally_connectable to CustomEvents (which will eventually work in Firefox) * Adds patch to @opentelemetry/instrumentation-user-interaction so specified event listeners are always registered, regardless of whether any other page code has already registered listeners (see: open-telemetry/opentelemetry-js-contrib#1749) * Adds .github workflow files for (some) CI/CD * Updates README.md
1 parent ba86866 commit 9551a84

18 files changed

+1411
-706
lines changed

.github/dependabot.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pnpm" # See documentation for possible values
4+
directory: "/" # Location of package manifests
5+
schedule:
6+
interval: "weekly"
7+
labels:
8+
- automerge

.github/workflows/build.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
with:
12+
submodules: recursive
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: '20'
16+
- uses: pnpm/action-setup@v4
17+
name: Install pnpm
18+
with:
19+
run_install: false
20+
- name: Get pnpm store directory
21+
shell: bash
22+
run: |
23+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
24+
- uses: actions/cache@v4
25+
name: Setup pnpm cache
26+
with:
27+
path: ${{ env.STORE_PATH }}
28+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
29+
restore-keys: |
30+
${{ runner.os }}-pnpm-store-
31+
- run: pnpm install
32+
- run: pnpm build
33+
- uses: actions/upload-artifact@v4
34+
with:
35+
path: build
36+
name: build

.github/workflows/publish.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
on:
2+
workflow_dispatch:
3+
inputs:
4+
version:
5+
description: 'Version to publish'
6+
required: true
7+
verbose:
8+
description: 'Verbose mode'
9+
required: false
10+
default: 'false'
11+
12+
jobs:
13+
run-bpp:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Download artifact
17+
uses: dawidd6/action-download-artifact@v3
18+
with:
19+
workflow: build.yml
20+
workflow_conclusion: success
21+
branch: main
22+
event: push
23+
name: build
24+
path: build
25+
- name: Browser Platform Publish
26+
uses: PlasmoHQ/bpp@v3
27+
with:
28+
keys: ${{ secrets.SUBMIT_KEYS }}
29+
chrome-file: 'build/chrome-mv3-prod.zip'
30+
firefox-file: 'build/firefox-mv3-prod.zip'
31+
edge-file: 'build/edge-mv3-prod.zip'
32+
edge-notes: "Publishing latest extension version (${{ inputs.version }}) to the Edge Store."
33+
# opera-file: 'build/opera-mv3-prod.zip'
34+
verbose: ${{ inputs.verbose }}

.github/workflows/submit.yml

-34
This file was deleted.

.github/workflows/tests.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Unit tests
2+
on:
3+
pull_request:
4+
branches: [main]
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
with:
12+
submodules: recursive
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: '20'
16+
- uses: pnpm/action-setup@v4
17+
name: Install pnpm
18+
with:
19+
run_install: false
20+
- name: Get pnpm store directory
21+
shell: bash
22+
run: |
23+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
24+
- uses: actions/cache@v4
25+
name: Setup pnpm cache
26+
with:
27+
path: ${{ env.STORE_PATH }}
28+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
29+
restore-keys: |
30+
${{ runner.os }}-pnpm-store-
31+
- run: pnpm install
32+
- run: pnpm test:unit
33+
- run: pnpm build

README.md

+42-14
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
1-
# opentelemetry-browser-extension
1+
<div align="center">
2+
<p style="font-size:2rem">Open<span style="font-weight:bold">Telemetry</span> Browser Extension</p>
3+
<p>published builds available on:</p>
4+
<a href="https://chromewebstore.google.com/detail/opentelemetry-browser-ext/bgjeoaohfhbfabbfhbafjihbobjgniag"><img src='./assets/chrome.svg' height=50 alt='chrome download'></img></a>
5+
*
6+
<a href=""><img src='./assets/safari.svg' height=50 alt='safari download'></img></a>
7+
*
8+
<a href=""><img src='./assets/edge.svg' height=50 alt='edge download'></img></a>
9+
<p>...or <a href='#making-a-production-build'>build it yourself!</a></p>
10+
</div>
11+
12+
13+
## About
214

315
> [!NOTE]
4-
> This project is in very early development, and is likely to change abruptly *and* be broken. Forgive any missing documentation.
16+
> This project is in early development. Please forgive (or feel free to contribute) any missing documentation.
517
6-
A [Plasmo](https://docs.plasmo.com/) browser extension that automatically instruments webpages with [OpenTelemetry](https://opentelemetry.io/docs/what-is-opentelemetry/).
18+
A [Plasmo](https://docs.plasmo.com/)-based browser extension that automatically instruments webpages with [OpenTelemetry](https://opentelemetry.io/docs/what-is-opentelemetry/).
719

8-
[Download it](https://chromewebstore.google.com/detail/opentelemetry-browser-ext/bgjeoaohfhbfabbfhbafjihbobjgniag), refresh your pages, and start recording OTLP logs and traces in your browser.
20+
[Download it](https://chromewebstore.google.com/detail/opentelemetry-browser-ext/bgjeoaohfhbfabbfhbafjihbobjgniag), refresh your pages, and automatically start emitting OTLP logs and traces from webpages of your choosing.
921

1022
## Preview
1123

1224
<img src='./assets/store/popup.png' width='524' alt='An example view of the popup UI'/>
1325

14-
## Download
15-
16-
| Browser | Link |
17-
|-|-|
18-
|Chrome|[Download it from the Chrome web store](https://chromewebstore.google.com/detail/opentelemetry-browser-ext/bgjeoaohfhbfabbfhbafjihbobjgniag)|
19-
2026
## Features
2127

2228
* Automatically instrument your webpages to collect traces and logs, sent to an OTLP-compatible collector
2329
* No content-security policy errors! Works around typical CSP limitations by making `fetch` requests from the background script instead of the webpage
2430
* Propagate b3 and w3c trace context to websites of your choosing (matched by regular expressions)
2531

2632

27-
## Browser support
33+
## Browser compatibility
2834

29-
Currently, this extension has only been confirmed to work with compatible Chromium-based browsers (Chrome, Edge, etc) which support [manifest v3](https://developer.chrome.com/docs/extensions/develop/migrate/what-is-mv3) and `chrome.scripting.executeScript({ world: 'MAIN' })`.
35+
Because this extension relies on the use of `chrome.scripting.executeScript({ ... , world: 'MAIN' })`, it is only compatible with browsers which support the `MAIN` execution world as a parameter. Luckily, this seems to include every browser except Firefox ([where development to support the feature is in-progress](https://bugzilla.mozilla.org/show_bug.cgi?id=1736575)).
3036

31-
## Getting Started
37+
## Developing
3238

3339
Initialize submodules (we use a custom build of Plasmo):
3440

@@ -55,12 +61,34 @@ pnpm dev
5561

5662
Then, open your browser and load the appropriate development build. For example, if you're developing for Chrome, using manifest v3, use: `build/chrome-mv3-dev`.
5763

58-
## Making production build
64+
## Making a production build
5965

6066
Run the following:
6167

6268
```bash
6369
pnpm build
6470
```
71+
or, for targeting a specific browser:
72+
73+
```bash
74+
pnpm build:chrome
75+
# or
76+
pnpm build:safari
77+
# or
78+
pnpm build:edge
79+
```
6580

6681
Then, follow the same steps as with running the development server, but load the appropriate production build from the `build` directory, i.e: `build/chrome-mv3-prod`.
82+
83+
### Safari
84+
85+
Safari requires a bit of extra work. After building the extension, run the following command to convert the extension to a an XCode project:
86+
87+
```bash
88+
cd build && xcrun safari-web-extension-converter safari-mv3-prod
89+
```
90+
91+
Then, build the extension in XCode (using the MacOS target), and enable it in Safari
92+
93+
> [!NOTE]
94+
> Safari requires extensions to be signed before they can be installed. You can either sign the extension yourself, or load it as an unsigned extension after enabling "allow unsigned extensions" in Safari's developer settings.

assets/chrome.svg

+1
Loading

assets/edge.svg

+1
Loading

assets/safari.svg

+31
Loading

docker-compose.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
ports:
1010
- 7280:7280
1111
command: ["run"]
12-
# attach: false
12+
attach: false # comment this line if you'd like to view quickwit log output
1313

1414
otel-collector:
1515
image: otel/opentelemetry-collector:latest

package.json

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
{
22
"name": "opentelemetry-browser-extension",
33
"displayName": "OpenTelemetry Browser Extension",
4-
"version": "0.0.6",
4+
"version": "0.0.7",
55
"description": "An extension for instrumenting webpages using OpenTelemetry",
66
"author": "Theodore Brockman <iam@theo.lol>",
7+
"packageManager": "pnpm@8.14.0",
78
"scripts": {
89
"preinstall": "pnpm install:plasmo && pnpm build:run-p && pnpm build:vendored",
910
"install:plasmo": "pnpm -C ./vendored/plasmo/ install",
1011
"build:run-p": "pnpm -C ./vendored/plasmo/packages/rps build",
1112
"dev": "plasmo dev",
12-
"build": "pnpm build:vendored && plasmo build",
13+
"clean": "rm -fr build",
14+
"build": "npm-run-all build:safari build:windows",
15+
"build:windows": "npm-run-all build:chrome build:edge build:opera",
16+
"build:chrome": "plasmo build --target=chrome-mv3 --zip --hoist",
17+
"build:firefox": "echo '\\033[1;31mwarning: firefox build is not currently functional due to its incomplete scripting.executeScript() functionality.\nproceeding to build anyways\\033[0m\n' && plasmo build --target=firefox-mv3 --zip --hoist",
18+
"build:edge": "plasmo build --target=edge-mv3 --zip --hoist",
19+
"build:safari": "plasmo build --target=safari-mv3 --zip --hoist",
20+
"convert:safari": "cd build && xcrun safari-web-extension-converter safari-mv3-prod",
21+
"build:opera": "plasmo build --target=opera-mv3 --zip --hoist",
1322
"build:vendored": "run-p build:plasmo:cli build:plasmo:storage build:plasmo:messaging",
1423
"build:plasmo:cli": "pnpm -C ./vendored/plasmo build:cli",
1524
"build:plasmo:storage": "pnpm -C ./vendored/plasmo/api/storage build",
@@ -21,7 +30,7 @@
2130
"@mantine/core": "^7.6.1",
2231
"@mantine/hooks": "^7.6.1",
2332
"@opentelemetry/api-logs": "^0.49.1",
24-
"@opentelemetry/auto-instrumentations-web": "^0.37.0",
33+
"@opentelemetry/auto-instrumentations-web": "^0.36.0",
2534
"@opentelemetry/context-zone": "^1.22.0",
2635
"@opentelemetry/core": "^1.22.0",
2736
"@opentelemetry/exporter-logs-otlp-proto": "^0.49.1",
@@ -46,14 +55,15 @@
4655
"deepmerge-ts": "^5.1.0",
4756
"plasmo": "workspace:*",
4857
"react": "18.2.0",
49-
"react-dom": "18.2.0"
58+
"react-dom": "18.2.0",
59+
"uuidv7": "^1.0.0"
5060
},
5161
"devDependencies": {
5262
"@ianvs/prettier-plugin-sort-imports": "4.1.1",
5363
"@parcel/config-default": "^2.12.0",
5464
"@parcel/packager-ts": "2.12.0",
55-
"@plasmohq/rps": "workspace:*",
5665
"@plasmohq/parcel-config": "workspace:*",
66+
"@plasmohq/rps": "workspace:*",
5767
"@types/chrome": "0.0.262",
5868
"@types/jest": "^29.5.12",
5969
"@types/mocha": "^10.0.6",
@@ -65,6 +75,7 @@
6575
"esbuild-plugin-polyfill-node": "^0.3.0",
6676
"mocha": "^10.4.0",
6777
"mocha-suppress-logs": "^0.5.1",
78+
"npm-run-all": "^4.1.5",
6879
"parcel": "^2.12.0",
6980
"postcss": "^8.4.35",
7081
"postcss-preset-mantine": "^1.13.0",
@@ -85,13 +96,7 @@
8596
"permissions": [
8697
"scripting",
8798
"storage"
88-
],
89-
"externally_connectable": {
90-
"matches": [
91-
"https://*/*",
92-
"http://localhost/*"
93-
]
94-
}
99+
]
95100
},
96101
"overrides": {
97102
"@opentelemetry/instrumentation-xml-http-request": "0.49.1",
@@ -103,7 +108,8 @@
103108
"@protobufjs/inquire@1.1.0": "patches/@protobufjs__inquire@1.1.0.patch",
104109
"@opentelemetry/otlp-proto-exporter-base@0.49.1": "patches/@opentelemetry__otlp-proto-exporter-base@0.49.1.patch",
105110
"@opentelemetry/instrumentation-xml-http-request@0.49.1": "patches/@opentelemetry__instrumentation-xml-http-request@0.49.1.patch",
106-
"@opentelemetry/instrumentation-fetch@0.49.1": "patches/@opentelemetry__instrumentation-fetch@0.49.1.patch"
111+
"@opentelemetry/instrumentation-fetch@0.49.1": "patches/@opentelemetry__instrumentation-fetch@0.49.1.patch",
112+
"@opentelemetry/instrumentation-user-interaction@0.35.0": "patches/@opentelemetry__instrumentation-user-interaction@0.35.0.patch"
107113
}
108114
},
109115
"parcel-resolver-inlinefunc": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
diff --git a/build/esm/instrumentation.js b/build/esm/instrumentation.js
2+
index 928b559ffdafaea1832ec9b6a119656f8f091558..511a277175d888445b8e39e419027fc2f1a19158 100644
3+
--- a/build/esm/instrumentation.js
4+
+++ b/build/esm/instrumentation.js
5+
@@ -63,9 +63,14 @@ var UserInteractionInstrumentation = /** @class */ (function (_super) {
6+
typeof (config === null || config === void 0 ? void 0 : config.shouldPreventSpanCreation) === 'function'
7+
? config.shouldPreventSpanCreation
8+
: defaultShouldPreventSpanCreation;
9+
+ _this.init();
10+
return _this;
11+
}
12+
- UserInteractionInstrumentation.prototype.init = function () { };
13+
+ UserInteractionInstrumentation.prototype.init = function () {
14+
+ this._eventNames.forEach(event => {
15+
+ window.addEventListener(event, () => { });
16+
+ });
17+
+ };
18+
/**
19+
* This will check if last task was timeout and will save the time to
20+
* fix the user interaction when nothing happens

0 commit comments

Comments
 (0)