3.10.2 • Published 6 months ago

@midwayjs-plus/otel v3.10.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

midwayjs open-telemetry module

PRs Welcome

this is a sub package for midway.

Install

$ npm install --save @opentelemetry/api
$ npm install --save @opentelemetry/sdk-node
$ npm install --save @opentelemetry/auto-instrumentations-node

Install component if you want decorator support.

$ npm i @midwayjs/otel@3 --save

Enable open-telemetry

open-telemetry must be loaded at the first of user code.

you can add at bootstrap.js.

const process = require('process');
const opentelemetry = require('@opentelemetry/sdk-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-base');
const { Resource } = require('@opentelemetry/resources');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { Bootstrap } = require('@midwayjs/bootstrap');

// configure the SDK to export telemetry data to the console
// enable all auto-instrumentations from the meta package
const traceExporter = new ConsoleSpanExporter();
const sdk = new opentelemetry.NodeSDK({
  resource: new Resource({
    [SemanticResourceAttributes.SERVICE_NAME]: 'my-service',
  }),
  traceExporter,
  instrumentations: [getNodeAutoInstrumentations()]
});

// initialize the SDK and register with the OpenTelemetry API
// this enables the API to record telemetry
sdk.start()
  .then(() => {
    return Bootstrap
      .configure(/**/)
      .run();
  });

// gracefully shut down the SDK on process exit
process.on('SIGTERM', () => {
  sdk.shutdown()
    .then(() => console.log('Tracing terminated'))
    .catch((error) => console.log('Error terminating tracing', error))
    .finally(() => process.exit(0));
});

You can find more information at opentelemetry-js

Decorator Support

Enable component first.

import { Configuration } from '@midwayjs/decorator';
import * as koa from '@midwayjs/koa';
import * as otel from '@midwayjs/otel';

@Configuration({
  imports: [
    koa,
    otel
  ]
})
export class MainConfiguration {
}

Otel component add a @Trace decorator for method.

export class UserService {

  @Trace('user.get')
  async getUser() {
    // ...
  }
}

it will create a new span in current trace.

License

MIT

3.10.1

6 months ago

3.10.0

7 months ago

3.10.2

6 months ago

3.9.6

11 months ago

3.9.3

1 year ago

3.9.2

1 year ago

3.9.1

1 year ago

3.9.5

1 year ago

3.9.4

1 year ago

3.6.0

1 year ago

3.9.0

1 year ago

3.3.24

2 years ago

3.3.22

2 years ago

3.3.23

2 years ago

3.3.21

2 years ago

3.3.20

2 years ago

3.3.19

2 years ago

3.3.18

2 years ago

3.3.17

2 years ago

3.3.16

2 years ago

3.3.15

2 years ago

3.3.14

2 years ago

3.3.13

2 years ago

3.3.12

2 years ago

3.3.11

2 years ago

3.3.10

2 years ago

3.3.9

2 years ago

3.3.8

2 years ago

3.3.7

2 years ago

3.3.6

2 years ago