├── .ci ├── bump-elastic-stack.yml ├── docker │ ├── node-playwright │ │ └── Dockerfile │ └── node-puppeteer │ │ ├── Dockerfile │ │ └── run-test.sh └── scripts │ ├── bench.sh │ ├── benchmarks.sh │ ├── index.html.template │ ├── lint.sh │ ├── load-testing.sh │ ├── pull_and_build.sh │ └── test.sh ├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .github ├── dependabot.yml ├── stale.yml └── workflows │ ├── README.md │ ├── bump-elastic-stack.yml │ ├── ci-docs.yml │ ├── ci-saucelabs.yml │ ├── ci.yml │ ├── docs-build.yml │ ├── docs-cleanup.yml │ ├── microbenchmark.yml │ ├── pre-release.yml │ ├── release.yml │ ├── run-test │ └── action.yml │ └── test-reporter.yml ├── .gitignore ├── .npmrc ├── .nvmrc ├── .prettierrc.json ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── RELEASE.md ├── codecov.yml ├── dev-utils ├── .node-version ├── build.js ├── dep-info.js ├── docker-compose.yml ├── elasticsearch │ ├── roles.yml │ ├── service_tokens │ ├── users │ └── users_roles ├── integration-test.js ├── jasmine.js ├── karma.js ├── kibana │ └── kibana.yml ├── object-configurable.js ├── run-script.js ├── test-config.js ├── test-servers.js ├── test-utils.js └── webdriver.js ├── docs ├── docset.yml ├── reference │ ├── advanced-topics.md │ ├── agent-api.md │ ├── angular-integration.md │ ├── api-reference.md │ ├── breakdown-metrics.md │ ├── configuration.md │ ├── configuring-cors.md │ ├── custom-transaction-name.md │ ├── custom-transactions.md │ ├── distributed-tracing.md │ ├── framework-specific-integrations.md │ ├── images │ │ └── compatibility.png │ ├── index.md │ ├── install-agent.md │ ├── longtasks.md │ ├── opentracing.md │ ├── performance-tuning.md │ ├── react-integration.md │ ├── set-up-apm-real-user-monitoring-javascript-agent.md │ ├── source-maps.md │ ├── span-api.md │ ├── supported-technologies.md │ ├── toc.yml │ ├── transaction-api.md │ ├── typescript.md │ ├── upgrading.md │ └── vue-integration.md └── release-notes │ ├── breaking-changes.md │ ├── index.md │ ├── known-issues.md │ └── toc.yml ├── lerna.json ├── package-lock.json ├── package.json ├── packages ├── rum-angular │ ├── CHANGELOG.md │ ├── NOTICE.txt │ ├── README.md │ ├── angular.json │ ├── karma.conf.js │ ├── ng-package.json │ ├── package.json │ ├── src │ │ ├── apm.module.ts │ │ ├── apm.service.ts │ │ ├── error-handler.ts │ │ └── index.ts │ ├── test │ │ ├── e2e │ │ │ └── with-router │ │ │ │ ├── app.e2e-spec.js │ │ │ │ ├── app │ │ │ │ ├── app-routing.module.ts │ │ │ │ ├── app.component.ts │ │ │ │ ├── app.module.ts │ │ │ │ ├── contact-detail.component.ts │ │ │ │ ├── contact-list.component.ts │ │ │ │ ├── contact.service.ts │ │ │ │ ├── home.component.ts │ │ │ │ └── not-found.component.ts │ │ │ │ ├── assets │ │ │ │ └── data.json │ │ │ │ ├── environments │ │ │ │ ├── environment.prod.ts │ │ │ │ └── environment.ts │ │ │ │ ├── index.html │ │ │ │ ├── main.ts │ │ │ │ ├── polyfills.ts │ │ │ │ └── tsconfig.app.json │ │ ├── index.ts │ │ └── specs │ │ │ ├── apm.service.spec.ts │ │ │ ├── error-handler.spec.ts │ │ │ └── index.ts │ ├── tsconfig.json │ ├── tsconfig.lib.json │ ├── tsconfig.lib.prod.json │ ├── tsconfig.spec.json │ └── wdio.conf.js ├── rum-core │ ├── CHANGELOG.md │ ├── NOTICE.txt │ ├── README.md │ ├── babel.config.js │ ├── karma.bench.conf.js │ ├── karma.conf.js │ ├── package.json │ ├── src │ │ ├── bootstrap.js │ │ ├── common │ │ │ ├── after-frame.js │ │ │ ├── apm-server.js │ │ │ ├── compress.js │ │ │ ├── config-service.js │ │ │ ├── constants.js │ │ │ ├── context.js │ │ │ ├── event-handler.js │ │ │ ├── http │ │ │ │ ├── fetch.js │ │ │ │ ├── response-status.js │ │ │ │ └── xhr.js │ │ │ ├── instrument.js │ │ │ ├── logging-service.js │ │ │ ├── ndjson.js │ │ │ ├── observers │ │ │ │ ├── index.js │ │ │ │ ├── page-clicks.js │ │ │ │ └── page-visibility.js │ │ │ ├── patching │ │ │ │ ├── fetch-patch.js │ │ │ │ ├── history-patch.js │ │ │ │ ├── index.js │ │ │ │ ├── patch-utils.js │ │ │ │ └── xhr-patch.js │ │ │ ├── polyfills.js │ │ │ ├── queue.js │ │ │ ├── service-factory.js │ │ │ ├── throttle.js │ │ │ ├── truncate.js │ │ │ ├── url.js │ │ │ └── utils.js │ │ ├── error-logging │ │ │ ├── error-logging.js │ │ │ ├── index.js │ │ │ └── stack-trace.js │ │ ├── index.js │ │ ├── opentracing │ │ │ ├── index.js │ │ │ ├── span.js │ │ │ └── tracer.js │ │ ├── performance-monitoring │ │ │ ├── breakdown.js │ │ │ ├── index.js │ │ │ ├── metrics │ │ │ │ ├── inp │ │ │ │ │ ├── process.js │ │ │ │ │ └── report.js │ │ │ │ └── metrics.js │ │ │ ├── navigation │ │ │ │ ├── capture-navigation.js │ │ │ │ ├── marks.js │ │ │ │ ├── navigation-timing.js │ │ │ │ ├── resource-timing.js │ │ │ │ ├── user-timing.js │ │ │ │ └── utils.js │ │ │ ├── performance-monitoring.js │ │ │ ├── span-base.js │ │ │ ├── span.js │ │ │ ├── transaction-service.js │ │ │ └── transaction.js │ │ └── state.js │ └── test │ │ ├── benchmarks │ │ ├── breakdown.bench.js │ │ ├── capture-navigation.bench.js │ │ ├── compress.bench.js │ │ ├── index.js │ │ ├── performance-monitoring.bench.js │ │ └── transaction-service.bench.js │ │ ├── bootstrap.spec.js │ │ ├── common │ │ ├── after-frame.spec.js │ │ ├── apm-server.spec.js │ │ ├── compress.spec.js │ │ ├── config-service.spec.js │ │ ├── context.spec.js │ │ ├── event-handler.spec.js │ │ ├── fetch-patch.spec.js │ │ ├── history-patch.spec.js │ │ ├── http │ │ │ ├── fetch.spec.js │ │ │ └── response-status.spec.js │ │ ├── instrument.spec.js │ │ ├── logging-service.spec.js │ │ ├── ndjson.spec.js │ │ ├── observers │ │ │ ├── page-clicks.spec.js │ │ │ └── page-visibility.spec.js │ │ ├── patch.js │ │ ├── queue.spec.js │ │ ├── service-factory.spec.js │ │ ├── throttle.spec.js │ │ ├── truncate.spec.js │ │ ├── url.spec.js │ │ ├── utils.spec.js │ │ └── xhr-patch.spec.js │ │ ├── error-logging │ │ ├── error-logging.spec.js │ │ └── stack-trace.spec.js │ │ ├── fixtures │ │ ├── fid-entries.js │ │ ├── lcp-entries.js │ │ ├── longtask-entries.js │ │ ├── navigation-entries.js │ │ ├── navigation-timing-span-snapshot.js │ │ ├── paint-entries.js │ │ ├── resource-entries.js │ │ └── user-timing-entries.js │ │ ├── index.js │ │ ├── mock-apm-server.js │ │ ├── opentracing │ │ ├── api_compatibility.js │ │ └── opentracing.spec.js │ │ ├── performance-monitoring │ │ ├── breakdown.spec.js │ │ ├── capture-navigation.spec.js │ │ ├── metrics │ │ │ ├── inp │ │ │ │ ├── process.spec.js │ │ │ │ └── report.spec.js │ │ │ └── metrics.spec.js │ │ ├── performance-monitoring.spec.js │ │ ├── span-base.spec.js │ │ ├── span.spec.js │ │ ├── transaction-service.spec.js │ │ └── transaction.spec.js │ │ ├── polyfills.js │ │ ├── run-apm-server.sh │ │ └── utils │ │ ├── apm-server-mock.js │ │ ├── globals-mock.js │ │ └── transportMock.js ├── rum-react │ ├── CHANGELOG.md │ ├── NOTICE.txt │ ├── README.md │ ├── babel.config.js │ ├── karma.conf.js │ ├── package.json │ ├── src │ │ ├── finish-transaction-effect.js │ │ ├── get-apm-routes.js │ │ ├── get-with-transaction.js │ │ └── index.js │ ├── test │ │ ├── e2e │ │ │ ├── components │ │ │ │ ├── func-component.js │ │ │ │ ├── lazy-component.js │ │ │ │ ├── main-component.js │ │ │ │ ├── manual-component.js │ │ │ │ └── topic-component.js │ │ │ ├── data.json │ │ │ ├── index.js │ │ │ └── with-router │ │ │ │ ├── general.e2e-spec.js │ │ │ │ ├── general.js │ │ │ │ ├── index.html │ │ │ │ ├── routes.e2e-spec.js │ │ │ │ ├── routes.html │ │ │ │ ├── routes.js │ │ │ │ └── webpack.config.js │ │ ├── polyfills.js │ │ └── specs │ │ │ ├── get-apm-routes.spec.js │ │ │ └── get-with-transaction.spec.js │ └── wdio.conf.js ├── rum-vue │ ├── CHANGELOG.md │ ├── NOTICE.txt │ ├── README.md │ ├── babel.config.js │ ├── karma.conf.js │ ├── package.json │ ├── src │ │ ├── error-handler.js │ │ ├── index.js │ │ └── route-hooks.js │ ├── test │ │ ├── e2e │ │ │ ├── App.vue │ │ │ ├── app.e2e-spec.js │ │ │ ├── app.js │ │ │ ├── components │ │ │ │ ├── Fetch.vue │ │ │ │ ├── Lazy.vue │ │ │ │ └── Syntax.vue │ │ │ ├── data.json │ │ │ ├── index.html │ │ │ ├── index.js │ │ │ └── webpack.config.js │ │ ├── polyfills.js │ │ └── specs │ │ │ ├── error-handler.spec.js │ │ │ └── index.spec.js │ └── wdio.conf.js └── rum │ ├── CHANGELOG.md │ ├── NOTICE.txt │ ├── README.md │ ├── babel.config.js │ ├── karma.conf.js │ ├── package.json │ ├── src │ ├── apm-base.js │ ├── index.d.ts │ ├── index.js │ └── opentracing.js │ ├── test │ ├── benchmarks │ │ ├── BENCHMARKS.md │ │ ├── analyzer.js │ │ ├── config.js │ │ ├── pages │ │ │ ├── basic.ejs │ │ │ ├── head.ejs │ │ │ ├── heavy.ejs │ │ │ └── init.ejs │ │ ├── profiler.js │ │ ├── run.js │ │ └── server.js │ ├── bundle │ │ └── bundle.spec.js │ ├── e2e │ │ ├── async-tests │ │ │ ├── app.js │ │ │ ├── async.e2e-spec.js │ │ │ ├── index.ejs │ │ │ └── webpack.config.js │ │ ├── bundle-test │ │ │ └── index.html │ │ ├── common │ │ │ └── data.json │ │ ├── general-usecase │ │ │ ├── app.e2e-spec.js │ │ │ ├── app.js │ │ │ ├── index.html │ │ │ └── webpack.config.js │ │ ├── index.js │ │ ├── logs-to-dom.js │ │ ├── manual-timing │ │ │ ├── app.e2e-spec.js │ │ │ ├── app.js │ │ │ ├── index.html │ │ │ └── webpack.config.js │ │ ├── standalone-html │ │ │ ├── app.e2e-failsafe.js │ │ │ ├── app.e2e-spec.js │ │ │ ├── base.js │ │ │ ├── index.html │ │ │ ├── opentracing.html │ │ │ ├── opentracing.js │ │ │ └── webpack.config.js │ │ └── utils.js │ ├── integration │ │ ├── babel.helper.js │ │ ├── index.spec.js │ │ ├── integration-test.spec.js │ │ └── upload-sourcemaps.spec.js │ ├── node │ │ ├── index-export.spec.js │ │ └── opentracing-export.spec.js │ ├── run-apm-server.sh │ ├── specs │ │ ├── apm-base.spec.js │ │ └── index.spec.js │ └── types │ │ ├── index.spec.ts │ │ └── tsconfig.json │ ├── wdio-failsafe.conf.js │ ├── wdio.conf.js │ └── webpack.config.js └── scripts ├── apm-server-load-test.js ├── benchmarks.js ├── build_docs.sh ├── ci-bundlesize.sh ├── ci-post-release.mjs ├── ci-pre-release.mjs ├── ci-prepare-release.js ├── ci-release.mjs ├── eslint-rules ├── require-license-header.js └── version-checker.js ├── github-release.js ├── license-checker.js ├── lint-commits.sh ├── prompt-release.js └── publish-package.js /.ci/bump-elastic-stack.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bump elastic stack to latest version 3 | 4 | actions: 5 | default: 6 | title: '[updatecli] Bump elastic stack version to {{ source "latestRelease" }}' 7 | kind: github/pullrequest 8 | spec: 9 | labels: 10 | - dependencies 11 | scmid: default 12 | 13 | scms: 14 | default: 15 | kind: github 16 | spec: 17 | user: '{{ requiredEnv "GITHUB_ACTOR" }}' 18 | owner: elastic 19 | repository: apm-agent-rum-js 20 | token: '{{ requiredEnv "GITHUB_TOKEN" }}' 21 | username: '{{ requiredEnv "GITHUB_ACTOR" }}' 22 | branch: main 23 | commitusingapi: true 24 | 25 | sources: 26 | latestRelease: 27 | name: Get Latest Elastic Release 28 | kind: githubrelease 29 | transformers: 30 | - trimprefix: v 31 | spec: 32 | owner: elastic 33 | repository: elasticsearch 34 | token: '{{ requiredEnv "GITHUB_TOKEN" }}' 35 | username: '{{ requiredEnv "GITHUB_ACTOR" }}' 36 | versionfilter: 37 | kind: regex 38 | pattern: ^v8\.(\d+)\.(\d+)$ 39 | 40 | conditions: 41 | dockerTag: 42 | name: Is docker image elasticsearch:{{ source "latestRelease" }} published 43 | kind: dockerimage 44 | spec: 45 | image: elasticsearch 46 | tag: '{{ source "latestRelease" }}' 47 | sourceid: latestRelease 48 | 49 | targets: 50 | 51 | update-ci-workflow: 52 | name: 'Update elastic stack version to {{ source "latestRelease" }}' 53 | sourceid: latestRelease 54 | scmid: default 55 | kind: file 56 | spec: 57 | file: .github/workflows/ci.yml 58 | content: >- 59 | '{{ source `latestRelease` }}' 60 | matchpattern: \'[0-9]+\.[0-9]+\.[0-9]+\' 61 | 62 | update-microbenchmark-workflow: 63 | name: 'Update elastic stack version to {{ source "latestRelease" }}' 64 | sourceid: latestRelease 65 | scmid: default 66 | kind: file 67 | spec: 68 | file: .github/workflows/microbenchmark.yml 69 | content: >- 70 | '{{ source `latestRelease` }}' 71 | matchpattern: \'[0-9]+\.[0-9]+\.[0-9]+\' 72 | -------------------------------------------------------------------------------- /.ci/docker/node-puppeteer/run-test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cat <Environment Vars 5 | 6 | USER=$(id) 7 | GOAL=${GOAL} 8 | MODE=${MODE} 9 | SCOPE=${SCOPE} 10 | STACK_VERSION=${STACK_VERSION} 11 | NODE_VERSION=${NODE_VERSION} 12 | YARN_VERSION=${YARN_VERSION} 13 | 14 | >Installed tools 15 | 16 | NODE=$(node --version) 17 | NPM=$(npm --version) 18 | NPX=$(npx --version) 19 | EOF 20 | 21 | cd /app 22 | npm install 23 | npm install puppeteer --unsafe-perm=true --allow-root 24 | set -eo pipefail 25 | npm run ${GOAL} 26 | -------------------------------------------------------------------------------- /.ci/scripts/benchmarks.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | USER_ID="$(id -u):$(id -g)" 4 | # The migration of this to Node.js 18 will wait. To update playwright (and browsers) 5 | # to make it work in Node.js 18 and latest version in ubuntu (or another OS) 6 | # will require us to invest a certain amount of time 7 | NODEJS_VERSION=14 8 | 9 | USER_ID="${USER_ID}" \ 10 | NODEJS_VERSION="${NODEJS_VERSION}" \ 11 | docker-compose -f ./dev-utils/docker-compose.yml down \ 12 | --remove-orphans \ 13 | --volumes || true 14 | 15 | USER_ID="${USER_ID}" \ 16 | NODEJS_VERSION="${NODEJS_VERSION}" \ 17 | docker-compose -f ./dev-utils/docker-compose.yml up \ 18 | --build \ 19 | --abort-on-container-exit \ 20 | --exit-code-from node-benchmark \ 21 | --remove-orphans \ 22 | node-benchmark 23 | -------------------------------------------------------------------------------- /.ci/scripts/index.html.template: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Real User Monitoring - Elastic 5 | 6 | 7 | VERSION 8 |
9 |
10 | For further details see this guide. 11 | 12 | 13 | -------------------------------------------------------------------------------- /.ci/scripts/lint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | npm install 3 | npm run lint 4 | scripts/lint-commits.sh 5 | -------------------------------------------------------------------------------- /.ci/scripts/load-testing.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | STACK_VERSION=${1:-8.6.1} 4 | USER_ID="$(id -u):$(id -g)" 5 | # The migration of this to Node.js 18 will wait. To update playwright (and browsers) 6 | # to make it work in Node.js 18 and latest version in ubuntu (or another OS) 7 | # will require us to invest a certain amount of time 8 | NODEJS_VERSION=14 9 | 10 | USER_ID="${USER_ID}" \ 11 | NODEJS_VERSION="${NODEJS_VERSION}" \ 12 | STACK_VERSION=${STACK_VERSION} \ 13 | docker-compose -f ./dev-utils/docker-compose.yml down \ 14 | --remove-orphans \ 15 | --volumes || true 16 | 17 | USER_ID="${USER_ID}" \ 18 | NODEJS_VERSION="${NODEJS_VERSION}" \ 19 | STACK_VERSION=${STACK_VERSION} \ 20 | docker-compose -f ./dev-utils/docker-compose.yml up \ 21 | --build \ 22 | --exit-code-from load-testing \ 23 | load-testing 24 | -------------------------------------------------------------------------------- /.ci/scripts/pull_and_build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | export NODEJS_VERSION=$(cat .nvmrc) 3 | export STACK_VERSION=${STACK_VERSION:-8.6.1} 4 | 5 | STACK_VERSION=${STACK_VERSION} \ 6 | docker --log-level INFO compose -f ./dev-utils/docker-compose.yml pull --quiet --ignore-pull-failures 7 | 8 | # We are building the images here even though the Docker images are already cached in Packer. 9 | # This is because there could be changes in the PR affecting the files copied to the Docker image, 10 | # which we want to test in the current build. 11 | NODEJS_VERSION="${NODEJS_VERSION}" \ 12 | STACK_VERSION=${STACK_VERSION} \ 13 | docker --log-level INFO compose -f ./dev-utils/docker-compose.yml build >docker-compose.log 2>docker-compose.err 14 | if [ $? -gt 0 ] ; then 15 | echo "Docker compose failed, see the below log output" 16 | cat docker-compose.log && rm docker-compose.log 17 | cat docker-compose.err && rm docker-compose.err 18 | exit 1 19 | else 20 | rm docker-compose.log docker-compose.err 21 | fi 22 | -------------------------------------------------------------------------------- /.ci/scripts/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -xo pipefail 3 | 4 | STACK_VERSION=${STACK_VERSION:-"8.6.1"} 5 | APM_SERVER_PORT=${APM_SERVER_PORT:-"8200"} 6 | APM_SERVER_URL=${APM_SERVER_URL:-"http://apm-server:8200"} 7 | KIBANA_URL=${KIBANA_URL:-"http://kibana:5601"} 8 | 9 | # As long as there are issues with the ssl lets use 6.1.3 10 | # see https://github.com/docker/docker-py/issues/3194 11 | pip3 uninstall docker 12 | pip3 install docker==6.1.3 13 | 14 | pip install docker-compose>=1.25.4 15 | 16 | # https://github.com/docker/docker-py/issues/3256 17 | pip3 uninstall requests 18 | pip3 install requests==2.31.0 19 | 20 | 21 | # Tests are run within the node-puppeteer container and can fails. 22 | # To avoid flakiness, we retry up to 3 times to run them. 23 | for i in {1..3}; 24 | do 25 | USER_ID="$(id -u):$(id -g)" \ 26 | NODEJS_VERSION=$(cat .nvmrc) \ 27 | STACK_VERSION=${STACK_VERSION} \ 28 | APM_SERVER_PORT=${APM_SERVER_PORT} \ 29 | APM_SERVER_URL=${APM_SERVER_URL} \ 30 | KIBANA_URL=${KIBANA_URL} \ 31 | docker --log-level INFO compose \ 32 | -f ./dev-utils/docker-compose.yml \ 33 | up \ 34 | --quiet-pull \ 35 | --exit-code-from node-puppeteer \ 36 | --remove-orphans \ 37 | node-puppeteer; 38 | status=${?} 39 | if [ "${status}" -eq "0" ]; then 40 | break 41 | fi 42 | sleep 5; 43 | done 44 | echo "Exit code from docker compose ${status}" 45 | exit ${status} 46 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.{md,asciidoc}] 13 | trim_trailing_whitespace = false 14 | insert_final_newline = false 15 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | build 2 | docs 3 | coverage 4 | dist 5 | *.e2e-bundle.* 6 | tmp 7 | *.min.js 8 | *.bundle.* 9 | node_modules -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | 4 | # GitHub actions 5 | - package-ecosystem: "github-actions" 6 | directory: "/" 7 | reviewers: 8 | - "elastic/observablt-ci" 9 | schedule: 10 | interval: "weekly" 11 | day: "sunday" 12 | time: "22:00" 13 | groups: 14 | github-actions: 15 | patterns: 16 | - "*" 17 | 18 | # GitHub composite actions 19 | - package-ecosystem: "github-actions" 20 | directory: "/.github/workflows/run-test" 21 | schedule: 22 | interval: "weekly" 23 | day: "sunday" 24 | time: "22:00" 25 | reviewers: 26 | - "elastic/observablt-ci" 27 | groups: 28 | github-actions: 29 | patterns: 30 | - "*" 31 | -------------------------------------------------------------------------------- /.github/workflows/README.md: -------------------------------------------------------------------------------- 1 | ## CI/CD 2 | 3 | There are 4 main stages that run on GitHub actions: 4 | 5 | * Lint 6 | * Test 7 | * Coverage 8 | * Release 9 | 10 | There are some other stages that run for every push on the main branches: 11 | 12 | * [Microbenchmark](./microbenchmark.yml) 13 | 14 | ### Scenarios 15 | 16 | * Tests should be triggered on branch, tag and PR basis. 17 | * Commits that are only affecting the docs files should not trigger any test or similar stages that are not required. 18 | * Automated release in the CI gets triggered through a GitHub workflow. 19 | * **This is not the case yet**, but if Github secrets are required then Pull Requests from forked repositories won't run any build accessing those secrets. If needed, then create a feature branch. 20 | 21 | ### How to interact with the CI? 22 | 23 | #### On a PR basis 24 | 25 | Once a PR has been opened then there are two different ways you can trigger builds in the CI: 26 | 27 | 1. Commit based 28 | 1. UI based, any Elasticians can force a build through the GitHub UI 29 | 30 | #### Branches 31 | 32 | Every time there is a merge to main or any release branches the whole workflow will compile and test on Linux. 33 | 34 | ### Release process 35 | 36 | This process has been fully automated and it gets triggered manually when running the [release](https://github.com/elastic/apm-agent-java/actions/workflows/release.yml) workflow. 37 | 38 | The tag release follows the naming convention: `v...`, where ``, `` and ``. 39 | 40 | ### OpenTelemetry 41 | 42 | Every workflow and its logs are exported to OpenTelemetry traces/logs/metrics. Those details can be seen [here](https://ela.st/oblt-ci-cd-stats) (**NOTE**: only available for Elasticians). 43 | 44 | ## Bump automation 45 | 46 | [updatecli](https://www.updatecli.io/) is the tool we use to automatically bump some of the dependencies related to 47 | the [Elastic Stack versions](./bump-elastic-stack.yml) used for the different tests. 48 | -------------------------------------------------------------------------------- /.github/workflows/bump-elastic-stack.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: bump-elastic-stack 3 | 4 | on: 5 | workflow_dispatch: 6 | schedule: 7 | - cron: '0 15 * * 1-5' 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | bump: 14 | runs-on: ubuntu-latest 15 | steps: 16 | 17 | - uses: actions/checkout@v4 18 | 19 | - name: Get token 20 | id: get_token 21 | uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0 22 | with: 23 | app_id: ${{ secrets.OBS_AUTOMATION_APP_ID }} 24 | private_key: ${{ secrets.OBS_AUTOMATION_APP_PEM }} 25 | permissions: >- 26 | { 27 | "contents": "write", 28 | "pull_requests": "write", 29 | "workflows": "write" 30 | } 31 | 32 | - uses: elastic/oblt-actions/updatecli/run@v1 33 | with: 34 | command: "--experimental apply --config .ci/bump-elastic-stack.yml" 35 | env: 36 | GITHUB_TOKEN: ${{ steps.get_token.outputs.token }} 37 | 38 | - if: failure() 39 | uses: elastic/oblt-actions/slack/send@v1 40 | with: 41 | bot-token: ${{ secrets.SLACK_BOT_TOKEN }} 42 | channel-id: "#apm-agent-js" 43 | message: ":traffic_cone: updatecli failed for `${{ github.repository }}@${{ github.ref_name }}`, @robots-ci please look what's going on " 44 | -------------------------------------------------------------------------------- /.github/workflows/ci-docs.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # This workflow sets the test / all status check to success in case it's a docs only PR and ci.yml is not triggered 3 | # https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks 4 | name: ci # The name must be the same as ci.yml 5 | 6 | on: 7 | pull_request: 8 | paths-ignore: # This expression needs to match the paths ignored on ci.yml. 9 | - '**' 10 | - '!**/*.md' 11 | - '!**/*.asciidoc' 12 | 13 | permissions: 14 | contents: read 15 | 16 | jobs: 17 | all: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - run: 'echo "No build required"' 21 | -------------------------------------------------------------------------------- /.github/workflows/docs-build.yml: -------------------------------------------------------------------------------- 1 | name: docs-build 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request_target: ~ 8 | merge_group: ~ 9 | 10 | jobs: 11 | docs-preview: 12 | uses: elastic/docs-builder/.github/workflows/preview-build.yml@main 13 | with: 14 | path-pattern: docs/** 15 | permissions: 16 | deployments: write 17 | id-token: write 18 | contents: read 19 | pull-requests: read 20 | -------------------------------------------------------------------------------- /.github/workflows/docs-cleanup.yml: -------------------------------------------------------------------------------- 1 | name: docs-cleanup 2 | 3 | on: 4 | pull_request_target: 5 | types: 6 | - closed 7 | 8 | jobs: 9 | docs-preview: 10 | uses: elastic/docs-builder/.github/workflows/preview-cleanup.yml@main 11 | permissions: 12 | contents: none 13 | id-token: write 14 | deployments: write 15 | -------------------------------------------------------------------------------- /.github/workflows/microbenchmark.yml: -------------------------------------------------------------------------------- 1 | name: microbenchmark 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | stack_version: 7 | description: 'Stack Version' 8 | default: '8.16.2' 9 | required: false 10 | push: 11 | branches: 12 | - main 13 | paths-ignore: 14 | - '**.md' 15 | - '**.asciidoc' 16 | 17 | # limit the access of the generated GITHUB_TOKEN 18 | permissions: 19 | contents: read 20 | 21 | jobs: 22 | microbenchmark: 23 | runs-on: ubuntu-latest 24 | timeout-minutes: 60 25 | steps: 26 | - name: Run buildkite pipeline 27 | uses: elastic/oblt-actions/buildkite/run@v1 28 | env: 29 | STACK_VERSION: ${{ inputs.stack_version || '8.16.2' }} 30 | with: 31 | token: ${{ secrets.BUILDKITE_TOKEN }} 32 | pipeline: apm-agent-microbenchmark 33 | wait-for: true 34 | env-vars: | 35 | script=.ci/scripts/bench.sh 36 | repo=apm-agent-rum-js 37 | sha=${{ github.sha }} 38 | STACK_VERSION=${{ env.STACK_VERSION }} 39 | BRANCH_NAME=${{ github.ref_name }} 40 | 41 | - if: ${{ failure() }} 42 | uses: elastic/oblt-actions/slack/send@v1 43 | with: 44 | bot-token: ${{ secrets.SLACK_BOT_TOKEN }} 45 | channel-id: "#apm-agent-js" 46 | message: | 47 | :ghost: [${{ github.repository }}] microbenchmark *${{ github.ref_name }}* failed to run in Buildkite. 48 | Build: (<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|here>) 49 | -------------------------------------------------------------------------------- /.github/workflows/test-reporter.yml: -------------------------------------------------------------------------------- 1 | --- 2 | ## Workflow to process the JUnit test results and add a report to the checks. 3 | name: test-reporter 4 | on: 5 | workflow_run: 6 | workflows: 7 | - ci 8 | - ci-saucelabs 9 | types: 10 | - completed 11 | 12 | permissions: 13 | contents: read 14 | actions: read 15 | checks: write 16 | 17 | jobs: 18 | report: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: elastic/oblt-actions/test-report@v1 22 | with: 23 | artifact: /test-results(.*)/ # artifact name pattern 24 | name: 'Test Report $1' # Name of the check run which will be created 25 | path: "**/*.xml" # Path to test results (inside artifact .zip) 26 | reporter: java-junit # Format of test results 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .config 3 | .npm 4 | .DS_Store 5 | .idea 6 | 7 | # Ignore all e2e related build files 8 | test/e2e/with-router/build 9 | *.e2e-bundle.* 10 | *-e2e.html 11 | 12 | dist 13 | tmp 14 | out-tsc 15 | 16 | error-screenshot 17 | html_docs 18 | build 19 | reports 20 | coverage 21 | 22 | # ignore lerna-debug and npm-debug logs 23 | *debug.log 24 | packages/**/*.tgz 25 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | legacy-peer-deps=true -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 18 2 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "semi": false, 4 | "trailingComma": "none", 5 | "arrowParens": "avoid" 6 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Release notes are now available in our documentation at ([elastic.co](https://www.elastic.co/guide/en/apm/agent/rum-js/current/release-notes.html)) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-present, Elasticsearch BV 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Elastic APM Real User Monitoring (RUM) JavaScript agent 2 | 3 | [![ci](https://github.com/elastic/apm-agent-rum-js/actions/workflows/ci.yml/badge.svg)](https://github.com/elastic/apm-agent-rum-js/actions/workflows/ci.yml) 4 | [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) 5 | [![codecov](https://codecov.io/gh/elastic/apm-agent-rum-js/branch/main/graph/badge.svg)](https://codecov.io/gh/elastic/apm-agent-rum-js) 6 | [![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lernajs.io/) 7 | 8 | [![Sauce Test Status](https://saucelabs.com/browser-matrix/elastic-apm-base.svg)](https://saucelabs.com/u/elastic-apm-base) 9 |
Cross Browser testing is provided by [Sauce Labs](https://saucelabs.com/) 10 | 11 | This is the official Real User Monitoring JavaScript agent. 12 | 13 | ## Documentation 14 | You can find our documentation [on our website](https://www.elastic.co/guide/en/apm/agent/rum-js/current/index.html). 15 | 16 | If you are interested in contributing to Elastic APM JavaScript agent, please see [our contributing guide](CONTRIBUTING.md). 17 | 18 | We'd love to hear your feedback, please take a minute to fill out our [survey](https://goo.gl/forms/nLCXGCvziqalzjlP2). 19 | 20 | ## License 21 | This project is [MIT licensed](LICENSE). 22 | 23 |
Made with ♥️ and ☕️ by Elastic and our community.
24 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | notify: 3 | require_ci_to_pass: no 4 | comment: 5 | layout: "header, changes, diff, files" 6 | behavior: default 7 | coverage: 8 | status: 9 | project: 10 | default: 11 | target: 80% 12 | threshold: 1 13 | if_not_found: success # if parent is not found report status as success, error, or failure 14 | if_ci_failed: error # if ci fails report status as success, error, or failure 15 | base: parent # will always use the parent commit to compare against. 16 | patch: off #https://docs.codecov.io/docs/commit-status#section-patch-status 17 | -------------------------------------------------------------------------------- /dev-utils/.node-version: -------------------------------------------------------------------------------- 1 | 18 2 | -------------------------------------------------------------------------------- /dev-utils/elasticsearch/roles.yml: -------------------------------------------------------------------------------- 1 | apm_server: 2 | cluster: ['manage_ilm', 'manage_security', 'manage_api_key'] 3 | indices: 4 | - names: ['apm-*', 'traces-apm*', 'logs-apm*', 'metrics-apm*'] 5 | privileges: ['write', 'create_index', 'manage', 'manage_ilm'] 6 | applications: 7 | - application: 'apm' 8 | privileges: ['sourcemap:write', 'event:write', 'config_agent:read'] 9 | resources: '*' 10 | beats: 11 | cluster: ['manage_index_templates', 'monitor', 'manage_ingest_pipelines', 'manage_ilm', 'manage_security', 'manage_api_key'] 12 | indices: 13 | - names: ['filebeat-*', 'shrink-filebeat-*'] 14 | privileges: ['all'] 15 | filebeat: 16 | cluster: ['manage_index_templates', 'monitor', 'manage_ingest_pipelines', 'manage_ilm'] 17 | indices: 18 | - names: ['filebeat-*', 'shrink-filebeat-*'] 19 | privileges: ['all'] 20 | heartbeat: 21 | cluster: ['manage_index_templates', 'monitor', 'manage_ingest_pipelines', 'manage_ilm'] 22 | indices: 23 | - names: ['heartbeat-*', 'shrink-heartbeat-*'] 24 | privileges: ['all'] 25 | metricbeat: 26 | cluster: ['manage_index_templates', 'monitor', 'manage_ingest_pipelines', 'manage_ilm'] 27 | indices: 28 | - names: ['metricbeat-*', 'shrink-metricbeat-*'] 29 | privileges: ['all'] -------------------------------------------------------------------------------- /dev-utils/elasticsearch/service_tokens: -------------------------------------------------------------------------------- 1 | elastic/fleet-server/elastic-package-fleet-server-token:{PBKDF2_STRETCH}10000$PNiVyY96dHwRfoDszBvYPAz+mSLbC+NhtPh63dblDZU=$dAY1tXX1U5rXB+2Lt7m0L2LUNSb1q5nRaIqPNZTBxb8= 2 | elastic/kibana/elastic-package-kibana-token:{PBKDF2_STRETCH}10000$wIEFHIIIZ2ap0D0iQsyw0MfB7YuFA1bHnXAmlCoL4Gg=$YxvIJnasjLZyDQZpmFBiJHdR/CGXd5BnVm013Jty6p0= -------------------------------------------------------------------------------- /dev-utils/elasticsearch/users: -------------------------------------------------------------------------------- 1 | admin:$2a$10$xiY0ZzOKmDDN1p3if4t4muUBwh2.bFHADoMRAWQgSClm4ZJ4132Y. 2 | apm_server_user:$2a$10$iTy29qZaCSVn4FXlIjertuO8YfYVLCbvoUAJ3idaXfLRclg9GXdGG 3 | apm_user_ro:$2a$10$hQfy2o2u33SapUClsx8NCuRMpQyHP9b2l4t3QqrBA.5xXN2S.nT4u 4 | beats_user:$2a$10$LRpKi4/Q3Qo4oIbiu26rH.FNIL4aOH4aj2Kwi58FkMo1z9FgJONn2 5 | filebeat_user:$2a$10$sFxIEX8tKyOYgsbJLbUhTup76ssvSD3L4T0H6Raaxg4ewuNr.lUFC 6 | heartbeat_user:$2a$10$nKUGDr/V5ClfliglJhfy8.oEkjrDtklGQfhd9r9NoFqQeoNxr7uUK 7 | kibana_system_user:$2a$10$nN6sRtQl2KX9Gn8kV/.NpOLSk6Jwn8TehEDnZ7aaAgzyl/dy5PYzW 8 | metricbeat_user:$2a$10$5PyTd121U2ZXnFk9NyqxPuLxdptKbB8nK5egt6M5/4xrKUkk.GReG -------------------------------------------------------------------------------- /dev-utils/elasticsearch/users_roles: -------------------------------------------------------------------------------- 1 | apm_server:apm_server_user 2 | apm_system:apm_server_user 3 | apm_user:apm_server_user,apm_user_ro 4 | beats:beats_user 5 | beats_system:beats_user,filebeat_user,heartbeat_user,metricbeat_user 6 | filebeat:filebeat_user 7 | heartbeat:heartbeat_user 8 | ingest_admin:apm_server_user 9 | kibana_system:kibana_system_user 10 | kibana_user:apm_user_ro,beats_user,filebeat_user,heartbeat_user,metricbeat_user 11 | metricbeat:metricbeat_user 12 | superuser:admin -------------------------------------------------------------------------------- /dev-utils/object-configurable.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | ;(function (defineProperty) { 27 | Object.defineProperty = function (obj, prop, desc) { 28 | desc.configurable = true 29 | return defineProperty.call(obj, obj, prop, desc) 30 | } 31 | })(Object.defineProperty) 32 | -------------------------------------------------------------------------------- /docs/docset.yml: -------------------------------------------------------------------------------- 1 | project: 'APM RUM agent docs' 2 | products: 3 | - id: apm-agent 4 | cross_links: 5 | - apm-agent-dotnet 6 | - apm-agent-go 7 | - apm-agent-java 8 | - apm-agent-nodejs 9 | - apm-agent-python 10 | - apm-agent-ruby 11 | - docs-content 12 | toc: 13 | - toc: reference 14 | - toc: release-notes 15 | subs: 16 | serverless-full: "Elastic Cloud Serverless" 17 | -------------------------------------------------------------------------------- /docs/reference/advanced-topics.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/apm/agent/rum-js/current/advanced-topics.html 4 | --- 5 | 6 | # Advanced topics [advanced-topics] 7 | 8 | * [How to interpret long task spans in the UI](/reference/longtasks.md) 9 | * [Using with TypeScript](/reference/typescript.md) 10 | * [Initial Page load transaction names](/reference/custom-transaction-name.md) 11 | * [Custom Transactions](/reference/custom-transactions.md) 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /docs/reference/api-reference.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/apm/agent/rum-js/current/api.html 4 | --- 5 | 6 | # API reference [api] 7 | 8 | The API reference documentation is divided into three parts: 9 | 10 | * [The `Agent` API](/reference/agent-api.md) - All functions and properties on the `Agent` object. An instance of the `Agent` object is acquired by calling the `init method` the agent either via script element on the page or require the `elastic-apm-rum` module in Node.js. The `Agent` instance is usually referred to by the variable `apm` in this documentation. 11 | * [The `Transaction` API](/reference/transaction-api.md) - All functions and properties on the `Transaction` object. An instance of the `Transaction` object is acquired by calling `apm.startTransaction()`. 12 | * [The `Span` API](/reference/span-api.md) - All functions and properties on the `Span` object. An instance of the `Span` object is acquired by calling `apm.startSpan()`. 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /docs/reference/configuring-cors.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/apm/agent/rum-js/current/configuring-cors.html 4 | --- 5 | 6 | # Configure CORS [configuring-cors] 7 | 8 | If APM Server is deployed in an origin different than the page’s origin, you will need to configure Cross-Origin Resource Sharing (CORS). 9 | 10 | A list of permitted origins can be supplied to the [`apm-server.rum.allow_origins`](docs-content://solutions/observability/apm/configure-real-user-monitoring-rum.md#apm-rum-allow-origins) configuration option. By default, APM Server allows all origins. 11 | 12 | 13 | ## How CORS works [_how_cors_works] 14 | 15 | When the RUM agent makes its initial `POST` request, the browser will check to see if it is a cross-origin request. If it is, the browser automatically makes a preflight `OPTIONS` request to the server to ensure the original `POST` request is allowed. If this `OPTIONS` check passes, then the original `POST` request is allowed. This request will fail if RUM support is not configured in the APM Server. 16 | 17 | If you use a proxy, the preflight request headers may be necessary for your configuration: 18 | 19 | ```js 20 | Access-Control-Request-Headers: Content-Type 21 | Access-Control-Request-Method: POST 22 | Origin: [request-origin] 23 | ``` 24 | 25 | The response should include these headers: 26 | 27 | ```js 28 | Access-Control-Allow-Headers: Content-Type 29 | Access-Control-Allow-Methods: POST, OPTIONS 30 | Access-Control-Allow-Origin: [request-origin] 31 | ``` 32 | 33 | If you enable the [`sendCredentials`](/reference/configuration.md#send-credentials) configuration option, your proxy’s response must include the header `Access-Control-Allow-Origin` with the page’s origin as a value, and the following header: 34 | 35 | ```js 36 | Access-Control-Allow-Credentials: true 37 | ``` 38 | 39 | ::::{tip} 40 | To learn more about CORS, see the MDN page on [Cross-Origin Resource Sharing](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS). 41 | :::: 42 | 43 | 44 | -------------------------------------------------------------------------------- /docs/reference/framework-specific-integrations.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/apm/agent/rum-js/current/framework-integrations.html 4 | --- 5 | 6 | # Framework-specific integrations [framework-integrations] 7 | 8 | * [React Integration](/reference/react-integration.md) 9 | * [Angular Integration](/reference/angular-integration.md) 10 | * [Vue Integration](/reference/vue-integration.md) 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /docs/reference/images/compatibility.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/apm-agent-rum-js/3d27a86f525e20c258fe49db4ba470a93fe9aea3/docs/reference/images/compatibility.png -------------------------------------------------------------------------------- /docs/reference/longtasks.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/apm/agent/rum-js/current/longtasks.html 4 | --- 5 | 6 | # How to interpret long task spans in the UI [longtasks] 7 | 8 | Long tasks is a new performance metric that can be used for measuring the responsiveness of an application and helps developers to understand the bad user experience. It enables detecting tasks that monopolize the UI thread for extended periods (greater than 50 milliseconds) and block other critical tasks from being executed as stated in the [official spec](https://github.com/w3c/longtasks). 9 | 10 | RUM agent automatically captures these Long tasks and include them as spans as part of the transaction. Since long tasks currently does not have the full information on which part of code cause slowness, it would be hard to interpret these spans. Below you can find some tips to help with interpreting long task spans: 11 | 12 | * The name of the long task span, e.g.: `self`, `same-origin`, etc., implies the origin of the task. It could be the current browsing context or inside iframes. 13 | * Context of the span is enriched with useful information like `attribution` (the type of work, such as script, layout, etc), `type`, `id` and `name`, which determines the culprit container (such as window, iframe, embed or object) responsible for the long task. 14 | 15 | With the help of the transaction timeline and span timings, one could dig deeper by marking slow application code with the [User Timing API](https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark). When these spans are then captured by the agent again, you could combine them with long tasks to reveal the true source code location. 16 | 17 | -------------------------------------------------------------------------------- /docs/reference/set-up-apm-real-user-monitoring-javascript-agent.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/apm/agent/rum-js/current/getting-started.html 4 | --- 5 | 6 | # Set up the APM Real User Monitoring JavaScript Agent [getting-started] 7 | 8 | To start reporting your web page performance to Elastic APM, you must first [enable the RUM endpoint](docs-content://solutions/observability/apm/configure-real-user-monitoring-rum.md) in your `apm-server` configuration. 9 | 10 | Once the APM Server endpoint has been configured, you can: 11 | 12 | * [Install the Agent](/reference/install-agent.md) 13 | * [Configure CORS](/reference/configuring-cors.md) 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /docs/reference/source-maps.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/apm/agent/rum-js/current/sourcemap.html 4 | --- 5 | 6 | # Source maps [sourcemap] 7 | 8 | Minifying JavaScript bundles is a common practice in production as it can improve the load time and network latency of your application. However, minified code by itself can be hard to debug. For this reason, Elastic APM supports source maps. A source map is a file that maps minified files back to the original source code, allowing you to maintain the speed advantage of minified code, without losing the ability to quickly and easily debug your applications. 9 | 10 | There are three steps required to enable, upload, and apply a source map to error stack traces. An overview is listed below, and a complete walk-through is available in the [generate and upload a source map](docs-content://solutions/observability/apm/create-upload-source-maps-rum.md) guide. 11 | 12 | 1. Set the [`serviceVersion`](/reference/configuration.md#service-version) when initializing the RUM Agent. 13 | 2. [Generate a source map](docs-content://solutions/observability/apm/create-upload-source-maps-rum.md#apm-source-map-rum-generate) for your application with the `serviceVersion` from step one. 14 | 3. [Enable and upload the source map file](docs-content://solutions/observability/apm/create-upload-source-maps-rum.md#apm-source-map-rum-upload) to APM Server. 15 | 16 | $$$secret-token$$$ 17 | You can also configure a [secret token](docs-content://solutions/observability/apm/secret-token.md) or [API key](docs-content://solutions/observability/apm/api-keys.md) to restrict the uploading of sourcemaps. 18 | 19 | ::::{tip} 20 | Don’t forget, you must enable [RUM support](docs-content://solutions/observability/apm/configure-real-user-monitoring-rum.md) in the APM Server for this endpoint to work. 21 | :::: 22 | 23 | 24 | -------------------------------------------------------------------------------- /docs/reference/span-api.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/apm/agent/rum-js/current/span-api.html 4 | --- 5 | 6 | # Span API [span-api] 7 | 8 | A span measures the duration of a single event. When a span is created it will measure the time until [`span.end()`](#span-end) is called. 9 | 10 | To get a `Span` object, you need to call [`apm.startSpan()`](/reference/agent-api.md#apm-start-span). 11 | 12 | 13 | ## `span.name` [span-name] 14 | 15 | * **Type:** String 16 | * **Default:** `Unknown` 17 | 18 | The name of the span. This can also be set via [`apm.startSpan()`](/reference/agent-api.md#apm-start-span). 19 | 20 | 21 | ## `span.type` [span-type] 22 | 23 | * **Type:** String 24 | * **Default:** `custom` 25 | 26 | The type of span. This can also be set via [`apm.startSpan()`](/reference/agent-api.md#apm-start-span). 27 | 28 | The type is a hierarchical string used to group similar spans together. For instance, all outgoing AJAX requests are given the type `external.http`. 29 | 30 | In the above example, `external` is considered the type prefix. Though there are no naming restrictions for this prefix, the following are standardized across all Elastic APM agents: `app`, `db`, `cache`, `template`, and `external`. 31 | 32 | 33 | ## `span.addLabels()` [span-add-labels] 34 | 35 | ```js 36 | span.addLabels({ [name]: value }) 37 | ``` 38 | 39 | Add several labels on the span. If an error happens during the span, it will also get tagged with the same labels. 40 | 41 | Arguments: 42 | 43 | * `name` - Any string. All periods (.), asterisks (*), and double quotation marks (") will be replaced by underscores (_), as those characters have special meaning in Elasticsearch 44 | * `value` - Any string, boolean, or number. All other data types will be converted to a string before being sent to the APM Server. 45 | 46 | 47 | ## `span.end()` [span-end] 48 | 49 | ```js 50 | span.end() 51 | ``` 52 | 53 | Ends the span. If the span has already ended, nothing happens. 54 | 55 | -------------------------------------------------------------------------------- /docs/reference/toc.yml: -------------------------------------------------------------------------------- 1 | project: 'APM Real User Monitoring (RUM) JavaScript Agent reference' 2 | toc: 3 | - file: index.md 4 | - file: set-up-apm-real-user-monitoring-javascript-agent.md 5 | children: 6 | - file: install-agent.md 7 | - file: configuring-cors.md 8 | - file: supported-technologies.md 9 | - file: configuration.md 10 | - file: api-reference.md 11 | children: 12 | - file: agent-api.md 13 | - file: transaction-api.md 14 | - file: span-api.md 15 | - file: source-maps.md 16 | - file: framework-specific-integrations.md 17 | children: 18 | - file: react-integration.md 19 | - file: angular-integration.md 20 | - file: vue-integration.md 21 | - file: distributed-tracing.md 22 | - file: breakdown-metrics.md 23 | - file: opentracing.md 24 | - file: advanced-topics.md 25 | children: 26 | - file: longtasks.md 27 | - file: typescript.md 28 | - file: custom-transaction-name.md 29 | - file: custom-transactions.md 30 | - file: performance-tuning.md 31 | - file: upgrading.md -------------------------------------------------------------------------------- /docs/reference/typescript.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/apm/agent/rum-js/current/typescript.html 4 | --- 5 | 6 | # Using with TypeScript [typescript] 7 | 8 | RUM agent publishes the type definitions for the `@elastic/apm-rum` package via `types` property in `package.json`. If you are importing the package on a TypeScript codebase, you will get automatic code completion, hover info and method signature information on supported platforms (Visual Studio Code, etc) 9 | 10 | -------------------------------------------------------------------------------- /docs/reference/upgrading.md: -------------------------------------------------------------------------------- 1 | --- 2 | mapped_pages: 3 | - https://www.elastic.co/guide/en/apm/agent/rum-js/current/upgrading.html 4 | --- 5 | 6 | # Upgrading [upgrading] 7 | 8 | Upgrades between minor versions of the agent, like from 3.1 to 3.2 are always backwards compatible. Upgrades that involve a major version bump often come with some backwards incompatible changes. 9 | 10 | Before upgrading the agent, be sure to review the: 11 | 12 | * [Agent release notes](/release-notes/index.md) 13 | * [Agent and Server compatibility chart](docs-content://solutions/observability/apm/apm-agent-compatibility.md) 14 | 15 | The following upgrade guides are also available: 16 | 17 | * [Upgrade to version 5.x](/release-notes/breaking-changes.md) - Follow this guide to upgrade from version `4.x` to version `5.x` of the Elastic APM RUM JS Agent. 18 | 19 | 20 | ## End of life dates [end-of-life-dates] 21 | 22 | We love all our products, but sometimes we must say goodbye to a release so that we can continue moving forward on future development and innovation. Our [End of life policy](https://www.elastic.co/support/eol) defines how long a given release is considered supported, as well as how long a release is considered still in active development or maintenance. The table below is a simplified description of this policy. 23 | 24 | | Agent version | EOL Date | Maintained until | 25 | | --- | --- | --- | 26 | | 4.8.x | 2021-08-13 | 4.9.0 | 27 | | 4.7.x | 2021-07-15 | 4.8.0 | 28 | | 4.6.x | 2021-05-19 | 4.7.0 | 29 | | 4.5.x | 2021-03-30 | 4.6.0 | 30 | | 4.4.x | 2021-02-05 | 4.5.0 | 31 | | 4.3.x | 2021-01-11 | 4.4.0 | 32 | | 4.2.x | 2021-01-08 | 4.3.0 | 33 | | 4.1.x | 2020-12-12 | 4.2.0 | 34 | | 4.0.x | 2020-09-11 | 4.1.0 | 35 | | 3.0.x | 2020-07-29 | 5.0.0 | 36 | | 2.3.x | 2020-06-18 | 4.0.0 | 37 | | 2.2.x | 2020-06-05 | 2.3.0 | 38 | | 2.1.x | 2020-06-03 | 2.2.0 | 39 | | 2.0.x | 2020-05-14 | 2.1.0 | 40 | | 1.0.x | 2020-02-23 | 3.0.0 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /docs/release-notes/known-issues.md: -------------------------------------------------------------------------------- 1 | --- 2 | navigation_title: "Known issues" 3 | 4 | --- 5 | # Elastic APM Real User Monitoring JavaScript Agent known issues [elastic-apm-rum-javascript-agent-known-issues] 6 | 7 | Known issues are significant defects or limitations that may impact your implementation. These issues are actively being worked on and will be addressed in a future release. Review the Elastic APM Real User Monitoring JavaScript Agent known issues to help you make informed decisions, such as upgrading to a new version. 8 | 9 | % Use the following template to add entries to this page. 10 | 11 | % :::{dropdown} Title of known issue 12 | % **Details** 13 | % On [Month/Day/Year], a known issue was discovered that [description of known issue]. 14 | 15 | % **Workaround** 16 | % Workaround description. 17 | 18 | % **Resolved** 19 | % On [Month/Day/Year], this issue was resolved. 20 | 21 | ::: 22 | 23 | _No known issues_ -------------------------------------------------------------------------------- /docs/release-notes/toc.yml: -------------------------------------------------------------------------------- 1 | toc: 2 | - file: index.md 3 | - file: known-issues.md 4 | - file: breaking-changes.md -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | "packages/*" 4 | ], 5 | "version": "independent", 6 | "registry": "https://registry.npmjs.org", 7 | "command": { 8 | "version": { 9 | "allowBranch": ["main", "4.x", "release", "prerelease/*"], 10 | "conventionalCommits": true, 11 | "message": "chore(release): publish", 12 | "changelogPreset": "conventionalcommits", 13 | "gitRemote": "origin", 14 | "loglevel": "verbose" 15 | }, 16 | "run": { 17 | "stream": true 18 | }, 19 | "publish": { 20 | "loglevel": "verbose" 21 | } 22 | }, 23 | "ignoreChanges": [ 24 | "**/*.md", 25 | "**/test/**", 26 | "docs" 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /packages/rum-angular/README.md: -------------------------------------------------------------------------------- 1 | Elastic APM Real User Monitoring for Angular applications 2 | 3 | This package provides Real User Monitoring (RUM) for Angular applications. 4 | 5 | ## Documentation 6 | You can find our documentation [on our website](https://www.elastic.co/guide/en/apm/agent/rum-js/current/index.html). 7 | 8 | If you are interested in contributing to Elastic APM JavaScript agent, please see [our contributing guide](CONTRIBUTING.md). 9 | 10 | 11 | ## License 12 | This project is [MIT licensed](LICENSE). 13 | 14 |
Made with ♥️ and ☕️ by Elastic and our community.
-------------------------------------------------------------------------------- /packages/rum-angular/ng-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", 3 | "dest": "dist", 4 | "lib": { 5 | "entryFile": "src/index.ts", 6 | "umdModuleIds": { 7 | "@elastic/apm-rum": "elastic.apmRum", 8 | "@elastic/apm-rum-core": "elastic.apmRumCore" 9 | }, 10 | "umdId": "elastic.apmRumAngular" 11 | }, 12 | "allowedNonPeerDependencies": [ 13 | "@elastic/*" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/rum-angular/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@elastic/apm-rum-angular", 3 | "version": "3.0.7", 4 | "description": "Elastic APM Real User Monitoring for Angular applications", 5 | "homepage": "https://www.elastic.co/guide/en/apm/agent/rum-js/current/index.html", 6 | "license": "MIT", 7 | "publishConfig": { 8 | "access": "public", 9 | "directory": "dist" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/elastic/apm-agent-rum-js.git", 14 | "directory": "packages/rum-angular" 15 | }, 16 | "engines": { 17 | "node": ">=16.0.0" 18 | }, 19 | "scripts": { 20 | "prepublishOnly": "npm run build", 21 | "build": "ng build --configuration production", 22 | "build:e2e": "NODE_OPTIONS='--openssl-legacy-provider' ng build app --configuration production", 23 | "test:unit": "NODE_OPTIONS='--openssl-legacy-provider' ng test", 24 | "test:e2e": "NODE_OPTIONS='--openssl-legacy-provider' npm run script runE2eTests packages/rum-angular/wdio.conf.js", 25 | "test:sauce": "NODE_OPTIONS='--openssl-legacy-provider' npm run script runSauceTests packages/rum-angular true test:unit build:e2e test:e2e", 26 | "test": "NODE_OPTIONS='--openssl-legacy-provider' npm run test:sauce", 27 | "script": "node ../../dev-utils/run-script.js", 28 | "karma:dev": "ng test --watch", 29 | "karma:coverage": "NODE_OPTIONS='--openssl-legacy-provider' ng test --code-coverage" 30 | }, 31 | "dependencies": { 32 | "@elastic/apm-rum": "file:../rum", 33 | "@elastic/apm-rum-core": "file:../rum-core", 34 | "tslib": "^2.1.0" 35 | }, 36 | "peerDependencies": { 37 | "@angular/core": ">=12.0.0", 38 | "@angular/router": ">=12.0.0" 39 | }, 40 | "browserslist": [ 41 | "ie 11" 42 | ] 43 | } 44 | -------------------------------------------------------------------------------- /packages/rum-angular/src/apm.module.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { InjectionToken, NgModule } from '@angular/core' 27 | import { RouterModule } from '@angular/router' 28 | import { apm, ApmBase } from '@elastic/apm-rum' 29 | 30 | export const APM = new InjectionToken('APM Base Client') 31 | 32 | @NgModule({ 33 | imports: [RouterModule], 34 | providers: [{ provide: APM, useValue: apm }] 35 | }) 36 | export class ApmModule {} 37 | -------------------------------------------------------------------------------- /packages/rum-angular/src/error-handler.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { ErrorHandler, Inject, Injectable } from '@angular/core' 27 | import { ApmBase } from '@elastic/apm-rum' 28 | import { APM } from './apm.module' 29 | 30 | @Injectable() 31 | export class ApmErrorHandler extends ErrorHandler { 32 | constructor(@Inject(APM) public apm: ApmBase) { 33 | super() 34 | } 35 | 36 | handleError(error) { 37 | this.apm.captureError(error.originalError || error) 38 | super.handleError(error) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /packages/rum-angular/src/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | export * from './apm.module' 27 | export * from './apm.service' 28 | export * from './error-handler' 29 | -------------------------------------------------------------------------------- /packages/rum-angular/test/e2e/with-router/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { NgModule } from '@angular/core' 27 | import { RouterModule, Routes } from '@angular/router' 28 | 29 | import { HomeComponent } from './home.component' 30 | import { PageNotFoundComponent } from './not-found.component' 31 | import { ContactListComponent } from './contact-list.component' 32 | import { ContactDetailComponent } from './contact-detail.component' 33 | 34 | const routes: Routes = [ 35 | { path: 'contacts', component: ContactListComponent }, 36 | { path: 'contact/:id', component: ContactDetailComponent }, 37 | { path: '', redirectTo: 'home', pathMatch: 'full' }, 38 | { path: 'home', component: HomeComponent }, 39 | { path: '**', component: PageNotFoundComponent } 40 | ] 41 | 42 | @NgModule({ 43 | imports: [RouterModule.forRoot(routes)], 44 | exports: [RouterModule] 45 | }) 46 | export class AppRoutingModule {} 47 | -------------------------------------------------------------------------------- /packages/rum-angular/test/e2e/with-router/app/app.component.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { Component } from '@angular/core' 27 | 28 | @Component({ 29 | selector: 'app-root', 30 | template: ` 31 |

Elastic APM with Angular Router

32 | 37 | 38 | ` 39 | }) 40 | export class AppComponent {} 41 | -------------------------------------------------------------------------------- /packages/rum-angular/test/e2e/with-router/app/contact-list.component.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { Component, OnInit } from '@angular/core' 27 | import { ContactService } from './contact.service' 28 | 29 | @Component({ 30 | selector: 'app-contact-list', 31 | template: ` 32 |
33 | Name - {{ contact.name }} 34 | Email - {{ contact.email }} 35 | 36 | Go to details 37 | 38 |
39 | `, 40 | styles: [ 41 | ` 42 | span { 43 | margin-right: 10px; 44 | } 45 | ` 46 | ] 47 | }) 48 | export class ContactListComponent implements OnInit { 49 | contacts: any[] = [] 50 | 51 | constructor(private contactService: ContactService) {} 52 | 53 | ngOnInit() { 54 | this.contactService.getContacts().subscribe((data: any[]) => { 55 | this.contacts = data 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /packages/rum-angular/test/e2e/with-router/app/contact.service.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { Injectable } from '@angular/core' 27 | import { HttpClient } from '@angular/common/http' 28 | 29 | @Injectable({ 30 | providedIn: 'root' 31 | }) 32 | export class ContactService { 33 | CONTACT_URL = '/test/e2e/with-router/build/assets/data.json' 34 | constructor(private http: HttpClient) {} 35 | 36 | getContacts() { 37 | return this.http.get(this.CONTACT_URL) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/rum-angular/test/e2e/with-router/app/home.component.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { Component } from '@angular/core' 27 | 28 | @Component({ 29 | selector: 'app-home', 30 | template: `

Home page

` 31 | }) 32 | export class HomeComponent {} 33 | -------------------------------------------------------------------------------- /packages/rum-angular/test/e2e/with-router/app/not-found.component.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { Component } from '@angular/core' 27 | 28 | @Component({ 29 | selector: 'app-page-not-found', 30 | template: '

page not found

' 31 | }) 32 | export class PageNotFoundComponent {} 33 | -------------------------------------------------------------------------------- /packages/rum-angular/test/e2e/with-router/assets/data.json: -------------------------------------------------------------------------------- 1 | [ 2 | { "id": 1, "name": "Contact 1", "email": "contact1@email.com" }, 3 | { "id": 2, "name": "Contact 2", "email": "contact2@email.com" }, 4 | { "id": 3, "name": "Contact 3", "email": "contact3@email.com" }, 5 | { "id": 4, "name": "Contact 4", "email": "contact4@email.com" } 6 | ] 7 | -------------------------------------------------------------------------------- /packages/rum-angular/test/e2e/with-router/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | export const environment = { 27 | production: true, 28 | serverUrl: 'http://apm-server:8200' 29 | } 30 | -------------------------------------------------------------------------------- /packages/rum-angular/test/e2e/with-router/environments/environment.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | // This file can be replaced during build by using the `fileReplacements` array. 27 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 28 | // The list of file replacements can be found in `angular.json`. 29 | 30 | export const environment = { 31 | production: false, 32 | serverUrl: 'http://localhost:8001' 33 | } 34 | -------------------------------------------------------------------------------- /packages/rum-angular/test/e2e/with-router/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | RUM Angular e2e test 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /packages/rum-angular/test/e2e/with-router/main.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { enableProdMode } from '@angular/core' 27 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic' 28 | 29 | import { AppModule } from './app/app.module' 30 | import { environment } from './environments/environment' 31 | 32 | if (environment.production) { 33 | enableProdMode() 34 | } 35 | 36 | platformBrowserDynamic() 37 | .bootstrapModule(AppModule) 38 | .catch(err => console.error(err)) 39 | -------------------------------------------------------------------------------- /packages/rum-angular/test/e2e/with-router/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | /** 27 | * This file includes polyfills needed by Angular and is loaded before the app. 28 | * You can add your own extra polyfills to this file. 29 | * Learn more in https://angular.io/guide/browser-support 30 | */ 31 | 32 | /** 33 | * Zone JS is required by default for Angular itself. 34 | */ 35 | import 'zone.js/dist/zone' 36 | -------------------------------------------------------------------------------- /packages/rum-angular/test/e2e/with-router/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../../out-tsc/app", 5 | "types": ["node"], 6 | "target": "ES5", 7 | "allowJs": true 8 | }, 9 | "files": ["main.ts", "polyfills.ts"], 10 | "include": ["**/rum-core/**/*.js", "**/*.d.ts"] 11 | } 12 | -------------------------------------------------------------------------------- /packages/rum-angular/test/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { apmBase } from '@elastic/apm-rum' 27 | import ApmServerMock from '../../rum-core/test/utils/apm-server-mock' 28 | 29 | export function initializeApmService(service, config) { 30 | const apmServer = apmBase.serviceFactory.getService('ApmServer') 31 | const serverMock = new ApmServerMock(apmServer, false) 32 | apmBase.serviceFactory.instances['ApmServer'] = serverMock 33 | return service.init(config) 34 | } 35 | -------------------------------------------------------------------------------- /packages/rum-angular/test/specs/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 27 | 28 | import 'zone.js/dist/zone' 29 | import 'zone.js/dist/zone-testing' 30 | import { getTestBed } from '@angular/core/testing' 31 | import { 32 | BrowserDynamicTestingModule, 33 | platformBrowserDynamicTesting 34 | } from '@angular/platform-browser-dynamic/testing' 35 | 36 | declare const require: { 37 | context( 38 | path: string, 39 | deep?: boolean, 40 | filter?: RegExp 41 | ): { 42 | keys(): string[] 43 | (id: string): T 44 | } 45 | } 46 | 47 | // First, initialize the Angular testing environment. 48 | getTestBed().initTestEnvironment( 49 | BrowserDynamicTestingModule, 50 | platformBrowserDynamicTesting() 51 | ) 52 | // Then we find all the tests. 53 | const context = require.context('./', true, /\.spec\.ts$/) 54 | // And load the modules. 55 | context.keys().map(context) 56 | -------------------------------------------------------------------------------- /packages/rum-angular/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "lib": ["es2018", "dom"], 15 | "paths": { 16 | "@elastic/apm-rum-core": ["../rum-core/dist/es"], 17 | "@elastic/apm-rum": ["../rum/src/dist/es"], 18 | "@elastic/apm-rum-angular": ["src"] 19 | } 20 | }, 21 | "angularCompilerOptions": { 22 | "fullTemplateTypeCheck": true, 23 | "strictInjectionParameters": true 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/rum-angular/tsconfig.lib.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "out-tsc/lib", 5 | "target": "es2015", 6 | "declaration": true, 7 | "inlineSources": true, 8 | "types": [], 9 | "lib": ["dom", "es2018"] 10 | }, 11 | "angularCompilerOptions": { 12 | "skipTemplateCodegen": true, 13 | "strictMetadataEmit": true, 14 | "enableResourceInlining": true 15 | }, 16 | "exclude": ["test/**", "**/*.spec.ts"] 17 | } 18 | -------------------------------------------------------------------------------- /packages/rum-angular/tsconfig.lib.prod.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.lib.json", 3 | "angularCompilerOptions": { 4 | "enableIvy": true, 5 | "compilationMode": "partial" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/rum-angular/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "out-tsc/spec", 5 | "types": ["jasmine", "node"], 6 | "target": "ES5" 7 | }, 8 | "files": ["test/specs/index.ts"], 9 | "include": ["**/*.spec.ts", "**/*.d.ts"] 10 | } 11 | -------------------------------------------------------------------------------- /packages/rum-angular/wdio.conf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const { getWebdriveBaseConfig } = require('../../dev-utils/webdriver') 27 | 28 | exports.config = getWebdriveBaseConfig(__dirname) 29 | -------------------------------------------------------------------------------- /packages/rum-core/README.md: -------------------------------------------------------------------------------- 1 | # Elastic APM JavaScript core (for development) 2 | 3 | This is the core JavaScript module for Elastic APM. 4 | 5 | **Only use this package if you want to implement an integration for a framework that Elastic APM does not support yet.** 6 | 7 | ## Documentation 8 | You can find our documentation [on our website](https://www.elastic.co/guide/en/apm/agent/rum-js/current/index.html). 9 | 10 | If you are interested in contributing to Elastic APM JavaScript agent, please see [our contributing guide](CONTRIBUTING.md). 11 | 12 | We'd love to hear your feedback, please take a minute to fill out our [survey](https://goo.gl/forms/nLCXGCvziqalzjlP2). 13 | 14 | ## License 15 | This project is [MIT licensed](LICENSE). 16 | 17 |
Made with ♥️ and ☕️ by Elastic and our community.
18 | -------------------------------------------------------------------------------- /packages/rum-core/babel.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const { getBabelConfig } = require('../../dev-utils/build') 27 | 28 | module.exports = function (api) { 29 | const env = api.env() 30 | return getBabelConfig(env) 31 | } 32 | -------------------------------------------------------------------------------- /packages/rum-core/karma.conf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const { baseConfig, prepareConfig } = require('../../dev-utils/karma') 27 | 28 | module.exports = function (config) { 29 | config.set(baseConfig) 30 | const preparedConfig = prepareConfig(config, 'rum-core') 31 | config.set(preparedConfig) 32 | } 33 | -------------------------------------------------------------------------------- /packages/rum-core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@elastic/apm-rum-core", 3 | "version": "5.23.0", 4 | "description": "Elastic apm core", 5 | "license": "MIT", 6 | "main": "dist/lib/index.js", 7 | "module": "dist/es/index.js", 8 | "source": "src/index.js", 9 | "sideEffects": false, 10 | "publishConfig": { 11 | "access": "public" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/elastic/apm-agent-rum-js.git", 16 | "directory": "packages/rum-core" 17 | }, 18 | "scripts": { 19 | "prepublishOnly": "npm run build", 20 | "build": "run-p build:*", 21 | "build:main": "BABEL_ENV=BROWSER_PROD npx babel src -d dist/lib", 22 | "build:module": "BABEL_ENV=BROWSER_ESM_PROD npx babel src -d dist/es", 23 | "karma:dev": "karma start --auto-watch --restartOnFileChange", 24 | "bench": "NODE_ENV=production karma start karma.bench.conf.js", 25 | "karma:coverage": "karma start --coverage --singleRun", 26 | "test:unit": "npm run script runUnitTests packages/rum-core", 27 | "test:sauce": "npm run script runSauceTests packages/rum-core true test:unit", 28 | "test": "npm run test:sauce", 29 | "script": "node ../../dev-utils/run-script.js" 30 | }, 31 | "files": [ 32 | "src", 33 | "dist" 34 | ], 35 | "engines": { 36 | "node": ">=8.0.0" 37 | }, 38 | "dependencies": { 39 | "error-stack-parser": "^1.3.5", 40 | "opentracing": "^0.14.3", 41 | "promise-polyfill": "^8.1.3" 42 | }, 43 | "browserslist": [ 44 | "ie 11" 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /packages/rum-core/src/bootstrap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { isPlatformSupported, isBrowser, now } from './common/utils' 27 | import { patchAll } from './common/patching' 28 | import { state } from './state' 29 | 30 | let enabled = false 31 | export function bootstrap() { 32 | if (isPlatformSupported()) { 33 | patchAll() 34 | state.bootstrapTime = now() 35 | enabled = true 36 | } else if (isBrowser) { 37 | /** 38 | * Print this error message only on the browser console 39 | * on unsupported browser versions 40 | */ 41 | console.log('[Elastic APM] platform is not supported!') 42 | } 43 | 44 | return enabled 45 | } 46 | -------------------------------------------------------------------------------- /packages/rum-core/src/common/after-frame.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const RAF_TIMEOUT = 100 27 | 28 | /** 29 | * Schedule a callback to be invoked after the browser paints a new frame. 30 | * 31 | * There are multiple ways to do this like double rAF, MessageChannel, But we 32 | * use the requestAnimationFrame + setTimeout 33 | * 34 | * Also, RAF does not fire if the current tab is not visible, so we schedule a 35 | * timeout in parallel to ensure the callback is invoked 36 | * 37 | * Based on the code from preact! 38 | * https://github.com/preactjs/preact/blob/f6577c495306f1e93174d69bd79f9fb8a418da75/hooks/src/index.js#L285-L297 39 | */ 40 | export default function afterFrame(callback) { 41 | const handler = () => { 42 | clearTimeout(timeout) 43 | cancelAnimationFrame(raf) 44 | setTimeout(callback) 45 | } 46 | const timeout = setTimeout(handler, RAF_TIMEOUT) 47 | 48 | const raf = requestAnimationFrame(handler) 49 | } 50 | -------------------------------------------------------------------------------- /packages/rum-core/src/common/http/response-status.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | export function isResponseSuccessful(status) { 27 | // An http 4xx or 5xx error. Signal an error. 28 | if (status === 0 || (status > 399 && status < 600)) { 29 | return false 30 | } 31 | 32 | return true 33 | } 34 | -------------------------------------------------------------------------------- /packages/rum-core/src/common/instrument.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { 27 | XMLHTTPREQUEST, 28 | FETCH, 29 | HISTORY, 30 | PAGE_LOAD, 31 | ERROR, 32 | EVENT_TARGET, 33 | CLICK 34 | } from './constants' 35 | 36 | export function getInstrumentationFlags(instrument, disabledInstrumentations) { 37 | /** 38 | * Valid instrumentation flags 39 | */ 40 | const flags = { 41 | [XMLHTTPREQUEST]: false, 42 | [FETCH]: false, 43 | [HISTORY]: false, 44 | [PAGE_LOAD]: false, 45 | [ERROR]: false, 46 | [EVENT_TARGET]: false, 47 | [CLICK]: false 48 | } 49 | 50 | if (!instrument) { 51 | return flags 52 | } 53 | 54 | Object.keys(flags).forEach(key => { 55 | if (disabledInstrumentations.indexOf(key) === -1) { 56 | flags[key] = true 57 | } 58 | }) 59 | return flags 60 | } 61 | -------------------------------------------------------------------------------- /packages/rum-core/src/common/ndjson.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | class NDJSON { 27 | static stringify(object) { 28 | return JSON.stringify(object) + '\n' 29 | } 30 | } 31 | 32 | export default NDJSON 33 | -------------------------------------------------------------------------------- /packages/rum-core/src/common/observers/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { observePageVisibility } from './page-visibility' 27 | import { observePageClicks } from './page-clicks' 28 | 29 | export { observePageVisibility, observePageClicks } 30 | -------------------------------------------------------------------------------- /packages/rum-core/src/common/patching/history-patch.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { INVOKE, HISTORY } from '../constants' 27 | 28 | export function patchHistory(callback) { 29 | if (!window.history) { 30 | return 31 | } 32 | 33 | const nativePushState = history.pushState 34 | if (typeof nativePushState === 'function') { 35 | history.pushState = function (state, title, url) { 36 | const task = { 37 | source: HISTORY, 38 | data: { 39 | state, 40 | title, 41 | url 42 | } 43 | } 44 | 45 | callback(INVOKE, task) 46 | nativePushState.apply(this, arguments) 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/rum-core/src/common/patching/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { patchXMLHttpRequest } from './xhr-patch' 27 | import { patchFetch } from './fetch-patch' 28 | import { patchHistory } from './history-patch' 29 | import EventHandler from '../event-handler' 30 | import { HISTORY, FETCH, XMLHTTPREQUEST } from '../constants' 31 | 32 | const patchEventHandler = new EventHandler() 33 | let alreadyPatched = false 34 | 35 | function patchAll() { 36 | if (!alreadyPatched) { 37 | alreadyPatched = true 38 | patchXMLHttpRequest(function (event, task) { 39 | patchEventHandler.send(XMLHTTPREQUEST, [event, task]) 40 | }) 41 | patchFetch(function (event, task) { 42 | patchEventHandler.send(FETCH, [event, task]) 43 | }) 44 | patchHistory(function (event, task) { 45 | patchEventHandler.send(HISTORY, [event, task]) 46 | }) 47 | } 48 | return patchEventHandler 49 | } 50 | 51 | export { patchAll, patchEventHandler } 52 | -------------------------------------------------------------------------------- /packages/rum-core/src/common/polyfills.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import PromisePollyfill from 'promise-polyfill' 27 | import { isBrowser } from './utils' 28 | 29 | /** 30 | * Use the globally available promise if it exists and 31 | * fallback to using the polyfilled Promise 32 | */ 33 | let local = {} 34 | if (isBrowser) { 35 | local = window 36 | } else if (typeof self !== 'undefined') { 37 | local = self 38 | } 39 | const Promise = 'Promise' in local ? local.Promise : PromisePollyfill 40 | 41 | export { Promise } 42 | -------------------------------------------------------------------------------- /packages/rum-core/src/common/throttle.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | export default function throttle(fn, onThrottle, opts) { 27 | var context = this 28 | var limit = opts.limit 29 | var interval = opts.interval 30 | var counter = 0 31 | var timeoutId 32 | return function () { 33 | counter++ 34 | if (typeof timeoutId === 'undefined') { 35 | timeoutId = setTimeout(function () { 36 | counter = 0 37 | timeoutId = undefined 38 | }, interval) 39 | } 40 | if (counter > limit && typeof onThrottle === 'function') { 41 | return onThrottle.apply(context, arguments) 42 | } else { 43 | return fn.apply(context, arguments) 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /packages/rum-core/src/error-logging/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import ErrorLogging from './error-logging' 27 | import { 28 | CONFIG_SERVICE, 29 | TRANSACTION_SERVICE, 30 | ERROR_LOGGING, 31 | APM_SERVER 32 | } from '../common/constants' 33 | import { serviceCreators } from '../common/service-factory' 34 | 35 | function registerServices() { 36 | serviceCreators[ERROR_LOGGING] = serviceFactory => { 37 | const [ 38 | apmServer, 39 | configService, 40 | transactionService 41 | ] = serviceFactory.getService([ 42 | APM_SERVER, 43 | CONFIG_SERVICE, 44 | TRANSACTION_SERVICE 45 | ]) 46 | return new ErrorLogging(apmServer, configService, transactionService) 47 | } 48 | } 49 | 50 | export { registerServices } 51 | -------------------------------------------------------------------------------- /packages/rum-core/src/opentracing/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import Tracer from './tracer' 27 | import Span from './span' 28 | import { 29 | TRANSACTION_SERVICE, 30 | LOGGING_SERVICE, 31 | PERFORMANCE_MONITORING, 32 | ERROR_LOGGING 33 | } from '../common/constants' 34 | 35 | function createTracer(serviceFactory) { 36 | var performanceMonitoring = serviceFactory.getService(PERFORMANCE_MONITORING) 37 | var transactionService = serviceFactory.getService(TRANSACTION_SERVICE) 38 | var errorLogging = serviceFactory.getService(ERROR_LOGGING) 39 | var loggingService = serviceFactory.getService(LOGGING_SERVICE) 40 | return new Tracer( 41 | performanceMonitoring, 42 | transactionService, 43 | loggingService, 44 | errorLogging 45 | ) 46 | } 47 | 48 | export { Span, Tracer, createTracer } 49 | -------------------------------------------------------------------------------- /packages/rum-core/src/performance-monitoring/navigation/user-timing.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { USER_TIMING_THRESHOLD } from '../../common/constants' 27 | import { shouldCreateSpan } from './utils' 28 | import Span from '../span' 29 | 30 | function createUserTimingSpans(entries, trStart, trEnd) { 31 | const userTimingSpans = [] 32 | for (let i = 0; i < entries.length; i++) { 33 | const { name, startTime, duration } = entries[i] 34 | const end = startTime + duration 35 | 36 | if ( 37 | duration <= USER_TIMING_THRESHOLD || 38 | !shouldCreateSpan(startTime, end, trStart, trEnd) 39 | ) { 40 | continue 41 | } 42 | const kind = 'app' 43 | const span = new Span(name, kind) 44 | span._start = startTime 45 | span.end(end) 46 | 47 | userTimingSpans.push(span) 48 | } 49 | return userTimingSpans 50 | } 51 | 52 | export { createUserTimingSpans } 53 | -------------------------------------------------------------------------------- /packages/rum-core/src/performance-monitoring/navigation/utils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { MAX_SPAN_DURATION } from '../../common/constants' 27 | 28 | /** 29 | * start, end, baseTime - unsigned long long(PerformanceTiming) 30 | * representing the moment, in milliseconds since the UNIX epoch 31 | * 32 | * trStart & trEnd - DOMHighResTimeStamp, measured in milliseconds. 33 | * 34 | * We have to convert the long values in milliseconds before doing the comparision 35 | * eg: end - baseTime <= transactionEnd 36 | */ 37 | function shouldCreateSpan(start, end, trStart, trEnd, baseTime = 0) { 38 | return ( 39 | typeof start === 'number' && 40 | typeof end === 'number' && 41 | start >= baseTime && 42 | end > start && 43 | start - baseTime >= trStart && 44 | end - baseTime <= trEnd && 45 | end - start < MAX_SPAN_DURATION && 46 | start - baseTime < MAX_SPAN_DURATION && 47 | end - baseTime < MAX_SPAN_DURATION 48 | ) 49 | } 50 | 51 | export { shouldCreateSpan } 52 | -------------------------------------------------------------------------------- /packages/rum-core/src/performance-monitoring/span.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import SpanBase from './span-base' 27 | import { addSpanContext } from '../common/context' 28 | 29 | class Span extends SpanBase { 30 | constructor(name, type, options) { 31 | super(name, type, options) 32 | this.parentId = this.options.parentId 33 | this.subtype = undefined 34 | this.action = undefined 35 | if (this.type.indexOf('.') !== -1) { 36 | var fields = this.type.split('.', 3) 37 | this.type = fields[0] 38 | this.subtype = fields[1] 39 | this.action = fields[2] 40 | } 41 | this.sync = this.options.sync 42 | } 43 | 44 | end(endTime, data) { 45 | super.end(endTime) 46 | addSpanContext(this, data) 47 | } 48 | } 49 | 50 | export default Span 51 | -------------------------------------------------------------------------------- /packages/rum-core/src/state.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const __DEV__ = process.env.NODE_ENV !== 'production' 27 | 28 | const state = { 29 | // Time when agent is bootstrapped and patching of modules happens 30 | bootstrapTime: null, 31 | // Time when the document is last backgrounded 32 | lastHiddenStart: Number.MIN_SAFE_INTEGER 33 | } 34 | 35 | export { __DEV__, state } 36 | -------------------------------------------------------------------------------- /packages/rum-core/test/benchmarks/breakdown.bench.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | import { captureBreakdown } from '../../src/performance-monitoring/breakdown' 26 | import Transaction from '../../src/performance-monitoring/transaction' 27 | import { PAGE_LOAD } from '../../src/common/constants' 28 | import { generateTestTransaction } from './' 29 | import { TIMING_LEVEL1_ENTRY } from '../fixtures/navigation-entries' 30 | 31 | suite('CaptureBreakdown', () => { 32 | benchmark('page-load transaction', () => { 33 | const pageLoadTr = new Transaction('/index', PAGE_LOAD, { 34 | startTime: 0, 35 | transactionSampleRate: 1 36 | }) 37 | pageLoadTr.end(5000) 38 | captureBreakdown(pageLoadTr, TIMING_LEVEL1_ENTRY) 39 | }) 40 | 41 | benchmark('other transaction', () => { 42 | const nonPageLoadTr = generateTestTransaction(10, true) 43 | captureBreakdown(nonPageLoadTr) 44 | }) 45 | }) 46 | -------------------------------------------------------------------------------- /packages/rum-core/test/common/http/response-status.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { isResponseSuccessful } from '../../../src/common/http/response-status' 27 | 28 | describe('isResponseSuccessful', () => { 29 | it('should return true if response status is 204', () => { 30 | expect(isResponseSuccessful(204)).toBe(true) 31 | }) 32 | 33 | it('should return false if response status is 500', () => { 34 | expect(isResponseSuccessful(500)).toBe(false) 35 | }) 36 | 37 | it('should return false if response status is 400', () => { 38 | expect(isResponseSuccessful(400)).toBe(false) 39 | }) 40 | }) 41 | -------------------------------------------------------------------------------- /packages/rum-core/test/common/ndjson.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import NDJSON from '../../src/common/ndjson' 27 | 28 | describe('NDJSON', function () { 29 | it('should stringify', function () { 30 | var result = NDJSON.stringify({ test: 'passed' }) 31 | expect(result).toBe('{"test":"passed"}\n') 32 | }) 33 | }) 34 | -------------------------------------------------------------------------------- /packages/rum-core/test/common/patch.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { patchAll } from '../../src/common/patching/' 27 | 28 | if (!window['__patchEventHandler']) { 29 | var nativeFetch = window.fetch 30 | if (nativeFetch) { 31 | window.fetch = function () { 32 | var delegate = window['__fetchDelegate'] 33 | if (typeof delegate === 'function') { 34 | return delegate.apply(this, arguments) 35 | } else { 36 | return nativeFetch.apply(this, arguments) 37 | } 38 | } 39 | } 40 | window['__patchEventHandler'] = patchAll() 41 | } 42 | 43 | export default window['__patchEventHandler'] 44 | -------------------------------------------------------------------------------- /packages/rum-core/test/fixtures/fid-entries.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | export default [ 27 | { 28 | name: 'mousedown', 29 | entryType: 'first-input', 30 | startTime: 5482.669999997597, 31 | duration: 16, 32 | processingStart: 5489.029999997001, 33 | processingEnd: 5489.0550000127405, 34 | cancelable: true 35 | } 36 | ] 37 | -------------------------------------------------------------------------------- /packages/rum-core/test/fixtures/lcp-entries.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | export default [ 27 | { 28 | renderTime: 298.51500000222586, 29 | loadTime: 295.4050000116695, 30 | size: 3000, 31 | id: '', 32 | url: 'http://example.com/logo.svg', 33 | element: null, // points to a DOM element 34 | name: '', 35 | entryType: 'largest-contentful-paint', 36 | startTime: 298.51500000222586, 37 | duration: 0 38 | }, 39 | { 40 | renderTime: 1040.0399999925867, 41 | loadTime: 0, 42 | size: 5250, 43 | id: '', 44 | url: '', 45 | element: null, 46 | name: '', 47 | entryType: 'largest-contentful-paint', 48 | startTime: 1040.0399999925867, 49 | duration: 0 50 | } 51 | ] 52 | -------------------------------------------------------------------------------- /packages/rum-core/test/fixtures/paint-entries.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | export const fcpEntries = [ 27 | { 28 | name: 'first-contentful-paint', 29 | entryType: 'paint', 30 | startTime: 128.5000000023283, 31 | duration: 0 32 | } 33 | ] 34 | -------------------------------------------------------------------------------- /packages/rum-core/test/fixtures/user-timing-entries.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | export default [ 27 | { 28 | duration: 1052.5299999972049, 29 | entryType: 'measure', 30 | name: 'measure_1', 31 | startTime: 0 32 | }, 33 | { 34 | duration: 2119.7900000006484, 35 | entryType: 'measure', 36 | name: 'measure_2', 37 | startTime: 0 38 | }, 39 | { 40 | duration: 2.4300000004586764, 41 | entryType: 'measure', 42 | name: 'measure_3', 43 | startTime: 1617.57999999827 44 | }, 45 | { 46 | duration: 8.760000000620494, 47 | entryType: 'measure', 48 | name: 'measure_4', 49 | startTime: 2110.949999998411 50 | }, 51 | { 52 | duration: 100.7900000006484, 53 | entryType: 'measure', 54 | name: 'measure_5', 55 | startTime: 0 56 | } 57 | ] 58 | -------------------------------------------------------------------------------- /packages/rum-core/test/mock-apm-server.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import express from 'express' 27 | 28 | const app = express() 29 | var port = 8201 30 | 31 | app.use(function (req, res, next) { 32 | res.header('Access-Control-Allow-Origin', '*') 33 | res.header( 34 | 'Access-Control-Allow-Headers', 35 | 'Origin, X-Requested-With, Content-Type, Accept' 36 | ) 37 | next() 38 | }) 39 | 40 | app.get('/healthcheck', function (req, res) { 41 | res.send('OK') 42 | }) 43 | 44 | function respondSuccess(req, res) { 45 | res.status(202).end() 46 | } 47 | 48 | // app.post('/v1/client-side/*', respondSuccess) 49 | app.post('/v1/client-side/transactions', respondSuccess) 50 | app.post('/v1/client-side/errors', respondSuccess) 51 | app.post('/v1/rum/*', respondSuccess) 52 | 53 | app.listen(port) 54 | 55 | console.log('serving MockApmServer on: ', port) 56 | -------------------------------------------------------------------------------- /packages/rum-core/test/performance-monitoring/span-base.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import SpanBase from '../../src/performance-monitoring/span-base' 27 | 28 | describe('SpanBase', function () { 29 | it('should add default name and type for span', () => { 30 | const span = new SpanBase('', undefined) 31 | 32 | expect(span.name).toEqual('Unknown') 33 | expect(span.type).toEqual('custom') 34 | }) 35 | 36 | it('should addLabels', function () { 37 | var span = new SpanBase() 38 | span.addLabels({ test: 'passed', 'test.new': 'new' }) 39 | expect(span.context).toEqual({ 40 | tags: { test: 'passed', test_new: 'new' } 41 | }) 42 | }) 43 | 44 | it('should addContext', function () { 45 | var span = new SpanBase() 46 | span.addContext({ test: { ctx: 'hamid' } }) 47 | expect(span.context).toEqual({ test: { ctx: 'hamid' } }) 48 | }) 49 | }) 50 | -------------------------------------------------------------------------------- /packages/rum-core/test/performance-monitoring/span.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import Span from '../../src/performance-monitoring/span' 27 | 28 | describe('Span', function () { 29 | it('should return null for duration if not ended', function () { 30 | var s = new Span('test', 'test') 31 | expect(s.duration()).toBe(null) 32 | }) 33 | 34 | it('should support dot delimiter in span types', function () { 35 | var s1 = new Span('test1', 'db.mysql.query') 36 | expect(s1.type).toBe('db') 37 | expect(s1.subtype).toBe('mysql') 38 | expect(s1.action).toBe('query') 39 | 40 | var s2 = new Span('test2', 'db-query') 41 | expect(s2.type).toBe('db-query') 42 | expect(s2.subtype).toBe(undefined) 43 | expect(s2.action).toBe(undefined) 44 | }) 45 | }) 46 | -------------------------------------------------------------------------------- /packages/rum-core/test/polyfills.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import 'promise-polyfill/src/polyfill' 27 | import 'core-js/features/array/map' 28 | import 'core-js/features/string/pad-end' 29 | 30 | Object.setPrototypeOf = 31 | Object.setPrototypeOf || 32 | function (obj, proto) { 33 | obj.__proto__ = proto 34 | return obj 35 | } 36 | -------------------------------------------------------------------------------- /packages/rum-core/test/run-apm-server.sh: -------------------------------------------------------------------------------- 1 | ELASTICSEARCH_PORT=9201 STACK_VERSION=6.4.0 APM_SERVER_PORT=8001 docker compose up apm-server kibana 2 | -------------------------------------------------------------------------------- /packages/rum-react/README.md: -------------------------------------------------------------------------------- 1 | # Elastic APM Real User Monitoring (RUM) for React applications 2 | 3 | This package provides Real User Monitoring (RUM) for React applications. 4 | 5 | ## Documentation 6 | You can find our documentation [on our website](https://www.elastic.co/guide/en/apm/agent/rum-js/current/index.html). 7 | 8 | If you are interested in contributing to Elastic APM JavaScript agent, please see [our contributing guide](CONTRIBUTING.md). 9 | 10 | 11 | ## License 12 | This project is [MIT licensed](LICENSE). 13 | 14 |
Made with ♥️ and ☕️ by Elastic and our community.
-------------------------------------------------------------------------------- /packages/rum-react/babel.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const { getBabelConfig, PACKAGE_TYPES } = require('../../dev-utils/build') 27 | 28 | module.exports = function (api) { 29 | /** 30 | * Reads BABEL_ENV to decide between CJS and ESM formats 31 | */ 32 | const env = api.env() 33 | return getBabelConfig(env, PACKAGE_TYPES.REACT) 34 | } 35 | -------------------------------------------------------------------------------- /packages/rum-react/karma.conf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const { baseConfig, prepareConfig } = require('../../dev-utils/karma.js') 27 | const { getBrowserList } = require('../../dev-utils/test-config') 28 | const { 29 | getWebpackConfig, 30 | PACKAGE_TYPES, 31 | BUNDLE_TYPES 32 | } = require('../../dev-utils/build') 33 | 34 | module.exports = function (config) { 35 | config.set(baseConfig) 36 | config.set({ 37 | webpack: getWebpackConfig(BUNDLE_TYPES.BROWSER_DEV, PACKAGE_TYPES.REACT), 38 | customLaunchers: getBrowserList('react').map(launcher => ({ 39 | ...launcher, 40 | base: 'SauceLabs' 41 | })) 42 | }) 43 | const preparedConfig = prepareConfig(config, 'rum-react') 44 | config.set(preparedConfig) 45 | } 46 | -------------------------------------------------------------------------------- /packages/rum-react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@elastic/apm-rum-react", 3 | "version": "2.0.6", 4 | "description": "Elastic APM Real User Monitoring for React applications", 5 | "author": "Hamid ", 6 | "homepage": "https://www.elastic.co/guide/en/apm/agent/rum-js/current/index.html", 7 | "license": "MIT", 8 | "main": "dist/lib/index.js", 9 | "module": "dist/es/index.js", 10 | "source": "src/index.js", 11 | "files": [ 12 | "dist", 13 | "src" 14 | ], 15 | "engines": { 16 | "node": ">=8.0.0" 17 | }, 18 | "publishConfig": { 19 | "access": "public" 20 | }, 21 | "repository": { 22 | "type": "git", 23 | "url": "git+https://github.com/elastic/apm-agent-rum-js.git", 24 | "directory": "packages/rum-react" 25 | }, 26 | "scripts": { 27 | "prepublishOnly": "npm run build", 28 | "build": "run-p build:main build:module", 29 | "build:main": "BABEL_ENV=BROWSER_PROD npx babel src -d dist/lib", 30 | "build:module": "BABEL_ENV=BROWSER_ESM_PROD npx babel src -d dist/es", 31 | "build:e2e": "npm run script buildE2eBundles packages/rum-react/test/e2e", 32 | "karma:dev": "karma start --auto-watch --restartOnFileChange", 33 | "karma:coverage": "karma start --coverage --singleRun", 34 | "test:unit": "npm run script runUnitTests packages/rum-react", 35 | "test:e2e": "npm run script runE2eTests packages/rum-react/wdio.conf.js", 36 | "test:sauce": "npm run script runSauceTests packages/rum-react true build:e2e test:unit test:e2e", 37 | "test": "npm run test:sauce", 38 | "script": "node ../../dev-utils/run-script.js" 39 | }, 40 | "bugs": { 41 | "url": "https://github.com/elastic/apm-agent-rum-js/issues" 42 | }, 43 | "dependencies": { 44 | "@elastic/apm-rum": "file:../rum", 45 | "hoist-non-react-statics": "^3.3.0" 46 | }, 47 | "peerDependencies": { 48 | "react": ">16.0.0", 49 | "react-router-dom": ">=6.0.0" 50 | }, 51 | "browserslist": [ 52 | "ie 11" 53 | ] 54 | } 55 | -------------------------------------------------------------------------------- /packages/rum-react/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { apm } from '@elastic/apm-rum' 27 | import { getWithTransaction } from './get-with-transaction' 28 | import { getApmRoutes } from './get-apm-routes' 29 | 30 | const withTransaction = getWithTransaction(apm) 31 | const ApmRoutes = getApmRoutes(apm) 32 | 33 | export { withTransaction, ApmRoutes } 34 | -------------------------------------------------------------------------------- /packages/rum-react/test/e2e/components/func-component.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import React, { useEffect, useState, Suspense, lazy } from 'react' 27 | 28 | const LazyComponent = lazy(() => import('./lazy-component')) 29 | 30 | export default function FunctionalComponent(props) { 31 | const [count, setCount] = useState(0) 32 | 33 | useEffect(() => { 34 | async function dummyGet() { 35 | try { 36 | await fetch('/test/e2e/data.json') 37 | } catch (_) { 38 | } finally { 39 | setCount(2) 40 | } 41 | } 42 | 43 | dummyGet() 44 | }, []) 45 | 46 | return ( 47 |
48 | {props.path + '\n'} {count} 49 | Loading...
}> 50 | 51 | 52 | 53 | ) 54 | } 55 | -------------------------------------------------------------------------------- /packages/rum-react/test/e2e/components/lazy-component.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import React from 'react' 27 | 28 | export default function lazyComponent() { 29 | return
lazy component rendered
30 | } 31 | -------------------------------------------------------------------------------- /packages/rum-react/test/e2e/components/manual-component.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import React from 'react' 27 | import { withTransaction } from '../../../src' 28 | 29 | class ManualComponent extends React.Component { 30 | constructor(props) { 31 | super(props) 32 | this.state = { 33 | userName: '' 34 | } 35 | } 36 | 37 | componentDidMount() { 38 | const url = '/test/e2e/data.json' 39 | fetch(url) 40 | .then(resp => resp.json()) 41 | .then(data => this.setState({ userName: data.userName })) 42 | 43 | if (typeof performance.measure === 'function') { 44 | performance.measure('manual-component-mounted', 'manual-component-start') 45 | } 46 | } 47 | 48 | render() { 49 | return
Manual {this.state.userName}
50 | } 51 | } 52 | 53 | export default withTransaction('ManualComponent', 'component')(ManualComponent) 54 | -------------------------------------------------------------------------------- /packages/rum-react/test/e2e/components/topic-component.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import React from 'react' 27 | 28 | class TopicComponent extends React.Component { 29 | constructor(props) { 30 | super(props) 31 | this.state = { 32 | userName: '' 33 | } 34 | } 35 | 36 | componentDidMount() { 37 | var url = '/test/e2e/data.json' 38 | fetch(url) 39 | .then(resp => resp.json()) 40 | .then(data => this.setState({ userName: data.userName })) 41 | } 42 | 43 | render() { 44 | return ( 45 |
46 |

47 | {this.props.path} 48 |

49 | {this.state.userName} 50 |
51 | ) 52 | } 53 | } 54 | 55 | export default TopicComponent 56 | -------------------------------------------------------------------------------- /packages/rum-react/test/e2e/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "userName": "hamid" 3 | } -------------------------------------------------------------------------------- /packages/rum-react/test/e2e/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import 'promise-polyfill/src/polyfill' 27 | import { apmBase } from '@elastic/apm-rum' 28 | import { APM_SERVER } from '@elastic/apm-rum-core' 29 | import { getGlobalConfig } from '../../../../dev-utils/test-config' 30 | import ApmServerMock from '../../../rum-core/test/utils/apm-server-mock' 31 | 32 | const globalConfig = getGlobalConfig() 33 | 34 | export default function createApmBase(config) { 35 | console.log('E2E Global Configs', JSON.stringify(globalConfig, null, 2)) 36 | const apmServer = apmBase.serviceFactory.getService(APM_SERVER) 37 | const { serverUrl } = globalConfig.agentConfig 38 | config.serverUrl = serverUrl 39 | const serverMock = new ApmServerMock(apmServer, globalConfig.useMocks) 40 | apmBase.serviceFactory.instances[APM_SERVER] = serverMock 41 | 42 | return apmBase.init(config) 43 | } 44 | -------------------------------------------------------------------------------- /packages/rum-react/test/e2e/with-router/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | React test 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /packages/rum-react/test/e2e/with-router/routes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | React test 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /packages/rum-react/test/e2e/with-router/webpack.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const path = require('path') 27 | const { 28 | getWebpackConfig, 29 | PACKAGE_TYPES, 30 | BUNDLE_TYPES, 31 | WEBPACK_HASH_FN 32 | } = require('../../../../../dev-utils/build') 33 | 34 | module.exports = { 35 | entry: { 36 | general: path.join(__dirname, 'general.js'), 37 | routes: path.join(__dirname, 'routes.js') 38 | }, 39 | output: { 40 | path: path.resolve(__dirname), 41 | filename: '[name].e2e-bundle.js', 42 | libraryTarget: 'umd', 43 | hashFunction: WEBPACK_HASH_FN 44 | }, 45 | ...getWebpackConfig(BUNDLE_TYPES.BROWSER_DEV, PACKAGE_TYPES.REACT) 46 | } 47 | -------------------------------------------------------------------------------- /packages/rum-react/test/polyfills.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | /** 27 | * Polyfills for unsupported browsers 28 | * - Symbol is used by Cheerio, which is an Enzyme dependency 29 | */ 30 | 31 | import 'core-js/es/symbol' 32 | -------------------------------------------------------------------------------- /packages/rum-react/wdio.conf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const { getWebdriveBaseConfig } = require('../../dev-utils/webdriver') 27 | const { getBrowserList } = require('../../dev-utils/test-config') 28 | 29 | exports.config = getWebdriveBaseConfig( 30 | __dirname, 31 | './test/e2e/**/*.e2e-spec.js', 32 | getBrowserList('react') 33 | ) 34 | -------------------------------------------------------------------------------- /packages/rum-vue/README.md: -------------------------------------------------------------------------------- 1 | # Elastic APM Real User Monitoring (RUM) for Vue applications 2 | 3 | This package provides Real User Monitoring (RUM) for Vue applications. 4 | 5 | ### Installation 6 | 7 | ``` 8 | npm install @elastic/apm-rum-vue 9 | ``` 10 | 11 | ## Documentation 12 | You can find our documentation [on our website](https://www.elastic.co/guide/en/apm/agent/rum-js/current/index.html). 13 | 14 | If you are interested in contributing to Elastic APM JavaScript agent, please see [our contributing guide](CONTRIBUTING.md). 15 | 16 | 17 | ## License 18 | This project is [MIT licensed](LICENSE). 19 | 20 |
Made with ♥️ and ☕️ by Elastic and our community.
21 | ``` 22 | -------------------------------------------------------------------------------- /packages/rum-vue/babel.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const { getBabelConfig } = require('../../dev-utils/build') 27 | 28 | module.exports = function (api) { 29 | const env = api.env() 30 | return getBabelConfig(env) 31 | } 32 | -------------------------------------------------------------------------------- /packages/rum-vue/karma.conf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const { baseConfig, prepareConfig } = require('../../dev-utils/karma') 27 | const { getBrowserList } = require('../../dev-utils/test-config') 28 | const { 29 | getWebpackConfig, 30 | PACKAGE_TYPES, 31 | BUNDLE_TYPES 32 | } = require('../../dev-utils/build') 33 | 34 | module.exports = function (config) { 35 | config.set(baseConfig) 36 | config.set({ 37 | webpack: getWebpackConfig(BUNDLE_TYPES.BROWSER_DEV, PACKAGE_TYPES.VUE), 38 | customLaunchers: getBrowserList('vue').map(launcher => ({ 39 | ...launcher, 40 | base: 'SauceLabs' 41 | })) 42 | }) 43 | const preparedConfig = prepareConfig(config, 'rum-vue') 44 | config.set(preparedConfig) 45 | } 46 | -------------------------------------------------------------------------------- /packages/rum-vue/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@elastic/apm-rum-vue", 3 | "version": "2.1.10", 4 | "description": "Elastic APM Real User Monitoring for Vue applications", 5 | "keywords": [ 6 | "elastic", 7 | "apm", 8 | "vue", 9 | "vue-router" 10 | ], 11 | "homepage": "https://www.elastic.co/guide/en/apm/agent/rum-js/current/index.html", 12 | "license": "MIT", 13 | "main": "dist/lib/index.js", 14 | "module": "dist/es/index.js", 15 | "source": "src/index.js", 16 | "files": [ 17 | "dist", 18 | "src" 19 | ], 20 | "engines": { 21 | "node": ">=8.0.0" 22 | }, 23 | "scripts": { 24 | "prepublishOnly": "npm run build", 25 | "build": "run-p build:main build:module", 26 | "build:main": "BABEL_ENV=BROWSER_PROD npx babel src -d dist/lib", 27 | "build:module": "BABEL_ENV=BROWSER_ESM_PROD npx babel src -d dist/es", 28 | "build:e2e": "npm run script buildE2eBundles packages/rum-vue/test/e2e", 29 | "karma:dev": "karma start --auto-watch --restartOnFileChange", 30 | "karma:coverage": "karma start --coverage --singleRun", 31 | "test:unit": "npm run script runUnitTests packages/rum-vue", 32 | "test:e2e": "npm run script runE2eTests packages/rum-vue/wdio.conf.js", 33 | "test:sauce": "npm run script runSauceTests packages/rum-vue true build:e2e test:unit test:e2e", 34 | "test": "npm run test:sauce", 35 | "script": "node ../../dev-utils/run-script.js" 36 | }, 37 | "publishConfig": { 38 | "access": "public" 39 | }, 40 | "repository": { 41 | "type": "git", 42 | "url": "https://github.com/elastic/apm-agent-rum-js.git", 43 | "directory": "packages/rum-vue" 44 | }, 45 | "bugs": { 46 | "url": "https://github.com/elastic/apm-agent-rum-js/issues" 47 | }, 48 | "dependencies": { 49 | "@elastic/apm-rum": "file:../rum", 50 | "@elastic/apm-rum-core": "file:../rum-core" 51 | }, 52 | "browserslist": [ 53 | "ie 11" 54 | ] 55 | } 56 | -------------------------------------------------------------------------------- /packages/rum-vue/test/e2e/App.vue: -------------------------------------------------------------------------------- 1 | 14 | -------------------------------------------------------------------------------- /packages/rum-vue/test/e2e/components/Fetch.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 49 | -------------------------------------------------------------------------------- /packages/rum-vue/test/e2e/components/Lazy.vue: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/rum-vue/test/e2e/components/Syntax.vue: -------------------------------------------------------------------------------- 1 | 5 | 6 | 12 | -------------------------------------------------------------------------------- /packages/rum-vue/test/e2e/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "msg": "loaded data.json" 3 | } 4 | -------------------------------------------------------------------------------- /packages/rum-vue/test/e2e/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Vue E2E test 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /packages/rum-vue/test/e2e/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import 'promise-polyfill/src/polyfill' 27 | import { apmBase } from '@elastic/apm-rum' 28 | import { APM_SERVER } from '@elastic/apm-rum-core' 29 | import { getGlobalConfig } from '../../../../dev-utils/test-config' 30 | import ApmServerMock from '@elastic/apm-rum-core/test/utils/apm-server-mock' 31 | 32 | const globalConfig = getGlobalConfig() 33 | 34 | export function getApmBase() { 35 | console.log('E2E Global Configs', JSON.stringify(globalConfig, null, 2)) 36 | const apmServer = apmBase.serviceFactory.getService(APM_SERVER) 37 | const serverMock = new ApmServerMock(apmServer, globalConfig.useMocks) 38 | apmBase.serviceFactory.instances[APM_SERVER] = serverMock 39 | return apmBase 40 | } 41 | 42 | export function getServerUrl() { 43 | return globalConfig.agentConfig.serverUrl 44 | } 45 | -------------------------------------------------------------------------------- /packages/rum-vue/test/e2e/webpack.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const path = require('path') 27 | const { 28 | getWebpackConfig, 29 | BUNDLE_TYPES, 30 | PACKAGE_TYPES, 31 | WEBPACK_HASH_FN 32 | } = require('../../../../dev-utils/build') 33 | 34 | module.exports = { 35 | entry: { 36 | app: path.join(__dirname, 'app.js') 37 | }, 38 | output: { 39 | path: path.resolve(__dirname), 40 | filename: 'app.e2e-bundle.js', 41 | hashFunction: WEBPACK_HASH_FN 42 | }, 43 | ...getWebpackConfig(BUNDLE_TYPES.BROWSER_DEV, PACKAGE_TYPES.VUE) 44 | } 45 | -------------------------------------------------------------------------------- /packages/rum-vue/test/polyfills.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | /** 27 | * Polyfills for unsupported browsers 28 | * - Object.assign is used in @vue/test-utils 29 | */ 30 | import 'core-js/es/object/assign' 31 | -------------------------------------------------------------------------------- /packages/rum-vue/wdio.conf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const { getWebdriveBaseConfig } = require('../../dev-utils/webdriver') 27 | const { getBrowserList } = require('../../dev-utils/test-config') 28 | 29 | exports.config = getWebdriveBaseConfig( 30 | __dirname, 31 | './test/e2e/**/*.e2e-spec.js', 32 | getBrowserList('vue') 33 | ) 34 | -------------------------------------------------------------------------------- /packages/rum/README.md: -------------------------------------------------------------------------------- 1 | # Elastic APM Real User Monitoring (RUM) JavaScript agent 2 | 3 | This is the main package for Elastic APM Real User Monitoring. 4 | 5 | ## Documentation 6 | You can find our documentation [on our website](https://www.elastic.co/guide/en/apm/agent/rum-js/current/index.html). 7 | 8 | If you are interested in contributing to Elastic APM JavaScript agent, please see [our contributing guide](CONTRIBUTING.md). 9 | 10 | We'd love to hear your feedback, please take a minute to fill out our [survey](https://goo.gl/forms/nLCXGCvziqalzjlP2). 11 | 12 | 13 | ## License 14 | This project is [MIT licensed](LICENSE). 15 | 16 |
Made with ♥️ and ☕️ by Elastic and our community.
-------------------------------------------------------------------------------- /packages/rum/babel.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const { getBabelConfig } = require('../../dev-utils/build') 27 | 28 | module.exports = function (api) { 29 | const env = api.env() 30 | return getBabelConfig(env) 31 | } 32 | -------------------------------------------------------------------------------- /packages/rum/karma.conf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const { baseConfig, prepareConfig } = require('../../dev-utils/karma.js') 27 | 28 | module.exports = function (config) { 29 | config.set(baseConfig) 30 | const preparedConfig = prepareConfig(config, 'rum') 31 | config.set(preparedConfig) 32 | } 33 | -------------------------------------------------------------------------------- /packages/rum/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { 27 | createServiceFactory, 28 | bootstrap, 29 | isBrowser 30 | } from '@elastic/apm-rum-core' 31 | import ApmBase from './apm-base' 32 | 33 | /** 34 | * Use a single instance of ApmBase across all instance of the agent 35 | * including the instances used in framework specific integrations 36 | */ 37 | function getApmBase() { 38 | if (isBrowser && window.elasticApm) { 39 | return window.elasticApm 40 | } 41 | const enabled = bootstrap() 42 | const serviceFactory = createServiceFactory() 43 | const apmBase = new ApmBase(serviceFactory, !enabled) 44 | 45 | if (isBrowser) { 46 | window.elasticApm = apmBase 47 | } 48 | 49 | return apmBase 50 | } 51 | 52 | const apmBase = getApmBase() 53 | 54 | const init = apmBase.init.bind(apmBase) 55 | 56 | export default init 57 | export { init, apmBase, ApmBase, apmBase as apm } 58 | -------------------------------------------------------------------------------- /packages/rum/src/opentracing.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { init, apm, apmBase, ApmBase } from './index' 27 | import { Tracer } from 'opentracing/lib/tracer' 28 | import { createTracer as createElasticTracer } from '@elastic/apm-rum-core' 29 | 30 | function createTracer(apmBase) { 31 | /** 32 | * If the platform is not supported, return 33 | * the default tracer from OT 34 | */ 35 | if (apmBase._disable) { 36 | return new Tracer() 37 | } 38 | return createElasticTracer(apmBase.serviceFactory) 39 | } 40 | 41 | if (typeof window !== 'undefined' && window.elasticApm) { 42 | window.elasticApm.createTracer = createTracer.bind( 43 | window.elasticApm, 44 | window.elasticApm 45 | ) 46 | } 47 | 48 | export default createTracer 49 | export { createTracer, init, apm, apmBase, ApmBase } 50 | -------------------------------------------------------------------------------- /packages/rum/test/benchmarks/config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const port = 9000 27 | module.exports = { 28 | scenarios: ['basic', 'heavy'], 29 | runs: 3, 30 | noOfImages: 30, 31 | browserTypes: ['chromium', 'firefox', 'webkit'], 32 | port, 33 | default: { 34 | launchOptions: { 35 | headless: true, 36 | dumpio: true 37 | } 38 | }, 39 | chromium: { 40 | /** 41 | * By default the CPU samples are taken at 1000 microseconds, To get 42 | * more samples in each run within page-load event, we have to tune it so that 43 | * number of samples are more than 50 to get clear idea of the overall profile 44 | * 45 | * https://chromedevtools.github.io/devtools-protocol/tot/Profiler#method-setSamplingInterval 46 | */ 47 | cpuSamplingInterval: 200, 48 | memorySamplingInterval: 10, 49 | launchOptions: { 50 | headless: true, 51 | args: ['--no-sandbox', '--disable-setuid-sandbox'] 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /packages/rum/test/benchmarks/pages/basic.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%- include('head') -%> 4 | 5 | <%- include('init') -%> 6 | 7 | 8 | -------------------------------------------------------------------------------- /packages/rum/test/benchmarks/pages/head.ejs: -------------------------------------------------------------------------------- 1 | 2 | Elastic APM RUM agent Benchmarks 3 | 4 | 5 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /packages/rum/test/benchmarks/pages/heavy.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%- include('head') -%> 4 | 5 | <% for(var i=0; i < images.length; i++) { %> 6 | 7 | <% } %> <%- include('init') -%> 8 | 9 | 10 | -------------------------------------------------------------------------------- /packages/rum/test/benchmarks/pages/init.ejs: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /packages/rum/test/e2e/async-tests/app.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { testXHR, renderTestElement } from '../utils' 27 | import { getGlobalConfig } from '../../../../../dev-utils/test-config' 28 | 29 | const { mockBackendUrl } = getGlobalConfig().testConfig 30 | 31 | /** 32 | * Currently, XHR call will not be captured as Spans by the agent 33 | * since agent script is loaded asynchronously and we will not be able to patch 34 | * XHR and FETCH calls on time 35 | */ 36 | testXHR(mockBackendUrl, renderTestElement, false) 37 | -------------------------------------------------------------------------------- /packages/rum/test/e2e/async-tests/index.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Async Test 5 | 6 | 7 | 39 | 40 | 41 | 42 |
Async test for RUM
43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /packages/rum/test/e2e/bundle-test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Bundle test 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /packages/rum/test/e2e/common/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "userName": "hamid" 3 | } -------------------------------------------------------------------------------- /packages/rum/test/e2e/general-usecase/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | General Usecase test 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /packages/rum/test/e2e/general-usecase/webpack.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const { join, resolve } = require('path') 27 | const { 28 | getWebpackConfig, 29 | BUNDLE_TYPES, 30 | WEBPACK_HASH_FN 31 | } = require('../../../../../dev-utils/build') 32 | 33 | module.exports = { 34 | entry: join(__dirname, 'app.js'), 35 | output: { 36 | filename: 'app.e2e-bundle.min.js', 37 | path: resolve(__dirname), 38 | libraryTarget: 'umd', 39 | hashFunction: WEBPACK_HASH_FN 40 | }, 41 | ...getWebpackConfig(BUNDLE_TYPES.BROWSER_PROD) 42 | } 43 | -------------------------------------------------------------------------------- /packages/rum/test/e2e/manual-timing/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Manual Timing test 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /packages/rum/test/e2e/manual-timing/webpack.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const { join, resolve } = require('path') 27 | const { 28 | getWebpackConfig, 29 | BUNDLE_TYPES, 30 | WEBPACK_HASH_FN 31 | } = require('../../../../../dev-utils/build') 32 | 33 | module.exports = { 34 | entry: join(__dirname, './app.js'), 35 | output: { 36 | path: resolve(__dirname), 37 | filename: 'app.e2e-bundle.js', 38 | libraryTarget: 'umd', 39 | hashFunction: WEBPACK_HASH_FN 40 | }, 41 | ...getWebpackConfig(BUNDLE_TYPES.BROWSER_DEV) 42 | } 43 | -------------------------------------------------------------------------------- /packages/rum/test/e2e/standalone-html/base.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { testXHR, renderTestElement } from '../utils' 27 | import { getGlobalConfig } from '../../../../../dev-utils/test-config' 28 | 29 | const { serverUrl, mockBackendUrl } = getGlobalConfig().testConfig 30 | 31 | window.elasticApm.init({ 32 | serviceName: 'standalone-html', 33 | serverUrl, 34 | distributedTracingOrigins: [mockBackendUrl], 35 | pageLoadTransactionName: '/' 36 | }) 37 | 38 | testXHR(mockBackendUrl, renderTestElement) 39 | -------------------------------------------------------------------------------- /packages/rum/test/e2e/standalone-html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | test 5 | 6 | 7 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /packages/rum/test/e2e/standalone-html/opentracing.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | test 5 | 6 | 7 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /packages/rum/test/e2e/standalone-html/opentracing.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { testXHR, renderTestElement } from '../utils' 27 | import { getGlobalConfig } from '../../../../../dev-utils/test-config' 28 | 29 | const { serverUrl, mockBackendUrl } = getGlobalConfig().testConfig 30 | 31 | window.elasticApm.init({ 32 | serviceName: 'standalone-html', 33 | serverUrl, 34 | distributedTracingOrigins: [mockBackendUrl], 35 | pageLoadTransactionName: '/' 36 | }) 37 | 38 | const tracer = window.elasticApm.createTracer() 39 | const span = tracer.startSpan('Opentracing span') 40 | span && span.finish(Date.now() + 100) 41 | 42 | testXHR(mockBackendUrl, renderTestElement) 43 | -------------------------------------------------------------------------------- /packages/rum/test/e2e/standalone-html/webpack.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const path = require('path') 27 | const { 28 | getWebpackConfig, 29 | BUNDLE_TYPES 30 | } = require('../../../../../dev-utils/build') 31 | 32 | module.exports = { 33 | entry: { 34 | base: path.join(__dirname, 'base'), 35 | opentracing: path.join(__dirname, 'opentracing') 36 | }, 37 | output: { 38 | path: path.resolve(__dirname), 39 | filename: '[name].e2e-bundle.js', 40 | libraryTarget: 'umd' 41 | }, 42 | ...getWebpackConfig(BUNDLE_TYPES.BROWSER_DEV) 43 | } 44 | -------------------------------------------------------------------------------- /packages/rum/test/integration/babel.helper.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const configFile = require.resolve('../../babel.config') 27 | 28 | require('@babel/register')({ configFile }) 29 | -------------------------------------------------------------------------------- /packages/rum/test/integration/index.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import { apmBase } from '../../src' 27 | import { getGlobalConfig } from '../../../../dev-utils/test-config' 28 | 29 | const { agentConfig } = getGlobalConfig() 30 | 31 | describe('ApmBase', function () { 32 | it('should not init ApmBase', function () { 33 | apmBase.init(agentConfig) 34 | try { 35 | throw new Error('ApmBase test error') 36 | } catch (error) { 37 | var result = apmBase.captureError(error) 38 | expect(result).toBeUndefined() 39 | } 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /packages/rum/test/integration/integration-test.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | import request from 'request' 27 | 28 | describe('integration-test', function () { 29 | it('should run integration test', function (done) { 30 | request.get( 31 | { 32 | url: 'http://localhost:8000/run_integration_test?echo=done' 33 | }, 34 | function (err, resp, body) { 35 | if (err || (resp.statusCode !== 200 && resp.statusCode !== 202)) { 36 | var message = `Integration test failed, error: ${err}, response: ${ 37 | resp && resp.statusCode 38 | }, body: ${body}` 39 | fail(message) 40 | } 41 | done() 42 | } 43 | ) 44 | }) 45 | }) 46 | -------------------------------------------------------------------------------- /packages/rum/test/node/opentracing-export.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | const opentracing = require('@elastic/apm-rum/dist/lib/opentracing') 26 | const { 27 | init, 28 | apm, 29 | apmBase, 30 | ApmBase, 31 | createTracer 32 | } = require('@elastic/apm-rum/dist/lib/opentracing') 33 | 34 | describe('opentracing', () => { 35 | it('should have default and named exports', () => { 36 | expect(opentracing.default).toEqual(jasmine.any(Function)) 37 | expect(createTracer).toEqual(jasmine.any(Function)) 38 | expect(init).toEqual(jasmine.any(Function)) 39 | expect(apm).toEqual(jasmine.any(Object)) 40 | expect(apmBase).toEqual(jasmine.any(Object)) 41 | expect(apmBase.init).toEqual(jasmine.any(Function)) 42 | expect(ApmBase).toEqual(jasmine.any(Function)) 43 | }) 44 | }) 45 | -------------------------------------------------------------------------------- /packages/rum/test/run-apm-server.sh: -------------------------------------------------------------------------------- 1 | #docker run -p 127.0.0.1:8200:8201 elastic/apm-server:6.2.4 /bin/sh -c "apm-server -e -E output.elasticsearch.password=$(ELASTICSEARCH_PASSWORD) -E output.elasticsearch.username=$(ELASTICSEARCH_USERNAME) -E output.elasticsearch.hosts=['$(ELASTICSEARCH_SERVICE_HOST):$(ELASTICSEARCH_SERVICE_PORT)'] -E apm-server.expvar.enabled=true -E apm-server.frontend.enabled=true -E apm-server.frontend.rate_limit=100000 -E apm-server.host=0.0.0.0:8200 -E apm-server.read_timeout=1m -E apm-server.shutdown_timeout=2m -E apm-server.write_timeout=1m" 2 | STACK_VERSION=6.2.4 APM_SERVER_PORT=8001 docker compose up apm-server 3 | #STACK_VERSION=6.2.4 docker compose -f ./test/docker compose.yml start apm-server 4 | -------------------------------------------------------------------------------- /packages/rum/test/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "commonjs", 5 | "noEmit": true, 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "allowJs": true, 11 | "checkJs": true, 12 | "strict": true, 13 | "esModuleInterop": true, 14 | "skipLibCheck": true, 15 | }, 16 | "include": ["*.ts"] 17 | } 18 | -------------------------------------------------------------------------------- /packages/rum/wdio-failsafe.conf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const { join } = require('path') 27 | const glob = require('glob') 28 | const { config } = require('./wdio.conf') 29 | const { getSauceConnectOptions } = require('../../dev-utils/test-config') 30 | 31 | const { tunnelIdentifier } = getSauceConnectOptions() 32 | const browserList = [ 33 | { 34 | browserName: 'internet explorer', 35 | platformName: 'Windows 7', 36 | browserVersion: '10', 37 | 'sauce:options': { 38 | tunnelIdentifier 39 | } 40 | } 41 | ] 42 | 43 | exports.config = Object.assign({}, config, { 44 | specs: glob.sync(join(__dirname, '/test/e2e/**/*failsafe.js')), 45 | capabilities: browserList 46 | }) 47 | -------------------------------------------------------------------------------- /packages/rum/wdio.conf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const { getWebdriveBaseConfig } = require('../../dev-utils/webdriver') 27 | 28 | exports.config = getWebdriveBaseConfig(__dirname) 29 | -------------------------------------------------------------------------------- /scripts/build_docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | name=$1 6 | path=$2 7 | build_dir=$3 8 | 9 | docs_dir=$build_dir/docs 10 | html_dir=$build_dir/html_docs 11 | 12 | # Checks if docs clone already exists 13 | if [ ! -d $docs_dir ]; then 14 | # Only head is cloned 15 | git clone --depth=1 https://github.com/elastic/docs.git $docs_dir 16 | else 17 | echo "$docs_dir already exists. Not cloning." 18 | fi 19 | 20 | 21 | index="${path}/index.asciidoc" 22 | 23 | echo "Building docs for ${name}..." 24 | echo "Index document: ${index}" 25 | 26 | dest_dir="$html_dir/${name}" 27 | mkdir -p "$dest_dir" 28 | params="--chunk=1" 29 | if [ "$PREVIEW" = "1" ]; then 30 | params="$params --open" 31 | fi 32 | $docs_dir/build_docs $params --doc "$index" --out "$dest_dir" 33 | -------------------------------------------------------------------------------- /scripts/ci-bundlesize.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Bash strict mode 4 | set -eo pipefail 5 | trap 's=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR 6 | 7 | # Create a tmp dir 8 | WORKSPACE=$(mktemp -d) 9 | BUNDLESIZE_PATH="${WORKSPACE}/bundlesize.txt" 10 | 11 | # Execute bundlesize 12 | npm run bundlesize | tee "${BUNDLESIZE_PATH}" || true 13 | 14 | # Extract passed and failed 15 | BUNDLESIZE_PASS=$(grep "✔" "${BUNDLESIZE_PATH}" | wc -l) || true 16 | BUNDLESIZE_FAIL=$(grep "✖" "${BUNDLESIZE_PATH}" | wc -l) || true 17 | if [ ! -z "${GITHUB_OUTPUT}" ]; then 18 | echo "bundlesize_pass=${BUNDLESIZE_PASS}" >> "${GITHUB_OUTPUT}" 19 | echo "bundlesize_fail=${BUNDLESIZE_FAIL}" >> "${GITHUB_OUTPUT}" 20 | fi 21 | 22 | # Cleanup 23 | rm -rf "${WORKSPACE}" 24 | -------------------------------------------------------------------------------- /scripts/lint-commits.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -xeo pipefail 3 | 4 | # Run if we're not on CI 5 | if [[ -z "${CI}" ]]; then 6 | export PATH=$(npm bin):${PATH} 7 | export HOME=$(pwd) 8 | if [[ -z "${CHANGE_ID}" ]]; then 9 | # If on main, just test the latest commit 10 | commitlint --from="${GIT_SHA}~1" 11 | else 12 | # If on a branch, test all commits between this branch and main 13 | commitlint --from="origin/${CHANGE_TARGET}" --to="${GIT_BASE_COMMIT}" 14 | 15 | # Lint PR title 16 | if [[ -n ${CHANGE_TITLE} ]]; then 17 | titleLength=$(echo -n "${CHANGE_TITLE}" | wc -c) 18 | titleResult=0 19 | if [ "${titleLength}" -ge 65 ] ; then 20 | echo "PR title has a long comment. This will fail when squashing and merging the Pull Request" 21 | titleResult=1 22 | fi 23 | echo "${CHANGE_TITLE}" | commitlint 24 | exit ${titleResult} 25 | fi 26 | fi 27 | fi 28 | -------------------------------------------------------------------------------- /scripts/prompt-release.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-present, Elasticsearch BV 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | const log = require('npmlog') 27 | const childProcess = require('@lerna/child-process') 28 | 29 | !(async () => { 30 | /** 31 | * Test the agent version with updated package version 32 | */ 33 | try { 34 | childProcess.execSync('eslint', [ 35 | '--rule', 36 | '{"rulesdir/version-checker": "error"}', 37 | '--fix', 38 | './packages/rum/src/apm-base.js' 39 | ]) 40 | 41 | childProcess.execSync('git', ['add', './packages/rum/src/apm-base.js']) 42 | } catch (err) { 43 | log.error(err) 44 | } 45 | })() 46 | --------------------------------------------------------------------------------