diff --git a/package.json b/package.json index 8ed2c13..5694a6b 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,14 @@ "@biothings-explorer/utils": "workspace:../utils", "@bull-board/api": "^5.9.1", "@bull-board/express": "^5.9.1", + "@opentelemetry/api": "^1.7.0", + "@opentelemetry/auto-instrumentations-node": "^0.40.2", + "@opentelemetry/exporter-metrics-otlp-proto": "^0.45.1", + "@opentelemetry/exporter-trace-otlp-proto": "^0.45.1", + "@opentelemetry/resources": "^1.18.1", + "@opentelemetry/sdk-metrics": "^1.18.1", + "@opentelemetry/sdk-node": "^0.45.1", + "@opentelemetry/sdk-trace-node": "^1.18.1", "@sentry/node": "^7.74.1", "@sentry/profiling-node": "^1.2.1", "axios": "^0.27.2", diff --git a/src/config/index.js b/src/config/index.js index ba2b7ad..b7b8a21 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -122,4 +122,8 @@ module.exports = class Config { debug(error); } } + + setOpenTel() { + + } }; diff --git a/src/controllers/opentelemetry.js b/src/controllers/opentelemetry.js new file mode 100644 index 0000000..86602ec --- /dev/null +++ b/src/controllers/opentelemetry.js @@ -0,0 +1,34 @@ +/*instrumentation.js*/ +const opentelemetry = require('@opentelemetry/sdk-node'); +const { + getNodeAutoInstrumentations, +} = require('@opentelemetry/auto-instrumentations-node'); +const { + OTLPTraceExporter, +} = require('@opentelemetry/exporter-trace-otlp-proto'); +const { + OTLPMetricExporter, +} = require('@opentelemetry/exporter-metrics-otlp-proto'); +const { PeriodicExportingMetricReader, ConsoleMetricExporter } = require('@opentelemetry/sdk-metrics'); +const { Resource } = require('@opentelemetry/resources') +const { ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-node'); + +const sdk = new opentelemetry.NodeSDK({ + traceExporter: new OTLPTraceExporter({ + url: process.env.JAEGER_URL ?? 'http://localhost:4318/v1/traces', + // optional - collection of custom headers to be sent with each request, empty by default + headers: {}, + }), + metricReader: new PeriodicExportingMetricReader({ + exporter: new OTLPMetricExporter({ + url: process.env.JAEGER_URL ?? 'http://localhost:4318/v1/traces', + headers: {}, // an optional object containing custom headers to be sent with each request + concurrencyLimit: 1, // an optional limit on pending requests + }), + }), + instrumentations: [getNodeAutoInstrumentations()], + resource: new Resource({ + "service.name": "biothings-explorer" + }) +}); +sdk.start(); \ No newline at end of file