├── .nvmrc ├── .tool-versions ├── test ├── lambda │ ├── fixtures │ │ ├── generic.json │ │ ├── esbuild-bundled-handler │ │ │ ├── Makefile │ │ │ ├── hello.ts │ │ │ ├── README.md │ │ │ └── hello.js │ │ ├── lambda.js │ │ ├── foo.js │ │ ├── handlermodule.cjs │ │ ├── express.js │ │ ├── aws_elb_test_data.json │ │ └── aws_api_http_test_data.json │ └── _util.js ├── fixtures │ ├── certs │ │ ├── .gitignore │ │ ├── README.md │ │ ├── regenerate-cert.sh │ │ └── cert.pem │ └── do-not-trace-self.js ├── activation-method │ └── fixtures │ │ ├── .npmrc │ │ ├── package.json │ │ ├── hi.js │ │ ├── require2.js │ │ ├── import1.mjs │ │ ├── require1.js │ │ └── import2.mjs ├── instrumentation │ ├── azure-functions │ │ └── fixtures │ │ │ ├── azfunc4 │ │ │ ├── .npmrc │ │ │ ├── README.md │ │ │ ├── .funcignore │ │ │ ├── package.json │ │ │ ├── host.json │ │ │ ├── initapm.js │ │ │ ├── local.settings.json │ │ │ └── src │ │ │ │ └── functions │ │ │ │ └── HttpExample.js │ │ │ └── azfunc3 │ │ │ ├── README.md │ │ │ ├── package.json │ │ │ ├── host.json │ │ │ ├── HttpFnError │ │ │ ├── index.js │ │ │ └── function.json │ │ │ ├── HttpFn1 │ │ │ ├── function.json │ │ │ └── index.js │ │ │ ├── HttpFnBindingsRes │ │ │ ├── function.json │ │ │ └── index.js │ │ │ ├── HttpFnContextDone │ │ │ ├── function.json │ │ │ └── index.js │ │ │ ├── HttpFnDistTraceA │ │ │ └── function.json │ │ │ ├── HttpFnDistTraceB │ │ │ ├── function.json │ │ │ └── index.js │ │ │ ├── HttpFnReturnContext │ │ │ ├── function.json │ │ │ └── index.js │ │ │ ├── HttpFnReturnObject │ │ │ ├── function.json │ │ │ └── index.js │ │ │ ├── HttpFnReturnString │ │ │ ├── function.json │ │ │ └── index.js │ │ │ ├── HttpFnReturnResponseData │ │ │ ├── function.json │ │ │ └── index.js │ │ │ ├── initapm.js │ │ │ ├── HttpFnRouteTemplate │ │ │ ├── function.json │ │ │ └── index.js │ │ │ ├── local.settings.json │ │ │ └── .gitignore │ ├── modules │ │ ├── fixtures │ │ │ ├── static │ │ │ │ └── style.css │ │ │ ├── use-fastify-errorCodes.js │ │ │ ├── use-ioredis.mjs │ │ │ └── use-pg.mjs │ │ ├── http │ │ │ ├── fixtures │ │ │ │ ├── load-http-twice.mjs │ │ │ │ ├── load-http.js │ │ │ │ ├── load-http.mjs │ │ │ │ ├── use-http-server.mjs │ │ │ │ ├── use-http-get.mjs │ │ │ │ ├── use-https-get.mjs │ │ │ │ └── use-dynamic-import.mjs │ │ │ ├── _echo_server_util.js │ │ │ └── _assert.js │ │ ├── koa-router │ │ │ ├── new-name.test.js │ │ │ ├── old-name.test.js │ │ │ ├── _generators.js │ │ │ ├── _non-generators.js │ │ │ └── _async-await.js │ │ ├── aws-sdk │ │ │ └── fixtures │ │ │ │ └── dynamodb.js │ │ ├── fastify │ │ │ ├── async-await.test.js │ │ │ └── set-framework.test.js │ │ ├── koa │ │ │ └── set-framework.test.js │ │ ├── hapi │ │ │ └── set-framework.test.js │ │ ├── mysql │ │ │ └── _utils.js │ │ ├── mysql2 │ │ │ └── _utils.js │ │ └── express │ │ │ └── set-framework.test.js │ ├── native-promises.test.js │ ├── _async-await.js │ ├── fs.test.js │ └── express-utils.test.js ├── apm-client │ └── http-apm-client │ │ ├── fixtures │ │ └── ecs-container-metadata.json │ │ └── lib │ │ └── unref-client.js ├── sourcemaps │ └── fixtures │ │ ├── src │ │ └── error.js │ │ └── lib │ │ ├── error-broken.js.map │ │ ├── error.js.map │ │ ├── error-src-missing.js.map │ │ ├── error.js │ │ ├── error-broken.js │ │ ├── error-map-missing.js │ │ ├── error-src-embedded.js │ │ ├── error-src-missing.js │ │ ├── error-src-embedded.js.map │ │ ├── error-inline.js │ │ └── error-inline-broken.js ├── opentelemetry-metrics │ └── fixtures │ │ ├── .tav.yml │ │ ├── package.json │ │ ├── use-disable-metrics-conf.js │ │ ├── await-agent-destroy.js │ │ ├── various-attrs.js │ │ └── instrumentation-scopes.js ├── config │ └── fixtures │ │ ├── pkg-zero-conf-noname │ │ ├── package.json │ │ └── index.js │ │ ├── pkg-zero-conf-valid │ │ ├── package.json │ │ └── index.js │ │ ├── pkg-zero-conf-nsname │ │ ├── package.json │ │ └── index.js │ │ ├── pkg-zero-conf-weird │ │ ├── package.json │ │ └── index.js │ │ ├── pkg-zero-conf-sanitize │ │ ├── package.json │ │ └── index.js │ │ └── use-agent-config.js ├── opentelemetry-bridge │ ├── package.json │ ├── .tav.yml │ ├── fixtures │ │ ├── start-span.js │ │ └── start-active-span.js │ └── package-lock.json ├── types │ ├── transpile-default │ │ ├── tsconfig.json │ │ └── index.ts │ ├── transpile │ │ ├── tsconfig.json │ │ └── index.ts │ ├── tsconfig.json │ ├── commonjs.js │ └── start.ts ├── babel │ ├── .babelrc │ ├── elastic-apm-node.js │ └── src.js ├── Dockerfile ├── script │ ├── docker │ │ ├── cleanup.sh │ │ └── run_tests.sh │ ├── local-deps-stop.sh │ └── local-deps-start.sh ├── _patch.js ├── start │ ├── file │ │ ├── elastic-apm-node.js │ │ └── test.test.js │ └── env │ │ └── test.test.js ├── stacktraces │ └── fixtures │ │ ├── Makefile │ │ ├── tsconfig.json │ │ ├── get-prepare-stacktrace.js │ │ ├── throw-an-error.js │ │ ├── src │ │ └── throw-an-error-with-sourcemap.ts │ │ ├── capture-error-string.js │ │ ├── send-a-span.js │ │ └── dist │ │ ├── throw-an-error-with-sourcemap.js │ │ └── throw-an-error-with-sourcemap.js.map ├── _promise_rejection.js ├── openssl-config-for-testing.cnf ├── benchmarks │ ├── utils │ │ ├── callstack.js │ │ └── apm-server.js │ ├── 004-transaction.js │ ├── 005-transaction-reading-file.js │ ├── 003-transaction-and-span-with-stack-trace.js │ └── 001-transaction-and-span-no-stack-trace.js ├── wildcard-matcher.test.js ├── docker-compose.ci.yml ├── integration │ ├── socket-close.test.js │ ├── server-url-path.test.js │ └── 503.test.js ├── _is_koa_incompat.js ├── central-config-disabled.test.js └── _is_express_incompat.js ├── examples ├── esbuild │ ├── .npmrc │ ├── package.json │ └── src │ │ ├── handler.js │ │ └── index.js ├── typescript │ ├── .npmrc │ ├── tsconfig.json │ ├── package.json │ └── index.ts ├── azure-function-app │ ├── .npmrc │ ├── initapm.js │ ├── local.settings.json │ ├── host.json │ ├── Makefile │ ├── package.json │ ├── .gitignore │ └── src │ │ └── functions │ │ └── Hello.js ├── opentelemetry-bridge │ ├── .gitignore │ ├── .npmrc │ ├── trace-hello-world.js │ ├── package.json │ └── trace-https-request.js ├── opentelemetry-metrics │ ├── .npmrc │ ├── num_requests-chart.png │ ├── package.json │ └── otel-metrics-hello-world.js ├── .eslintrc.json ├── README.md ├── trace-pug.js ├── trace-handlebars.js └── trace-fetch.js ├── .gitattributes ├── .prettierrc.json ├── .ci ├── updatecli │ └── values.d │ │ ├── apm-json-specs.yml │ │ ├── update-compose.yml │ │ ├── apm-data-spec.yml │ │ └── scm.yml ├── docker │ ├── node-container │ │ └── Dockerfile │ ├── docker-compose-redis.yml │ ├── docker-compose-memcached.yml │ ├── docker-compose-kafka.yml │ ├── docker-compose-mssql.yml │ ├── docker-compose-mysql.yml │ ├── docker-compose-mongodb.yml │ ├── docker-compose-postgres.yml │ ├── docker-compose-cassandra.yml │ ├── docker-compose-elasticsearch.yml │ ├── docker-compose-localstack.yml │ ├── docker-compose-node-test.yml │ └── docker-compose-node-edge-test.yml ├── scripts │ ├── windows │ │ ├── prepare-test.sh │ │ └── stop-test.sh │ ├── run-benchmarks.sh │ ├── create-arn-table.sh │ ├── bench.sh │ └── prepare-benchmarks-env.sh └── .editorconfig ├── CODE_OF_CONDUCT.md ├── docs ├── release-notes │ ├── toc.yml │ └── known-issues.md ├── reference │ ├── images │ │ ├── config-layer.png │ │ ├── choose-a-layer.png │ │ ├── nodejs-lambda-env-vars.png │ │ ├── azure-functions-configuration.png │ │ └── dynamic-config.svg │ ├── advanced-setup.md │ ├── api.md │ └── toc.yml ├── redirects.yml ├── docset.yml └── scripts │ └── build_docs.sh ├── .github ├── CODEOWNERS ├── workflows │ ├── docs-cleanup.yml │ ├── github-commands-comment.yml │ ├── docs-build.yml │ ├── test-docs.yml │ └── microbenchmark.yml ├── ISSUE_TEMPLATE │ └── Feature_request.md └── pull_request_template.md ├── dev-utils ├── docker-compose.yml ├── license-header.js ├── lint-yaml-files.sh ├── license.MIT.txt ├── license.node-measured.txt └── ci-tav-slow-jobs.sh ├── Dockerfile.wolfi ├── lib ├── opentelemetry-bridge │ ├── opentelemetry-core-mini │ │ └── README.md │ ├── index.js │ ├── OTelTracerProvider.js │ └── oblog.js ├── instrumentation │ ├── modules │ │ ├── koa.js │ │ ├── express-queue.js │ │ ├── pug.js │ │ ├── jade.js │ │ ├── handlebars.js │ │ ├── @apollo │ │ │ └── server.js │ │ ├── _lambda-handler.js │ │ ├── mongodb │ │ │ └── lib │ │ │ │ └── cmap │ │ │ │ └── connection_pool.js │ │ └── finalhandler.js │ ├── run-context │ │ └── index.js │ ├── ids.js │ └── template-shared.js ├── middleware │ └── connect.js ├── apm-client │ └── http-apm-client │ │ ├── ndjson.js │ │ ├── logging.js │ │ └── central-config.js ├── metrics │ └── platforms │ │ ├── linux │ │ └── index.js │ │ └── generic │ │ ├── process-cpu.js │ │ ├── stats.js │ │ ├── index.js │ │ └── system-cpu.js ├── symbols.js └── constants.js ├── Dockerfile ├── loader.mjs ├── start.d.ts ├── .gitignore ├── SECURITY.md ├── index.js ├── .npmrc ├── Makefile ├── CHANGELOG.md ├── start.js ├── types └── connect.d.ts ├── updatecli-compose.yaml └── LICENSE /.nvmrc: -------------------------------------------------------------------------------- 1 | 16.20.2 2 | -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | updatecli v0.112.0 2 | -------------------------------------------------------------------------------- /test/lambda/fixtures/generic.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /examples/esbuild/.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | CHANGELOG.asciidoc merge=union 2 | -------------------------------------------------------------------------------- /examples/typescript/.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /test/fixtures/certs/.gitignore: -------------------------------------------------------------------------------- 1 | /generate_cert.go 2 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true 3 | } 4 | -------------------------------------------------------------------------------- /examples/azure-function-app/.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /examples/opentelemetry-bridge/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | -------------------------------------------------------------------------------- /examples/opentelemetry-bridge/.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /examples/opentelemetry-metrics/.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /test/activation-method/fixtures/.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /examples/azure-function-app/initapm.js: -------------------------------------------------------------------------------- 1 | require('elastic-apm-node').start() 2 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc4/.npmrc: -------------------------------------------------------------------------------- 1 | lockfile-version=3 2 | -------------------------------------------------------------------------------- /examples/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "no-var": ["error"] 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.ci/updatecli/values.d/apm-json-specs.yml: -------------------------------------------------------------------------------- 1 | apm_json_specs_path: test/fixtures/json-specs 2 | -------------------------------------------------------------------------------- /.ci/updatecli/values.d/update-compose.yml: -------------------------------------------------------------------------------- 1 | spec: 2 | files: 3 | - "updatecli-compose.yaml" -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 303 See Other 2 | 3 | Location: https://www.elastic.co/community/codeofconduct 4 | -------------------------------------------------------------------------------- /test/instrumentation/modules/fixtures/static/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color:#ff9 3 | } 4 | -------------------------------------------------------------------------------- /.ci/updatecli/values.d/apm-data-spec.yml: -------------------------------------------------------------------------------- 1 | apm_schema_specs_path: test/integration/api-schema/apm-server-schema 2 | -------------------------------------------------------------------------------- /docs/release-notes/toc.yml: -------------------------------------------------------------------------------- 1 | toc: 2 | - file: index.md 3 | - file: known-issues.md 4 | - file: breaking-changes.md -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @elastic/apm-agent-node-js 2 | /.github/workflows/ @elastic/apm-agent-node-js @elastic/observablt-ci 3 | -------------------------------------------------------------------------------- /docs/reference/images/config-layer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/apm-agent-nodejs/main/docs/reference/images/config-layer.png -------------------------------------------------------------------------------- /docs/reference/images/choose-a-layer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/apm-agent-nodejs/main/docs/reference/images/choose-a-layer.png -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | This directory holds example programs demonstrating the use of the Elastic 2 | Node.js APM agent (`elastic-apm-node`). 3 | -------------------------------------------------------------------------------- /docs/reference/images/nodejs-lambda-env-vars.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/apm-agent-nodejs/main/docs/reference/images/nodejs-lambda-env-vars.png -------------------------------------------------------------------------------- /examples/typescript/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@tsconfig/node20/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/lambda/fixtures/esbuild-bundled-handler/Makefile: -------------------------------------------------------------------------------- 1 | hello.js: hello.ts 2 | npx esbuild@0.14.42 hello.ts --platform=node --bundle --outfile=hello.js 3 | -------------------------------------------------------------------------------- /examples/opentelemetry-metrics/num_requests-chart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/apm-agent-nodejs/main/examples/opentelemetry-metrics/num_requests-chart.png -------------------------------------------------------------------------------- /test/apm-client/http-apm-client/fixtures/ecs-container-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "ContainerID": "34dc0b5e626f2c5c4c5170e34b10e7654ce36f0fcd532739f4445baabea03376" 3 | } 4 | -------------------------------------------------------------------------------- /dev-utils/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | services: 3 | nodejs-agent: 4 | image: node:20 5 | entrypoint: /bin/bash 6 | volumes: 7 | - ..:/agent 8 | -------------------------------------------------------------------------------- /docs/reference/images/azure-functions-configuration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elastic/apm-agent-nodejs/main/docs/reference/images/azure-functions-configuration.png -------------------------------------------------------------------------------- /test/sourcemaps/fixtures/src/error.js: -------------------------------------------------------------------------------- 1 | // Just a little prefixing line 2 | const generateError = (msg = 'foo') => new Error(msg) 3 | 4 | module.exports = generateError 5 | -------------------------------------------------------------------------------- /test/opentelemetry-metrics/fixtures/.tav.yml: -------------------------------------------------------------------------------- 1 | "@opentelemetry/api": 2 | versions: '>=1.3.0 <1.10.0' 3 | node: '>=14.0.0' 4 | commands: 5 | - node ../fixtures.test.js 6 | -------------------------------------------------------------------------------- /.ci/docker/node-container/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG NODE_VERSION=16 2 | FROM node:${NODE_VERSION} 3 | 4 | # test npm works properly 5 | RUN node --version && npm --version 6 | 7 | WORKDIR /app 8 | -------------------------------------------------------------------------------- /Dockerfile.wolfi: -------------------------------------------------------------------------------- 1 | FROM docker.elastic.co/wolfi/chainguard-base:latest@sha256:36a56e3d8a40080f81e3ccca6b0fed0167716225bbc305052db6d5a9f594ccb2 2 | ARG AGENT_DIR 3 | COPY ${AGENT_DIR} /opt/nodejs -------------------------------------------------------------------------------- /test/config/fixtures/pkg-zero-conf-noname/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.2.3", 3 | "description": "a package without a 'name' field for testing serviceName and serviceVersion inference" 4 | } 5 | -------------------------------------------------------------------------------- /docs/redirects.yml: -------------------------------------------------------------------------------- 1 | # https://docs-v3-preview.elastic.dev/elastic/docs-builder/tree/main/contribute/redirects 2 | redirects: 3 | 'reference/restify.md': 4 | to: 'release-notes/index.md' 5 | anchors: '!' 6 | -------------------------------------------------------------------------------- /test/config/fixtures/pkg-zero-conf-valid/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validName", 3 | "version": "1.2.3", 4 | "description": "a package with valid values for serviceName and serviceVersion inference" 5 | } 6 | -------------------------------------------------------------------------------- /test/opentelemetry-bridge/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "opentelemetry-bridge-tests", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "@opentelemetry/api": "^1.9.0" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/activation-method/fixtures/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "activation-method-fixtures", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "elastic-apm-node": "file:../../.." 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/config/fixtures/pkg-zero-conf-nsname/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@ns/name", 3 | "version": "1.2.3", 4 | "description": "a package with a scoped npm name for testing serviceName and serviceVersion inference" 5 | } 6 | -------------------------------------------------------------------------------- /test/types/transpile-default/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "strict": true 6 | }, 7 | "files": [ 8 | "./index.ts" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /test/config/fixtures/pkg-zero-conf-weird/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "~~-~~", 3 | "version": "1.2.3", 4 | "description": "a package with a valid npm name that sanitizes to all non-alphanumeric for testing serviceName inference" 5 | } 6 | -------------------------------------------------------------------------------- /test/config/fixtures/pkg-zero-conf-sanitize/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "~*.!'()validNpmName", 3 | "version": "1.2.3", 4 | "description": "a package with a valid npm name, but invalid for serviceName, to test serviceName inference" 5 | } 6 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/README.md: -------------------------------------------------------------------------------- 1 | A Node.js Azure Functions app, using **version 3** of the Node.js 2 | programming model. See: 3 | https://learn.microsoft.com/en-ca/azure/azure-functions/functions-node-upgrade-v4 4 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc4/README.md: -------------------------------------------------------------------------------- 1 | A Node.js Azure Functions app, using **version 4** of the Node.js 2 | programming model. See: 3 | https://learn.microsoft.com/en-ca/azure/azure-functions/functions-node-upgrade-v4 4 | -------------------------------------------------------------------------------- /dev-utils/license-header.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | -------------------------------------------------------------------------------- /test/babel/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | [ 4 | "@babel/preset-env", 5 | { 6 | "targets": { 7 | "node": "current" 8 | }, 9 | "modules": "commonjs" 10 | } 11 | ] 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /test/types/transpile/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "strict": true, 6 | "esModuleInterop": true 7 | }, 8 | "files": [ 9 | "./index.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /lib/opentelemetry-bridge/opentelemetry-core-mini/README.md: -------------------------------------------------------------------------------- 1 | This holds a very small subset of the `@opentelemetry/core` package, instead of 2 | having a dependency on it. "Very small" here is just the `TraceState` class, as 3 | opposed to a ~2.6M dependency. 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Pin the latest Alpine 3 2 | # https://github.com/docker-library/repo-info/blob/master/repos/alpine/remote/3.md 3 | 4 | FROM alpine@sha256:865b95f46d98cf867a156fe4a135ad3fe50d2056aa3f25ed31662dff6da4eb62 5 | ARG AGENT_DIR 6 | COPY ${AGENT_DIR} /opt/nodejs 7 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc4/.funcignore: -------------------------------------------------------------------------------- 1 | *.js.map 2 | *.ts 3 | .git* 4 | .vscode 5 | local.settings.json 6 | test 7 | getting_started.md 8 | node_modules/@types/ 9 | node_modules/azure-functions-core-tools/ 10 | node_modules/typescript/ -------------------------------------------------------------------------------- /test/sourcemaps/fixtures/lib/error-broken.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["../src/error.js"],"names":[],"mappings":";;AAA;ACA,IAM,gBAgB,SAhB,aAAgB;AAAA,MAAC,GAAD,uEAAO,KAAP;AAAA,SAAiB,IAAI,KAAJ,CAAU,GAAV,CAAjB;AAAA,CAAtB;;AAEA,OAAO,OAAP,GAAiB,aAAjB","file":"error.js"} 2 | -------------------------------------------------------------------------------- /test/sourcemaps/fixtures/lib/error.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["../src/error.js"],"names":[],"mappings":";;AAAA;AACA,IAAM,gBAAgB,SAAhB,aAAgB;AAAA,MAAC,GAAD,uEAAO,KAAP;AAAA,SAAiB,IAAI,KAAJ,CAAU,GAAV,CAAjB;AAAA,CAAtB;;AAEA,OAAO,OAAP,GAAiB,aAAjB","file":"error.js"} 2 | -------------------------------------------------------------------------------- /test/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG NODE_VERSION 2 | FROM node:${NODE_VERSION} 3 | 4 | RUN apt-get update && \ 5 | apt-get install -y xsltproc libxml2-utils && \ 6 | rm -rf /var/lib/apt/lists/* 7 | 8 | ENV NPM_CONFIG_PREFIX=/home/node/.npm-global 9 | 10 | WORKDIR /app 11 | -------------------------------------------------------------------------------- /test/script/docker/cleanup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | DOCKER_CONTAINERS=$(docker ps -a -q) 3 | 4 | if [ -n "${DOCKER_CONTAINERS}" ]; then 5 | docker stop ${DOCKER_CONTAINERS} 6 | docker rm -v ${DOCKER_CONTAINERS} 7 | docker volume prune -f 8 | fi 9 | 10 | exit 0 11 | -------------------------------------------------------------------------------- /test/sourcemaps/fixtures/lib/error-src-missing.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["../src/not/found.js"],"names":[],"mappings":";;AAAA;AACA,IAAM,gBAAgB,SAAhB,aAAgB;AAAA,MAAC,GAAD,uEAAO,KAAP;AAAA,SAAiB,IAAI,KAAJ,CAAU,GAAV,CAAjB;AAAA,CAAtB;;AAEA,OAAO,OAAP,GAAiB,aAAjB","file":"error.js"} 2 | -------------------------------------------------------------------------------- /loader.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | export * from 'import-in-the-middle/hook.mjs'; 8 | -------------------------------------------------------------------------------- /start.d.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | import * as agent from './'; 8 | export = agent; 9 | -------------------------------------------------------------------------------- /test/activation-method/fixtures/hi.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | console.log('hi'); 8 | -------------------------------------------------------------------------------- /test/_patch.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | module.exports = () => ({ 8 | foo: 'bar', 9 | }); 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Files to ignore 2 | .DS_Store 3 | /.vscode 4 | /test/babel/out.js 5 | /test/types/transpile/index.js 6 | /test/types/transpile-default/index.js 7 | /test-suite-output.tap 8 | 9 | # Folders to ignore 10 | /build 11 | node_modules 12 | /test/benchmarks/.tmp 13 | tmp 14 | /examples/*/dist 15 | .next 16 | -------------------------------------------------------------------------------- /test/script/local-deps-stop.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | pg_ctl -D /usr/local/var/postgres stop 4 | kill `cat /tmp/mongod.pid` 5 | kill `cat /tmp/elasticsearch.pid` 6 | kill `cat /tmp/cassandra.pid` 7 | kill `cat /tmp/memcached.pid` 8 | redis-cli shutdown 9 | mysql.server stop 10 | docker stop dev-localstack 11 | -------------------------------------------------------------------------------- /.ci/updatecli/values.d/scm.yml: -------------------------------------------------------------------------------- 1 | scm: 2 | enabled: true 3 | owner: elastic 4 | repository: apm-agent-nodejs 5 | branch: main 6 | commitusingapi: true 7 | # begin update-compose policy values 8 | user: obltmachine 9 | email: obltmachine@users.noreply.github.com 10 | # end update-compose policy values 11 | -------------------------------------------------------------------------------- /test/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "commonjs", 5 | "noEmit": true, 6 | "allowJs": true, 7 | "checkJs": true, 8 | "strict": true, 9 | "esModuleInterop": true 10 | }, 11 | "include": [ 12 | "*.ts", 13 | "*.js" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | Thanks for your interest in the security of our products. 4 | Our security policy can be found at [https://www.elastic.co/community/security](https://www.elastic.co/community/security). 5 | 6 | ## Reporting a Vulnerability 7 | Please send security vulnerability reports to security@elastic.co. 8 | -------------------------------------------------------------------------------- /test/opentelemetry-metrics/fixtures/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "otel-metrics-fixtures", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "@opentelemetry/api": "^1.9.0", 7 | "@opentelemetry/exporter-prometheus": ">=0.41.2 <2", 8 | "@opentelemetry/sdk-metrics": "^1.30.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var Agent = require('./lib/agent'); 10 | 11 | module.exports = new Agent(); 12 | -------------------------------------------------------------------------------- /test/instrumentation/modules/http/fixtures/load-http-twice.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | import './load-http.js'; 8 | import './load-http.mjs'; 9 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.ci/docker/docker-compose-redis.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | services: 4 | redis: 5 | extends: 6 | file: docker-compose.yml 7 | service: redis 8 | node_tests: 9 | extends: 10 | file: docker-compose-node-test.yml 11 | service: node_tests 12 | depends_on: 13 | redis: 14 | condition: service_healthy 15 | -------------------------------------------------------------------------------- /test/sourcemaps/fixtures/lib/error.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Just a little prefixing line 4 | var generateError = function generateError() { 5 | var msg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'foo'; 6 | return new Error(msg); 7 | }; 8 | 9 | module.exports = generateError; 10 | 11 | //# sourceMappingURL=error.js.map -------------------------------------------------------------------------------- /examples/azure-function-app/local.settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "IsEncrypted": false, 3 | "Values": { 4 | "FUNCTIONS_WORKER_RUNTIME": "node", 5 | "AzureWebJobsStorage": "", 6 | 7 | "REGION_NAME": "test-region-name", 8 | "WEBSITE_SITE_NAME": "example-azure-function-app", 9 | "WEBSITE_INSTANCE_ID": "test-website-instance-id" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/activation-method/fixtures/require2.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | require('elastic-apm-node/start'); 8 | console.log("using: require('elastic-apm-node/start')"); 9 | -------------------------------------------------------------------------------- /test/fixtures/certs/README.md: -------------------------------------------------------------------------------- 1 | This dir holds a self-signed TLS certificate (and key) to be used from some 2 | HTTPS tests. 3 | 4 | They were generated via the same method as Go's builtin test certificate/key 5 | pair, using https://github.com/golang/go/blob/master/src/crypto/tls/generate_cert.go. 6 | Use "./regenerate.sh" to regenerate the TLS cert if necessary. 7 | -------------------------------------------------------------------------------- /test/lambda/fixtures/esbuild-bundled-handler/hello.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | export const main = async (event, context) => { 8 | return 'hi' 9 | } 10 | -------------------------------------------------------------------------------- /test/activation-method/fixtures/import1.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | import 'elastic-apm-node/start.js'; 8 | console.log("using: import 'elastic-apm-node/start.js'"); 9 | -------------------------------------------------------------------------------- /test/activation-method/fixtures/require1.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | require('elastic-apm-node').start(); 8 | console.log("using: require('elastic-apm-node').start()"); 9 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "initapm.js", 6 | "scripts": { 7 | "start": "func start", 8 | "test": "echo \"No tests yet...\"" 9 | }, 10 | "devDependencies": { 11 | "azure-functions-core-tools": "^4.0.5148" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/lambda/fixtures/lambda.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | 'use strict'; 8 | module.exports.foo = function (event, context) { 9 | return 'fake handler'; 10 | }; 11 | -------------------------------------------------------------------------------- /.ci/docker/docker-compose-memcached.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | services: 4 | memcached: 5 | extends: 6 | file: docker-compose.yml 7 | service: memcached 8 | node_tests: 9 | extends: 10 | file: docker-compose-node-test.yml 11 | service: node_tests 12 | depends_on: 13 | memcached: 14 | condition: service_healthy 15 | -------------------------------------------------------------------------------- /test/start/file/elastic-apm-node.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | 'use strict' 8 | 9 | module.exports = { 10 | serviceName: 'from-file', 11 | active: false 12 | } 13 | -------------------------------------------------------------------------------- /examples/opentelemetry-metrics/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examples-opentelemetry-metrics", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "@opentelemetry/api": "^1.4.1", 7 | "@opentelemetry/exporter-prometheus": ">=0.41.0 <2", 8 | "@opentelemetry/sdk-metrics": "^1.12.0", 9 | "elastic-apm-node": "file:../.." 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc4/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "{initapm.js,src/functions/*.js}", 6 | "scripts": { 7 | "start": "func start" 8 | }, 9 | "dependencies": { 10 | "@azure/functions": "^4.0.0", 11 | "azure-functions-core-tools": "^4.0.6821" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/sourcemaps/fixtures/lib/error-broken.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Just a little prefixing line 4 | var generateError = function generateError() { 5 | var msg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'foo'; 6 | return new Error(msg); 7 | }; 8 | 9 | module.exports = generateError; 10 | 11 | //# sourceMappingURL=error-broken.js.map 12 | -------------------------------------------------------------------------------- /test/sourcemaps/fixtures/lib/error-map-missing.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Just a little prefixing line 4 | var generateError = function generateError() { 5 | var msg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'foo'; 6 | return new Error(msg); 7 | }; 8 | 9 | module.exports = generateError; 10 | 11 | //# sourceMappingURL=invalid.js.map 12 | -------------------------------------------------------------------------------- /test/lambda/fixtures/esbuild-bundled-handler/README.md: -------------------------------------------------------------------------------- 1 | This is directory holds the result of using `esbuild` to bundled a TypeScript 2 | lambda handler -- as is done by a handler built using Serverless Framework 3 | and TypeScript. 4 | https://esbuild.github.io/getting-started/#bundling-for-node 5 | 6 | "hello.js" can be rebuilt from "hello.ts" by running `make` in this directory. 7 | -------------------------------------------------------------------------------- /test/sourcemaps/fixtures/lib/error-src-embedded.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Just a little prefixing line 4 | var generateError = function generateError() { 5 | var msg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'foo'; 6 | return new Error(msg); 7 | }; 8 | 9 | module.exports = generateError; 10 | 11 | //# sourceMappingURL=error-src-embedded.js.map 12 | -------------------------------------------------------------------------------- /test/sourcemaps/fixtures/lib/error-src-missing.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Just a little prefixing line 4 | var generateError = function generateError() { 5 | var msg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'foo'; 6 | return new Error(msg); 7 | }; 8 | 9 | module.exports = generateError; 10 | 11 | //# sourceMappingURL=error-src-missing.js.map 12 | -------------------------------------------------------------------------------- /examples/azure-function-app/host.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "logging": { 4 | "applicationInsights": { 5 | "samplingSettings": { 6 | "isEnabled": true, 7 | "excludedTypes": "Request" 8 | } 9 | } 10 | }, 11 | "extensionBundle": { 12 | "id": "Microsoft.Azure.Functions.ExtensionBundle", 13 | "version": "[4.*, 5.0.0)" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/lambda/fixtures/foo.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | module.exports = { 10 | bar: function (event, context) { 11 | return 'fake handler'; 12 | }, 13 | }; 14 | -------------------------------------------------------------------------------- /test/stacktraces/fixtures/Makefile: -------------------------------------------------------------------------------- 1 | # This Makefile can be used to rebuild dist/... from src/... if necessary. 2 | # However, this is mostly here to be self-documenting. I don't expect this 3 | # test code to need to change. 4 | # 5 | # Prerequisite: You have TypeScript installed. That can be done via something 6 | # like 'npm install -g typescript'. 7 | 8 | .PHONY: all 9 | all: 10 | tsc 11 | -------------------------------------------------------------------------------- /.github/workflows/github-commands-comment.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: github-commands-comment 3 | 4 | on: 5 | pull_request_target: 6 | types: 7 | - opened 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | comment: 14 | runs-on: ubuntu-latest 15 | permissions: 16 | pull-requests: write 17 | steps: 18 | - uses: elastic/oblt-actions/elastic/github-commands@v1 19 | -------------------------------------------------------------------------------- /test/activation-method/fixtures/import2.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | import apm from 'elastic-apm-node'; 8 | apm.start(); 9 | console.log("using: import apm from 'elastic-apm-node'; apm.start()"); 10 | -------------------------------------------------------------------------------- /test/config/fixtures/pkg-zero-conf-weird/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | const apm = require('../../../..').start({ 8 | disableSend: true, 9 | }); 10 | console.log(JSON.stringify(apm._conf)); 11 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc4/host.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "logging": { 4 | "applicationInsights": { 5 | "samplingSettings": { 6 | "isEnabled": true, 7 | "excludedTypes": "Request" 8 | } 9 | } 10 | }, 11 | "extensionBundle": { 12 | "id": "Microsoft.Azure.Functions.ExtensionBundle", 13 | "version": "[4.*, 5.0.0)" 14 | } 15 | } -------------------------------------------------------------------------------- /test/lambda/fixtures/handlermodule.cjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | module.exports = { 8 | lambda: { 9 | foo: function myHandler(event, context) { 10 | return 'hi'; 11 | }, 12 | }, 13 | }; 14 | -------------------------------------------------------------------------------- /test/opentelemetry-bridge/.tav.yml: -------------------------------------------------------------------------------- 1 | "@opentelemetry/api": 2 | versions: '>=1.0.0 <1.10.0' 3 | node: '>=8.0.0' 4 | commands: 5 | - node OTelBridgeNonRecordingSpan.test.js 6 | - node OTelBridgeRunContext.test.js 7 | - node active-span-and-context-interop.test.js 8 | - node fixtures.test.js 9 | - node interface-ContextManager.test.js 10 | - node otel-bridge-feature.test.js 11 | 12 | -------------------------------------------------------------------------------- /test/sourcemaps/fixtures/lib/error-src-embedded.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["../src/error.js"],"names":[],"mappings":";;AAAA;AACA,IAAM,gBAAgB,SAAhB,aAAgB;AAAA,MAAC,GAAD,uEAAO,KAAP;AAAA,SAAiB,IAAI,KAAJ,CAAU,GAAV,CAAjB;AAAA,CAAtB;;AAEA,OAAO,OAAP,GAAiB,aAAjB","file":"error.js","sourcesContent":["// Just a little prefixing line\nconst generateError = (msg = 'foo') => new Error(msg)\n\nmodule.exports = generateError\n"]} -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/host.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "logging": { 4 | "applicationInsights": { 5 | "samplingSettings": { 6 | "isEnabled": true, 7 | "excludedTypes": "Request" 8 | } 9 | } 10 | }, 11 | "extensionBundle": { 12 | "id": "Microsoft.Azure.Functions.ExtensionBundle", 13 | "version": "[3.*, 4.0.0)" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.ci/docker/docker-compose-kafka.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | services: 4 | kafka: 5 | extends: 6 | file: docker-compose.yml 7 | service: kafka 8 | node_tests: 9 | extends: 10 | file: docker-compose-node-test.yml 11 | service: node_tests 12 | depends_on: 13 | kafka: 14 | condition: service_healthy 15 | 16 | volumes: 17 | nodekafkadata: 18 | driver: local 19 | -------------------------------------------------------------------------------- /.ci/docker/docker-compose-mssql.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | services: 4 | mssql: 5 | extends: 6 | file: docker-compose.yml 7 | service: mssql 8 | node_tests: 9 | extends: 10 | file: docker-compose-node-test.yml 11 | service: node_tests 12 | depends_on: 13 | mssql: 14 | condition: service_healthy 15 | 16 | volumes: 17 | nodemssqldata: 18 | driver: local 19 | -------------------------------------------------------------------------------- /.ci/docker/docker-compose-mysql.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | services: 4 | mysql: 5 | extends: 6 | file: docker-compose.yml 7 | service: mysql 8 | node_tests: 9 | extends: 10 | file: docker-compose-node-test.yml 11 | service: node_tests 12 | depends_on: 13 | mysql: 14 | condition: service_healthy 15 | 16 | volumes: 17 | nodemysqldata: 18 | driver: local 19 | -------------------------------------------------------------------------------- /.ci/docker/docker-compose-mongodb.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | services: 4 | mongodb: 5 | extends: 6 | file: docker-compose.yml 7 | service: mongodb 8 | node_tests: 9 | extends: 10 | file: docker-compose-node-test.yml 11 | service: node_tests 12 | depends_on: 13 | mongodb: 14 | condition: service_healthy 15 | 16 | volumes: 17 | nodemongodata: 18 | driver: local 19 | -------------------------------------------------------------------------------- /.ci/docker/docker-compose-postgres.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | services: 4 | postgres: 5 | extends: 6 | file: docker-compose.yml 7 | service: postgres 8 | node_tests: 9 | extends: 10 | file: docker-compose-node-test.yml 11 | service: node_tests 12 | depends_on: 13 | postgres: 14 | condition: service_healthy 15 | 16 | volumes: 17 | nodepgdata: 18 | driver: local 19 | -------------------------------------------------------------------------------- /test/config/fixtures/pkg-zero-conf-valid/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | const apm = require('../../../..').start({ 8 | disableSend: true, 9 | logLevel: 'off', 10 | }); 11 | console.log(JSON.stringify(apm._conf)); 12 | -------------------------------------------------------------------------------- /test/config/fixtures/pkg-zero-conf-noname/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | const apm = require('../../../..').start({ 8 | disableSend: true, 9 | logLevel: 'off', 10 | }); 11 | console.log(JSON.stringify(apm._conf)); 12 | -------------------------------------------------------------------------------- /test/config/fixtures/pkg-zero-conf-nsname/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | const apm = require('../../../..').start({ 8 | disableSend: true, 9 | logLevel: 'off', 10 | }); 11 | console.log(JSON.stringify(apm._conf)); 12 | -------------------------------------------------------------------------------- /test/config/fixtures/pkg-zero-conf-sanitize/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | const apm = require('../../../..').start({ 8 | disableSend: true, 9 | logLevel: 'off', 10 | }); 11 | console.log(JSON.stringify(apm._conf)); 12 | -------------------------------------------------------------------------------- /.ci/scripts/windows/prepare-test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -exo pipefail 3 | 4 | NODE_VERSION=${1:?Nodejs version missing NODE_VERSION is not set} 5 | 6 | NODE_VERSION=${NODE_VERSION} \ 7 | USER_ID="$(id -u):$(id -g)" \ 8 | docker --log-level error\ 9 | compose \ 10 | --ansi never \ 11 | -f .ci/docker/docker-compose-all.yml \ 12 | up \ 13 | --build \ 14 | --remove-orphans \ 15 | --quiet-pull \ 16 | --detach 17 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/HttpFnError/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | module.exports = async function ThrowErrorHandler(context, req) { 8 | throw new Error('thrown error in HttpFnError'); 9 | }; 10 | -------------------------------------------------------------------------------- /.ci/docker/docker-compose-cassandra.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | services: 4 | cassandra: 5 | extends: 6 | file: docker-compose.yml 7 | service: cassandra 8 | node_tests: 9 | extends: 10 | file: docker-compose-node-test.yml 11 | service: node_tests 12 | depends_on: 13 | cassandra: 14 | condition: service_healthy 15 | 16 | volumes: 17 | nodecassandradata: 18 | driver: local 19 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/HttpFn1/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindings": [ 3 | { 4 | "authLevel": "Anonymous", 5 | "type": "httpTrigger", 6 | "direction": "in", 7 | "name": "req", 8 | "methods": [ 9 | "get", 10 | "post" 11 | ] 12 | }, 13 | { 14 | "type": "http", 15 | "direction": "out", 16 | "name": "res" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/HttpFnError/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindings": [ 3 | { 4 | "authLevel": "Anonymous", 5 | "type": "httpTrigger", 6 | "direction": "in", 7 | "name": "req", 8 | "methods": [ 9 | "get", 10 | "post" 11 | ] 12 | }, 13 | { 14 | "type": "http", 15 | "direction": "out", 16 | "name": "res" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /.ci/docker/docker-compose-elasticsearch.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | services: 4 | elasticsearch: 5 | extends: 6 | file: docker-compose.yml 7 | service: elasticsearch 8 | node_tests: 9 | extends: 10 | file: docker-compose-node-test.yml 11 | service: node_tests 12 | depends_on: 13 | elasticsearch: 14 | condition: service_healthy 15 | 16 | volumes: 17 | nodeesdata: 18 | driver: local 19 | -------------------------------------------------------------------------------- /.ci/docker/docker-compose-localstack.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | services: 4 | localstack: 5 | extends: 6 | file: docker-compose.yml 7 | service: localstack 8 | node_tests: 9 | extends: 10 | file: docker-compose-node-test.yml 11 | service: node_tests 12 | depends_on: 13 | localstack: 14 | condition: service_healthy 15 | 16 | volumes: 17 | nodelocalstackdata: 18 | driver: local 19 | -------------------------------------------------------------------------------- /docs/docset.yml: -------------------------------------------------------------------------------- 1 | project: 'APM Node.js agent docs' 2 | products: 3 | - id: apm-agent 4 | cross_links: 5 | - apm-agent-rum-js 6 | - apm-aws-lambda 7 | - apm-k8s-attacher 8 | - docs-content 9 | - ecs 10 | - ecs-logging 11 | - ecs-logging-nodejs 12 | - elasticsearch 13 | toc: 14 | - toc: reference 15 | - toc: release-notes 16 | subs: 17 | ecloud: "Elastic Cloud" 18 | apm-lambda-ext: "Elastic APM AWS Lambda extension" 19 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/HttpFnBindingsRes/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindings": [ 3 | { 4 | "authLevel": "Anonymous", 5 | "type": "httpTrigger", 6 | "direction": "in", 7 | "name": "req", 8 | "methods": [ 9 | "get", 10 | "post" 11 | ] 12 | }, 13 | { 14 | "type": "http", 15 | "direction": "out", 16 | "name": "res" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/HttpFnContextDone/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindings": [ 3 | { 4 | "authLevel": "Anonymous", 5 | "type": "httpTrigger", 6 | "direction": "in", 7 | "name": "req", 8 | "methods": [ 9 | "get", 10 | "post" 11 | ] 12 | }, 13 | { 14 | "type": "http", 15 | "direction": "out", 16 | "name": "res" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/HttpFnDistTraceA/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindings": [ 3 | { 4 | "authLevel": "Anonymous", 5 | "type": "httpTrigger", 6 | "direction": "in", 7 | "name": "req", 8 | "methods": [ 9 | "get", 10 | "post" 11 | ] 12 | }, 13 | { 14 | "type": "http", 15 | "direction": "out", 16 | "name": "res" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/HttpFnDistTraceB/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindings": [ 3 | { 4 | "authLevel": "Anonymous", 5 | "type": "httpTrigger", 6 | "direction": "in", 7 | "name": "req", 8 | "methods": [ 9 | "get", 10 | "post" 11 | ] 12 | }, 13 | { 14 | "type": "http", 15 | "direction": "out", 16 | "name": "res" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/HttpFnReturnContext/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindings": [ 3 | { 4 | "authLevel": "Anonymous", 5 | "type": "httpTrigger", 6 | "direction": "in", 7 | "name": "req", 8 | "methods": [ 9 | "get", 10 | "post" 11 | ] 12 | }, 13 | { 14 | "type": "http", 15 | "direction": "out", 16 | "name": "res" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/HttpFnReturnObject/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindings": [ 3 | { 4 | "authLevel": "Anonymous", 5 | "type": "httpTrigger", 6 | "direction": "in", 7 | "name": "req", 8 | "methods": [ 9 | "get", 10 | "post" 11 | ] 12 | }, 13 | { 14 | "type": "http", 15 | "direction": "out", 16 | "name": "$return" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/HttpFnReturnString/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindings": [ 3 | { 4 | "authLevel": "Anonymous", 5 | "type": "httpTrigger", 6 | "direction": "in", 7 | "name": "req", 8 | "methods": [ 9 | "get", 10 | "post" 11 | ] 12 | }, 13 | { 14 | "type": "http", 15 | "direction": "out", 16 | "name": "$return" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /test/instrumentation/modules/http/fixtures/load-http.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | const assert = require('assert'); 8 | const http = require('http'); 9 | assert(http.get, 'http.get is defined'); 10 | assert(http.request, 'http.request is defined'); 11 | -------------------------------------------------------------------------------- /test/instrumentation/modules/http/fixtures/load-http.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | import assert from 'node:assert'; 8 | import http from 'node:http'; 9 | assert(http.get, 'http.get is defined'); 10 | assert(http.request, 'http.request is defined'); 11 | -------------------------------------------------------------------------------- /.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: write 20 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/HttpFnDistTraceB/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | module.exports = async function (context, req) { 8 | context.res = { 9 | status: 200, 10 | body: 'HttpFnDistTraceB body', 11 | }; 12 | }; 13 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/HttpFnReturnResponseData/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindings": [ 3 | { 4 | "authLevel": "Anonymous", 5 | "type": "httpTrigger", 6 | "direction": "in", 7 | "name": "req", 8 | "methods": [ 9 | "get", 10 | "post" 11 | ] 12 | }, 13 | { 14 | "type": "http", 15 | "direction": "out", 16 | "name": "$return" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /lib/instrumentation/modules/koa.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | module.exports = function (koa, agent, { version, enabled }) { 10 | if (!enabled) return koa; 11 | 12 | agent.setFramework({ name: 'koa', version, overwrite: false }); 13 | 14 | return koa; 15 | }; 16 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/HttpFn1/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | module.exports = async function (context, _req) { 8 | context.res = { 9 | headers: { 10 | MyHeaderName: 'MyHeaderValue', 11 | }, 12 | body: 'HttpFn1 body', 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/initapm.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | // For the normal use case an "initapm.js" would look like: 8 | // module.exports = require('elastic-apm-node').start(/* { ... } */) 9 | 10 | module.exports = require('../../../../../').start(); 11 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc4/initapm.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | // For the normal use case an "initapm.js" would look like: 8 | // module.exports = require('elastic-apm-node').start(/* { ... } */) 9 | 10 | module.exports = require('../../../../../').start(); 11 | -------------------------------------------------------------------------------- /lib/opentelemetry-bridge/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Elasticsearch B.V. and other contributors where applicable. 3 | * Licensed under the BSD 2-Clause License; you may not use this file except in 4 | * compliance with the BSD 2-Clause License. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | const { OTelBridgeRunContext } = require('./OTelBridgeRunContext'); 10 | const { setupOTelBridge } = require('./setup'); 11 | 12 | module.exports = { 13 | OTelBridgeRunContext, 14 | setupOTelBridge, 15 | }; 16 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | # Workaround unresolvable peerDependencies between graphql, @apollo-server, 2 | # and apollo-server-express. npm v7 (included with node v15) makes these 3 | # peerDependencies issues an install error. Until the community catches up 4 | # and resolves peerDependencies issues or apm-agent-nodejs.git's tests are 5 | # setup to not have competing deps in "devDependencies", we revert to the 6 | # pre-v7 behavior. 7 | # https://docs.npmjs.com/cli/v7/using-npm/config#legacy-peer-deps 8 | legacy-peer-deps=true 9 | -------------------------------------------------------------------------------- /examples/azure-function-app/Makefile: -------------------------------------------------------------------------------- 1 | APP_NAME=$(USER)-example-azure-function-app 2 | 3 | .PHONY: print-app-name 4 | print-app-name: 5 | @echo "APP_NAME: $(APP_NAME)" 6 | 7 | .PHONY: publish 8 | publish: 9 | func azure functionapp publish "$(APP_NAME)" 10 | 11 | # Note that the Azure Functions log stream is extremely flaky. Don't expect it 12 | # to reliably be able to show logs from the deployed function app. 13 | .PHONY: logstream 14 | logstream: 15 | func azure functionapp logstream "$(APP_NAME)" 16 | -------------------------------------------------------------------------------- /test/instrumentation/azure-functions/fixtures/azfunc3/HttpFnRouteTemplate/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindings": [ 3 | { 4 | "authLevel": "Anonymous", 5 | "type": "httpTrigger", 6 | "direction": "in", 7 | "name": "req", 8 | "methods": [ 9 | "get", 10 | "post" 11 | ], 12 | "route": "products/{category:alpha}/{id:int?}" 13 | }, 14 | { 15 | "type": "http", 16 | "direction": "out", 17 | "name": "res" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /test/stacktraces/fixtures/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2016", 4 | "module": "commonjs", 5 | "outDir": "dist", 6 | "strict": true, 7 | "noImplicitAny": true, 8 | "esModuleInterop": true, 9 | "sourceMap": true, 10 | "inlineSources": true, 11 | // Use a bogus "sourceRoot" path to force source lookup via 12 | // "sourcesContent". 13 | "sourceRoot": "./no-such-dir" 14 | }, 15 | "include": [ 16 | "./src/**/*" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # All development tasks are typically available via npm scripts, i.e. 2 | # `npm run