-
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.
feat(collector): tracing all spans when client app is using ES modules (
#672) Added support for client app being an ESM app. Unsupported: ESM instrumentations. We will extend the esm-loader.mjs to add this support asap. But this missing feature should not affect a customer right now, because there are no known bigger NPM modules, which have dropped the support for CJS (except e.g. got). Furthermore we do not offer an API to add custom instrumentations.
- Loading branch information
Showing
47 changed files
with
5,135 additions
and
12 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
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
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,31 @@ | ||
/* | ||
* (c) Copyright IBM Corp. 2022 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* We currently only instrument CJS modules. As soon as we want | ||
* to instrument ES modules (such as `got` v12), the requireHook will | ||
* no longer work. Therefor we would need to wrap the target ES module | ||
* with our instrumentations using the resolve & load hook. | ||
* | ||
* Usage: | ||
* node --experimental-loader=@instana/collector/esm-loader.mjs server.js | ||
* | ||
* NOTE: When using ESM the customer can only configure the collector with | ||
* ENV variables. | ||
*/ | ||
|
||
import instana from './src/index.js'; | ||
instana(); | ||
|
||
/* | ||
export async function resolve(specifier, context, nextResolve) { | ||
return nextResolve(specifier, context, nextResolve); | ||
} | ||
export async function load(url, context, nextLoad) { | ||
return nextLoad(url, context, nextLoad); | ||
} | ||
*/ |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* (c) Copyright IBM Corp. 2021 | ||
* (c) Copyright Instana Inc. and contributors 2019 | ||
*/ | ||
|
||
/* eslint-disable no-console */ | ||
|
||
'use strict'; | ||
|
||
import instanaFactory from '../../../src/index.js'; | ||
const instana = instanaFactory(); | ||
|
||
import express from 'express'; | ||
import morgan from 'morgan'; | ||
import bodyParser from 'body-parser'; | ||
|
||
const app = express(); | ||
const logPrefix = `API: Server (${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('/span/active', (req, res) => { | ||
const span = instana.currentSpan(); | ||
res.json({ | ||
span: serialize(span) | ||
}); | ||
}); | ||
|
||
app.get('/span/annotate-path-flat-string', (req, res) => { | ||
const span = instana.currentSpan(); | ||
span.annotate('sdk.custom.tags.key', 'custom nested tag value'); | ||
span.annotate('http.path_tpl', '/custom/{template}'); | ||
span.annotate('..redundant....dots..', 'will be silently dropped'); | ||
res.json({ | ||
span: serialize(span) | ||
}); | ||
}); | ||
|
||
app.get('/span/annotate-path-array', (req, res) => { | ||
const span = instana.currentSpan(); | ||
span.annotate(['sdk', 'custom', 'tags', 'key'], 'custom nested tag value'); | ||
span.annotate(['http', 'path_tpl'], '/custom/{template}'); | ||
res.json({ | ||
span: serialize(span) | ||
}); | ||
}); | ||
|
||
app.get('/span/manuallyended', (req, res) => { | ||
const span = instana.currentSpan(); | ||
span.disableAutoEnd(); | ||
setTimeout(() => { | ||
span.end(42); | ||
res.json({ | ||
span: serialize(span) | ||
}); | ||
}, 50); | ||
}); | ||
|
||
app.listen(process.env.APP_PORT, () => { | ||
log(`Listening on port: ${process.env.APP_PORT}`); | ||
}); | ||
|
||
function serialize(span) { | ||
return { | ||
traceId: span.getTraceId(), | ||
spanId: span.getSpanId(), | ||
parentSpanId: span.getParentSpanId(), | ||
name: span.getName(), | ||
isEntry: span.isEntrySpan(), | ||
isExit: span.isExitSpan(), | ||
isIntermediate: span.isIntermediateSpan(), | ||
timestamp: span.getTimestamp(), | ||
duration: span.getDuration(), | ||
errorCount: span.getErrorCount(), | ||
data: span.span ? span.span.data : null, | ||
handleConstructorName: span.constructor.name | ||
}; | ||
} | ||
|
||
function log() { | ||
const args = Array.prototype.slice.call(arguments); | ||
args[0] = logPrefix + args[0]; | ||
console.log.apply(console, args); | ||
} |
Oops, something went wrong.