Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XHR instrumentation experimental package #239

Merged
merged 25 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a8a1f74
Initial commit of XHR instrumentation package
eskirk Jul 31, 2023
c480f9c
Capturing progress on testing out the XHR instrumentation
eskirk Jul 31, 2023
fe85096
Capturing progress - instrumenting XHR with event listeners, need par…
eskirk Aug 3, 2023
37103a5
Capturing more progress, adding some TODOs
eskirk Aug 4, 2023
00f3888
One last commit
eskirk Aug 4, 2023
b7cf74a
Fixing find + replace issue in jest config
eskirk Aug 4, 2023
4b9b70b
Fixing lint issue in readme
eskirk Aug 4, 2023
3b1bb74
Removing OTel tracing of fetch and XHR from demo app, replacing with …
eskirk Aug 4, 2023
a0abf02
Capturing more progress - event listeners are instrumented - needs te…
eskirk Aug 5, 2023
2131914
Small change, adding todo
eskirk Aug 5, 2023
20e78dd
Merge branch 'main' of https://github.com/grafana/faro-web-sdk into e…
eskirk Sep 13, 2023
06b7bf2
Leftover merge conflict
eskirk Sep 13, 2023
0335e57
Couple touch ups, addressing some feedback
eskirk Sep 13, 2023
fe5335a
Simplifying code and addressing more comments
eskirk Sep 13, 2023
8ff6620
Adding more testing to XHR instrumentation
eskirk Sep 13, 2023
cbc525b
Pleasing the linter
eskirk Sep 13, 2023
bd96c9e
Markdown linting
eskirk Sep 13, 2023
7a7cce3
More linting fixes lol
eskirk Sep 13, 2023
f5a90bd
Cleaning up package json and yarn lock things
eskirk Sep 13, 2023
b120400
Final lint for real
eskirk Sep 13, 2023
794a5a4
Bumping version, remove XHR instrumentation from demo deps
eskirk Sep 13, 2023
dbb5dd9
Addressing Marco's suggestions
eskirk Sep 14, 2023
fb1dccd
Addressing more Marco feedback
eskirk Sep 14, 2023
18605fc
Remove clashing instrumentations?
eskirk Sep 14, 2023
b0ee498
Adding more details to readme
eskirk Sep 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ DEMO_PACKAGES_REACT_PATH=packages/react
DEMO_PACKAGES_WEB_SDK_PATH=packages/web-sdk
DEMO_PACKAGES_WEB_TRACING_PATH=packages/web-tracing
DEMO_PACKAGES_FETCH_INSTRUMENTATION_PATH=experimental/instrumentation-fetch
DEMO_PACKAGES_XHR_INSTRUMENTATION_PATH=experimental/instrumentation-xhr
DEMO_PORT=5173
DEMO_PORT_HMR=24678
DEMO_SERVER_AGENT_HOST=
Expand Down
1 change: 1 addition & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@grafana/faro-react": "^1.1.2",
"@grafana/faro-web-sdk": "^1.1.2",
"@grafana/faro-web-tracing": "^1.1.2",
"@grafana/faro-instrumentation-xhr": "link:../experimental/instrumentation-xhr", // TODO - remove this once we publish instrumentation-xhr
"@grpc/grpc-js": "^1.8.17",
"@opentelemetry/api": "^1.4.1",
"@opentelemetry/core": "^1.11.0",
Expand Down
2 changes: 2 additions & 0 deletions demo/src/client/faro/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createRoutesFromChildren, matchRoutes, Routes, useLocation, useNavigationType } from 'react-router-dom';

import { XHRInstrumentation } from '@grafana/faro-instrumentation-xhr';
import {
initializeFaro as coreInit,
getWebInstrumentations,
Expand All @@ -20,6 +21,7 @@ export function initializeFaro(): Faro {
captureConsole: true,
}),
new TracingInstrumentation(),
new XHRInstrumentation(),
new ReactIntegration({
router: {
version: ReactRouterVersion.V6,
Expand Down
3 changes: 2 additions & 1 deletion demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
{ "path": "../packages/react/tsconfig.esm.json" },
{ "path": "../packages/web-sdk/tsconfig.esm.json" },
{ "path": "../packages/web-tracing/tsconfig.esm.json" },
{ "path": "../experimental/instrumentation-fetch/tsconfig.esm.json" }
{ "path": "../experimental/instrumentation-fetch/tsconfig.esm.json" },
{ "path": "../experimental/instrumentation-xhr/tsconfig.esm.json" }
]
}
5 changes: 5 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ services:
- 'demo_web_tracing_node_modules:${DEMO_WORKSPACE_PATH}/${DEMO_PACKAGES_WEB_TRACING_PATH}/node_modules'
- 'demo_fetch_instrumentation_dist:${DEMO_WORKSPACE_PATH}/${DEMO_PACKAGES_FETCH_INSTRUMENTATION_PATH}/dist'
- 'demo_fetch_instrumentation_node_modules:${DEMO_WORKSPACE_PATH}/${DEMO_PACKAGES_FETCH_INSTRUMENTATION_PATH}/node_modules'
- 'demo_xhr_instrumentation_dist:${DEMO_WORKSPACE_PATH}/${DEMO_PACKAGES_XHR_INSTRUMENTATION_PATH}/dist'
- 'demo_xhr_instrumentation_node_modules:${DEMO_WORKSPACE_PATH}/${DEMO_PACKAGES_XHR_INSTRUMENTATION_PATH}/node_modules'
build:
context: '.'
args:
Expand All @@ -121,6 +123,7 @@ services:
DEMO_PACKAGES_WEB_SDK_PATH: '${DEMO_PACKAGES_WEB_SDK_PATH}'
DEMO_PACKAGES_WEB_TRACING_PATH: '${DEMO_PACKAGES_WEB_TRACING_PATH}'
DEMO_PACKAGES_FETCH_INSTRUMENTATION_PATH: '${DEMO_PACKAGES_FETCH_INSTRUMENTATION_PATH}'
DEMO_PACKAGES_XHR_INSTRUMENTATION_PATH: '${DEMO_PACKAGES_XHR_INSTRUMENTATION_PATH}'
DEMO_PORT: '${DEMO_PORT}'
DEMO_PORT_HMR: '${DEMO_PORT_HMR}'
ports:
Expand Down Expand Up @@ -152,3 +155,5 @@ volumes:
demo_web_tracing_node_modules:
demo_fetch_instrumentation_dist:
demo_fetch_instrumentation_node_modules:
demo_xhr_instrumentation_dist:
demo_xhr_instrumentation_node_modules:
1 change: 1 addition & 0 deletions experimental/instrumentation-xhr/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
supports es6-module
29 changes: 29 additions & 0 deletions experimental/instrumentation-xhr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# @grafana/instrumentation-xhr

Faro instrumentation of the JavaScript [XMLHttpRequest (XHR)](https://developer.mozilla.org/en-US/docs/Glossary/XMLHttpRequest) API

❗️*Warning*: this package is experimental and may be subject to frequent and breaking changes.
Use at your own risk.❗️

## Installation and Usage

```ts
// index.ts
import { XHRInstrumentation } from '@grafana/faro-instrumentation-xhr';
import { getWebInstrumentations, initializeFaro } from '@grafana/faro-react';

initializeFaro({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: explain the availbale options too.

// ...
instrumentations: [
// Load the default Web instrumentations
...getWebInstrumentations(),
// Add XHR instrumentation
new XHRInstrumentation(),
],
});

// myApi.ts
const req = new XMLHttpRequest();
req.open("GET", "...");
req.send(); // use XHR as normal - telemetry data is sent to your Faro endpoint
```
16 changes: 16 additions & 0 deletions experimental/instrumentation-xhr/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { jestBaseConfig } = require('../../jest.config.base.js');

module.exports = {
...jestBaseConfig,
roots: ['experimental/instrumentation-xhr/src'],
testEnvironment: 'jsdom',
setupFiles: ['<rootDir>/experimental/instrumentation-xhr/src/setupTests.ts'],
moduleNameMapper: {
'^@remix-run/router$': '<rootDir>/index.ts',
'^@remix-run/web-blob$': require.resolve('@remix-run/web-blob'),
'^@remix-run/web-xhr$': require.resolve('@remix-run/web-xhr'),
'^@remix-run/web-form-data$': require.resolve('@remix-run/web-form-data'),
'^@remix-run/web-stream$': require.resolve('@remix-run/web-stream'),
'^@web3-storage/multipart-parser$': require.resolve('@web3-storage/multipart-parser'),
},
};
47 changes: 47 additions & 0 deletions experimental/instrumentation-xhr/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@grafana/faro-instrumentation-xhr",
"version": "1.0.0",
eskirk marked this conversation as resolved.
Show resolved Hide resolved
"description": "Faro XHR auto-instrumentation package",
"keywords": [
"observability",
"apm",
"rum",
"logs",
"traces",
"metrics",
"XMLHttpRequest",
"xhr"
],
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"scripts": {
"test": "jest",
"start": "yarn watch",
"build": "run-s build:*",
"build:compile": "run-p build:compile:*",
"build:compile:cjs": "tsc --build tsconfig.cjs.json",
"build:compile:esm": "tsc --build tsconfig.esm.json",
"build:compile:bundle": "run-s build:compile:bundle:*",
"build:compile:bundle:create": "rollup -c ./rollup.config.js",
"build:compile:bundle:remove-extras": "rimraf dist/bundle/dist",
"watch": "run-s watch:compile",
"watch:compile": "yarn build:compile:cjs -w",
"clean": "rimraf dist/ yarn-error.log",
"quality": "run-s quality:*",
"quality:test": "jest",
"quality:format": "prettier --cache --cache-location=../../.cache/prettier/instrumentationXHR --ignore-path ../../.prettierignore -w \"./**/*.{js,jsx,ts,tsx,css,scss,md,yaml,yml,json}\"",
"quality:lint": "run-s quality:lint:*",
"quality:lint:eslint": "eslint --cache --cache-location ../../.cache/eslint/instrumentationXHR --ignore-path ../../.eslintignore \"./**/*.{js,jsx,ts,tsx}\"",
"quality:lint:prettier": "prettier --cache --cache-location=../../.cache/prettier/instrumentationXHR --ignore-path ../../.prettierignore -c \"./**/*.{js,jsx,ts,tsx,css,scss,md,yaml,yml,json}\"",
"quality:lint:md": "markdownlint README.md",
"quality:circular-deps": "madge --circular ."
},
"repository": {
"type": "git",
"url": "git+https://github.com/grafana/faro-web-sdk.git",
"directory": "experimental/instrumentation-xhr"
},
"author": "Grafana Labs",
"license": "Apache-2.0"
}
3 changes: 3 additions & 0 deletions experimental/instrumentation-xhr/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { getRollupConfigBase } = require('../../rollup.config.base.js');

module.exports = getRollupConfigBase('instrumentationXHR');
1 change: 1 addition & 0 deletions experimental/instrumentation-xhr/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { XHRInstrumentation } from './instrumentation';
10 changes: 10 additions & 0 deletions experimental/instrumentation-xhr/src/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { BaseInstrumentation, VERSION } from '@grafana/faro-core';

export class XHRInstrumentation extends BaseInstrumentation {
readonly name = '@grafana/faro-web-sdk:instrumentation-xhr';
readonly version = VERSION;

initialize(): void {
console.log('Initializing XHR instrumentation')
}
}
12 changes: 12 additions & 0 deletions experimental/instrumentation-xhr/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.base.cjs.json",
"compilerOptions": {
"declarationDir": "./dist/types",
"outDir": "./dist/cjs",
"rootDir": "./src",
"tsBuildInfoFile": "../../.cache/tsc/instrumentationXHR.cjs.tsbuildinfo"
},
"include": ["./src"],
"exclude": ["**/*.test.ts"],
"references": [{ "path": "../../packages/core/tsconfig.spec.json" }]
}
12 changes: 12 additions & 0 deletions experimental/instrumentation-xhr/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.base.esm.json",
"compilerOptions": {
"declarationDir": "./dist/types",
"outDir": "./dist/esm",
"rootDir": "./src",
"tsBuildInfoFile": "../../.cache/tsc/instrumentationXHR.esm.tsbuildinfo"
},
"include": ["./src"],
"exclude": ["**/*.test.ts"],
"references": [{ "path": "../../packages/core/tsconfig.spec.json" }]
}
10 changes: 10 additions & 0 deletions experimental/instrumentation-xhr/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"noPropertyAccessFromIndexSignature": false
eskirk marked this conversation as resolved.
Show resolved Hide resolved
},
"references": [
{ "path": "./tsconfig.cjs.json" },
{ "path": "./tsconfig.esm.json" },
{ "path": "./tsconfig.spec.json" }
]
}
11 changes: 11 additions & 0 deletions experimental/instrumentation-xhr/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.base.spec.json",
"compilerOptions": {
"declarationDir": "./dist/types",
"outDir": "./dist/spec",
"rootDir": "../../",
"tsBuildInfoFile": "../../.cache/tsc/instrumentationXHR.spec.tsbuildinfo"
},
"include": ["./src"],
"references": [{ "path": "../../packages/core/tsconfig.spec.json" }]
}
6 changes: 6 additions & 0 deletions rollup.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ const modules = {
globalName: 'GrafanaFaroInstrumentationFetch',
externals: [],
},
instrumentationXHR: {
name: '@grafana/faro-instrumentation-xhr',
bundleName: 'faro-instrumentation-xhr',
globalName: 'GrafanaFaroInstrumentationXHR',
externals: [],
},
};

exports.getRollupConfigBase = (moduleName) => {
Expand Down
3 changes: 3 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@
eslint-plugin-react-hooks "4.6.0"
typescript "4.8.4"

"@grafana/faro-instrumentation-xhr@link:experimental/instrumentation-xhr":
version "1.0.0"

"@grpc/grpc-js@^1.7.1", "@grpc/grpc-js@^1.8.17":
version "1.8.17"
resolved "https://registry.yarnpkg.com/@grpc/grpc-js/-/grpc-js-1.8.17.tgz#a3a2f826fc033eae7d2f5ee41e0ab39cee948838"
Expand Down