opentelemetry-instrumentation-egg
v0.3.5
Published
OpenTelemetry Egg automatic instrumentation package.
Downloads
275
Readme
opentelemetry-instrumentation-egg
This module provides automatic instrumentation for Egg
.
For automatic instrumentation see the @opentelemetry/node package.
Since Egg
is based on Koa
packaging, we also based it on opentelemetry-instrumentation-koa, just adjusting some details and adaptations.
Installation
This instrumentation relies on HTTP calls to also be instrumented. Make sure you install and enable both, otherwise you will not see any spans being exported from the instrumentation.
npm install --save @opentelemetry/instrumentation-http opentelemetry-instrumentation-egg
Supported Versions
^4.20.0
Usage
OpenTelemetry Egg Instrumentation allows the user to automatically collect trace data and export them to their backend of choice, to give observability to distributed systems.
To load the instrumentation, specify it in the Node Tracer's configuration:
const { NodeTracerProvider } = require('@opentelemetry/node')
const { registerInstrumentations } = require('@opentelemetry/instrumentation')
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http')
const { EggInstrumentation } = require('opentelemetry-instrumentation-egg')
const provider = new NodeTracerProvider()
provider.register()
registerInstrumentations({
instrumentations: [
// Egg instrumentation expects HTTP layer to be instrumented
new HttpInstrumentation(),
new EggInstrumentation(),
],
})
Egg Instrumentation Options
Egg instrumentation has few options available to choose from. You can set the following:
| Options | Type | Example | Description |
| ------------------ | ----------------- | --------------------- | -------------------------------- |
| ignoreLayers
| IgnoreMatcher[]
| [/^\/_internal\//]
| Ignore layers that by match. |
| ignoreLayersType
| KoaLayerType[]
| ['request_handler']
| Ignore layers of specified type. |
ignoreLayers
accepts an array of elements of types:
string
for full match of the path,RegExp
for partial match of the path,function
in the form of(path) => boolean
for custom logic.
ignoreLayersType
accepts an array of following strings:
router
is the name ofegg app.Router
,middleware
,
By default, we disable the following egg
default middlewares:
export const defaultConfig: EggInstrumentationConfig = {
ignoreLayers: [
(name: string) => {
return [
'middleware - meta',
'middleware - siteFile',
'middleware - notfound',
'middleware - static',
'middleware - overrideMethod',
'middleware - session',
'middleware - i18n',
'middleware - bodyParser',
'middleware - securities',
'middleware - eggLoaderTrace',
].includes(name)
},
],
}
Useful links
- For more information on OpenTelemetry, visit: https://opentelemetry.io/
- For more about OpenTelemetry JavaScript: https://github.com/open-telemetry/opentelemetry-js
References
License
MIT © zcong1993