-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolved issue in setLogger function with winston logger (#1522)
refs INSTA-24448
- Loading branch information
1 parent
1a8f05b
commit 52f102e
Showing
4 changed files
with
114 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/collector/test/tracing/logger/instana-logger/app-instana-receives-winston-logger.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* (c) Copyright IBM Corp. 2025 | ||
*/ | ||
|
||
/* eslint-disable no-console */ | ||
|
||
'use strict'; | ||
|
||
// NOTE: c8 bug https://github.com/bcoe/c8/issues/166 | ||
process.on('SIGTERM', () => { | ||
process.disconnect(); | ||
process.exit(0); | ||
}); | ||
|
||
const agentPort = process.env.AGENT_PORT; | ||
const winston = require('winston'); | ||
const instana = require('../../../..')({ | ||
agentPort, | ||
level: 'warn', | ||
tracing: { | ||
enabled: process.env.TRACING_ENABLED !== 'false', | ||
forceTransmissionStartingAt: 1 | ||
} | ||
}); | ||
|
||
instana.setLogger( | ||
winston.createLogger({ | ||
level: 'info' | ||
}) | ||
); | ||
|
||
let instanaLogger; | ||
instanaLogger = require('../../../../src/logger').getLogger('test-module-name', newLogger => { | ||
instanaLogger = newLogger; | ||
}); | ||
|
||
const bodyParser = require('body-parser'); | ||
const express = require('express'); | ||
const morgan = require('morgan'); | ||
const port = require('../../../test_util/app-port')(); | ||
const app = express(); | ||
const logPrefix = `winston App [Instana receives winston logger] (${process.pid}):\t`; | ||
|
||
if (process.env.WITH_STDOUT) { | ||
app.use(morgan(`${logPrefix}:method :url :status`)); | ||
} | ||
|
||
app.use(bodyParser.json()); | ||
|
||
app.get('/', (req, res) => { | ||
res.sendStatus(200); | ||
}); | ||
|
||
app.get('/trigger', (req, res) => { | ||
instanaLogger.error('An error logged by Instana - this must not be traced'); | ||
res.sendStatus(200); | ||
}); | ||
|
||
app.listen(port, () => { | ||
log(`Listening on port: ${port}`); | ||
}); | ||
|
||
function log() { | ||
const args = Array.prototype.slice.call(arguments); | ||
args[0] = logPrefix + args[0]; | ||
console.log.apply(console, args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters