Skip to content

Instantly share code, notes, and snippets.

@trentm
Created September 14, 2021 17:25
Show Gist options
  • Save trentm/54a1bd3ced2be1346a4441cd080231fd to your computer and use it in GitHub Desktop.
Save trentm/54a1bd3ced2be1346a4441cd080231fd to your computer and use it in GitHub Desktop.
diff --git a/.env b/.env
index fc10945..3f08e96 100644
--- a/.env
+++ b/.env
@@ -1,6 +1,6 @@
# Below envs are needed by the apm agent for elastic
-ELASTIC_APM_DISABLE_SEND=false
+ELASTIC_APM_DISABLE_SEND=true
ELASTIC_APM_METRICS_INTERVAL=0
ELASTIC_APM_CAPTURE_EXCEPTIONS=true
ELASTIC_APM_LOG_UNCAUGHT_EXCEPTIONS=true
-ELASTIC_APM_CAPTURE_ERROR_LOG_STACK_TRACES=always
\ No newline at end of file
+ELASTIC_APM_CAPTURE_ERROR_LOG_STACK_TRACES=always
diff --git a/app.ts b/app.ts
index d7f3baa..e6d1f2f 100644
--- a/app.ts
+++ b/app.ts
@@ -1,5 +1,7 @@
// Configuration of apm is inside .env file variables.
-const apm = require("elastic-apm-node/start");
+import 'elastic-apm-node/start'
+// Or this:
+// import apm from './elastic-apm-node/start'; apm
import express from "express";
import { AddressInfo } from "net";
diff --git a/package-lock.json b/package-lock.json
index 7e1308b..ca51af3 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -7513,6 +7513,11 @@
"wildcard": "^2.0.0"
}
},
+ "webpack-node-externals": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/webpack-node-externals/-/webpack-node-externals-3.0.0.tgz",
+ "integrity": "sha512-LnL6Z3GGDPht/AigwRh2dvL9PQPFQ8skEpVrWZXLWBYmqcaojHNN0onvHzie6rq7EWKrrBfPYqNEzTJgiwEQDQ=="
+ },
"webpack-sources": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-2.3.0.tgz",
diff --git a/package.json b/package.json
index f3ede6a..4b4ff6a 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,7 @@
"main": "app.js",
"scripts": {
"build-release": "webpack --mode production",
- "start": "export $(cat .env | grep \"^[^#;]\" |xargs) && node -r elastic-apm-node/start --unhandled-rejections=strict ./dist/app.js",
+ "start": "export $(cat .env | grep \"^[^#;]\" |xargs) && node --unhandled-rejections=strict ./dist/app.js",
"debug": "export DEBUG=* && tsc && node --unhandled-rejections=strict ./dist/app.js",
"test": "jest"
},
@@ -22,6 +22,7 @@
"elastic-apm-node": "^3.18.0",
"express": "^4.17.1",
"express-winston": "^4.1.0",
+ "webpack-node-externals": "^3.0.0",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.5"
},
diff --git a/webpack.config.js b/webpack.config.js
index dddae8a..e741a32 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -1,5 +1,6 @@
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
+const nodeExternals = require('webpack-node-externals');
module.exports = {
entry: path.join(__dirname, '/app.ts'),
@@ -22,8 +23,9 @@ module.exports = {
new CleanWebpackPlugin()
],
target: 'node',
+ externals: [nodeExternals()],
node: {
__dirname: true,
__filename: false,
}
-};
\ No newline at end of file
+};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment