Skip to content

Commit

Permalink
Add custom attributes to server telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Johnston committed Oct 9, 2023
1 parent 93e50a6 commit fcf2d42
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions blog-app/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ const os = require('os');
const path = require('path');
const appInsights = require('applicationinsights');

if (process.env['APPLICATIONINSIGHTS_CONNECTION_STRING']) {
appInsights.setup()
.start();
console.log('Azure monitor configured');
} else {
console.log('Application insights not configured.');
};

const template = fs
.readFileSync(path.join(join(process.cwd(), 'dist/blog-app/browser'), 'index.html'))
.toString();
Expand All @@ -30,6 +22,21 @@ const version = fs
.readFileSync(path.join(join(process.cwd(), 'dist/blog-app/browser/assets'), 'version.txt'))
.toString().trim();

const resOrigin = `${os.hostname()} ${process.cwd()} ${version}`;

if (process.env['APPLICATIONINSIGHTS_CONNECTION_STRING']) {
appInsights.setup()
.start();
appInsights.defaultClient.commonProperties = {
node: os.hostname(),
slot: process.cwd(),
version: version
};
console.log('Azure monitor configured');
} else {
console.log('Application insights not configured.');
};

global['window'] = domino.createWindow(template, 'SERVER');
global['document'] = window.document;

Expand All @@ -49,7 +56,6 @@ export function app(): express.Express {
server.set('views', distFolder);

server.use((req, res, next) => {
const resOrigin = `${os.hostname()} ${process.cwd()} ${version}`;
res.setHeader('X-Origin-Node', resOrigin);
res.cookie('originnode', resOrigin, { httpOnly: false });
next();
Expand Down

0 comments on commit fcf2d42

Please sign in to comment.