pragmaticivan / nestjs-otel

OpenTelemetry (Tracing + Metrics) module for Nest framework (node.js) 🔭
Apache License 2.0
560 stars 48 forks source link

SyntaxError: Unexpected token '.' #43

Closed kosmos closed 3 years ago

kosmos commented 3 years ago

I am getting the following error:

/node_modules/nestjs-otel/lib/opentelemetry-core.module.js:74

const { apiMetrics = { enable: false }, } = this.options?.metrics;

^

SyntaxError: Unexpected token '.'

at wrapSafe (internal/modules/cjs/loader.js:1053:16)

at Module._compile (internal/modules/cjs/loader.js:1101:27)

at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)

at Module.load (internal/modules/cjs/loader.js:985:32)

at Function.Module._load (internal/modules/cjs/loader.js:878:14)

at Module.require (internal/modules/cjs/loader.js:1025:19)

at require (internal/modules/cjs/helpers.js:72:18)

at Object.<anonymous> (/srv/viax-service-stl/node_modules/nestjs-otel/lib/opentelemetry.module.js:12:37)

at Module._compile (internal/modules/cjs/loader.js:1137:30)

at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)

With the following configuration:

import { OpenTelemetryModule } from 'nestjs-otel';
import { BatchSpanProcessor } from '@opentelemetry/tracing';
import { JaegerExporter } from '@opentelemetry/exporter-jaeger';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';
import { CompositePropagator } from '@opentelemetry/core';
import { B3InjectEncoding, B3Propagator } from '@opentelemetry/propagator-b3';

const OpenTelemetryModuleConfig = OpenTelemetryModule.forRoot({
  metrics: {
    hostMetrics: true, // Includes Host Metrics
    defaultMetrics: true, // Includes Default Metrics
    apiMetrics: {
      enable: true, // Includes api metrics
      timeBuckets: [],
    },
  },
  nodeSDKConfiguration: {
    spanProcessor: new BatchSpanProcessor(new JaegerExporter({
      host: 'host.docker.internal', // For local testing
      port: 6832,
    })),
    contextManager: new AsyncLocalStorageContextManager(),
    textMapPropagator: new CompositePropagator({
      propagators: [
        new B3Propagator(),
        new B3Propagator({
          injectEncoding: B3InjectEncoding.MULTI_HEADER,
        }),
      ],
    }),
    instrumentations: [getNodeAutoInstrumentations()],
  },
});

packaje.json

 "@opentelemetry/api": "^1.0.1",
    "@opentelemetry/auto-instrumentations-node": "^0.22.0",
    "@opentelemetry/context-async-hooks": "^0.22.0",
    "@opentelemetry/exporter-jaeger": "^0.22.0",
    "@opentelemetry/exporter-zipkin": "^0.22.0",
    "@opentelemetry/host-metrics": "^0.22.0",
    "@opentelemetry/instrumentation": "^0.22.0",
    "@opentelemetry/instrumentation-express": "^0.22.0",
    "@opentelemetry/instrumentation-graphql": "^0.22.0",
    "@opentelemetry/instrumentation-http": "^0.22.0",
    "@opentelemetry/metrics": "^0.22.0",
    "@opentelemetry/node": "^0.22.0",
    "@opentelemetry/propagator-b3": "^0.22.0",
    "@opentelemetry/tracing": "^0.22.0",

Perhaps you know what could be the problem?

kosmos commented 3 years ago

Looks like the problem is that you use ES2020. It is not supported by node 12.

pragmaticivan commented 3 years ago

@kosmos that's the case. I have a ticket to show that once someone installs this package. I've started this project with LTS due to limited time to support multiple versions.