diff --git a/nodejs/packages/layer/package.json b/nodejs/packages/layer/package.json index 899de06cb3..91ebc67e01 100644 --- a/nodejs/packages/layer/package.json +++ b/nodejs/packages/layer/package.json @@ -27,15 +27,17 @@ "node": ">=16.0.0" }, "dependencies": { - "@opentelemetry/api": "^1.7.0", + "@opentelemetry/api": "^1.9.0", + "@opentelemetry/api-logs": "^0.52.1", + "@opentelemetry/exporter-logs-otlp-proto": "^0.52.1", "@opentelemetry/auto-configuration-propagators": "^0.2.0", "@opentelemetry/exporter-metrics-otlp-proto": "^0.52.1", "@opentelemetry/exporter-trace-otlp-proto": "^0.52.1", "@opentelemetry/instrumentation": "^0.52.1", "@opentelemetry/instrumentation-aws-lambda": "^0.43.0", - "@opentelemetry/instrumentation-aws-sdk": "^0.43.0", + "@opentelemetry/instrumentation-aws-sdk": "^0.43.1", "@opentelemetry/instrumentation-dns": "^0.38.0", - "@opentelemetry/instrumentation-express": "^0.41.0", + "@opentelemetry/instrumentation-express": "^0.41.1", "@opentelemetry/instrumentation-graphql": "^0.42.0", "@opentelemetry/instrumentation-grpc": "^0.52.1", "@opentelemetry/instrumentation-hapi": "^0.40.0", @@ -47,17 +49,18 @@ "@opentelemetry/instrumentation-net": "^0.38.0", "@opentelemetry/instrumentation-pg": "^0.43.0", "@opentelemetry/instrumentation-redis": "^0.41.0", - "@opentelemetry/propagator-aws-xray": "^1.3.1", - "@opentelemetry/resource-detector-aws": "^1.3.4", - "@opentelemetry/resources": "^1.18.1", - "@opentelemetry/sdk-metrics": "^1.18.1", - "@opentelemetry/sdk-trace-base": "^1.18.1", - "@opentelemetry/sdk-trace-node": "^1.18.1" + "@opentelemetry/propagator-aws-xray": "^1.25.1", + "@opentelemetry/resource-detector-aws": "^1.5.2", + "@opentelemetry/resources": "^1.25.1", + "@opentelemetry/sdk-logs": "^0.52.1", + "@opentelemetry/sdk-metrics": "^1.25.1", + "@opentelemetry/sdk-trace-base": "^1.25.1", + "@opentelemetry/sdk-trace-node": "^1.25.1" }, "devDependencies": { - "@types/mocha": "^10.0.6", + "@types/mocha": "^10.0.7", "@types/sinon": "^17.0.3", - "mocha": "^10.4.0", + "mocha": "^10.7.0", "sinon": "^18.0.0", "ts-node": "^10.9.2" } diff --git a/nodejs/packages/layer/src/wrapper.ts b/nodejs/packages/layer/src/wrapper.ts index 1cc8bf6fbd..fa55363f7c 100644 --- a/nodejs/packages/layer/src/wrapper.ts +++ b/nodejs/packages/layer/src/wrapper.ts @@ -13,17 +13,25 @@ import { processDetector, } from '@opentelemetry/resources'; import { AwsInstrumentation, AwsSdkInstrumentationConfig } from '@opentelemetry/instrumentation-aws-sdk'; -import { AwsLambdaInstrumentation } from '@opentelemetry/instrumentation-aws-lambda'; +import { AwsLambdaInstrumentation, AwsLambdaInstrumentationConfig} from '@opentelemetry/instrumentation-aws-lambda'; import { diag, DiagConsoleLogger, DiagLogLevel, } from "@opentelemetry/api"; import { getEnv } from '@opentelemetry/core'; -import { AwsLambdaInstrumentationConfig } from '@opentelemetry/instrumentation-aws-lambda'; import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto'; -import { MeterProvider, MeterProviderOptions } from '@opentelemetry/sdk-metrics'; +import { MeterProvider, MeterProviderOptions, PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics'; +import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto'; +import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-proto'; import { getPropagator } from '@opentelemetry/auto-configuration-propagators'; +import { + LoggerProvider, + SimpleLogRecordProcessor, + ConsoleLogRecordExporter, + LoggerProviderConfig, +} from '@opentelemetry/sdk-logs'; +import { logs } from '@opentelemetry/api-logs'; function defaultConfigureInstrumentations() { // Use require statements for instrumentation to avoid having to have transitive dependencies on all the typescript @@ -69,6 +77,7 @@ declare global { function configureMeterProvider(meterProvider: MeterProvider): void function configureLambdaInstrumentation(config: AwsLambdaInstrumentationConfig): AwsLambdaInstrumentationConfig function configureInstrumentations(): Instrumentation[] + function configureLoggerProvider(loggerProvider: LoggerProvider): void } console.log('Registering OpenTelemetry'); @@ -129,8 +138,14 @@ async function initializeProvider() { tracerProvider.register(sdkRegistrationConfig); // Configure default meter provider (doesn't export metrics) + const metricExporter = new OTLPMetricExporter(); let meterConfig: MeterProviderOptions = { resource, + readers: [ + new PeriodicExportingMetricReader({ + exporter: metricExporter, + }) + ], } if (typeof configureMeter === 'function') { meterConfig = configureMeter(meterConfig); @@ -141,11 +156,31 @@ async function initializeProvider() { configureMeterProvider(meterProvider) } + const logExporter = new OTLPLogExporter(); + let loggerConfig: LoggerProviderConfig = { + resource, + } + const loggerProvider = new LoggerProvider(loggerConfig); + if (typeof configureLoggerProvider === 'function') { + configureLoggerProvider(loggerProvider) + } else { + loggerProvider.addLogRecordProcessor(new SimpleLogRecordProcessor(logExporter)); + logs.setGlobalLoggerProvider(loggerProvider); + } + + // logging for debug + if (logLevel === DiagLogLevel.DEBUG) { + loggerProvider.addLogRecordProcessor( + new SimpleLogRecordProcessor(new ConsoleLogRecordExporter()) + ); + } + // Re-register instrumentation with initialized provider. Patched code will see the update. registerInstrumentations({ instrumentations, tracerProvider, - meterProvider + meterProvider, + loggerProvider, }); } initializeProvider();