Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTLPExporterBrowserBase cannot be invoked without 'new' #2943

Closed
cchatfield opened this issue Apr 30, 2022 · 6 comments · Fixed by #2952
Closed

OTLPExporterBrowserBase cannot be invoked without 'new' #2943

cchatfield opened this issue Apr 30, 2022 · 6 comments · Fixed by #2952
Assignees
Labels
bug Something isn't working

Comments

@cchatfield
Copy link

cchatfield commented Apr 30, 2022

Please answer these questions before submitting a bug report.

What version of OpenTelemetry are you using?

1.2.0 with 0.28.0

    "@opentelemetry/api": "^1.1.0",
    "@opentelemetry/context-zone": "^1.2.0",
    "@opentelemetry/exporter-trace-otlp-http": "^0.28.0",
    "@opentelemetry/otlp-exporter-base": "^0.28.0",
    "@opentelemetry/resources": "^1.2.0",
    "@opentelemetry/sdk-trace-base": "^1.2.0",
    "@opentelemetry/sdk-trace-web": "^1.2.0",
    "@opentelemetry/semantic-conventions": "^1.2.0",

What version of Node are you using?

14 +

Please provide the code you used to setup the OpenTelemetry SDK

import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
import { OTLPExporterConfigBase } from '@opentelemetry/otlp-exporter-base';
import { W3CTraceContextPropagator } from '@opentelemetry/core';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource } from '@opentelemetry/resources';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import * as otel from '@opentelemetry/api';
import { ROOT_CONTEXT } from '@opentelemetry/api';

...

initTracing() {
    this.provider = new WebTracerProvider({
      resource: new Resource({
        [SemanticResourceAttributes.HOST_NAME]: this.document.location.host,
        [SemanticResourceAttributes.SERVICE_NAME]: this.environment?.telemetry?.trace?.serviceName,
      }),
    });
    const collectorExporterConfig: OTLPExporterConfigBase = {
      url: 'redacted',
    };
    const exporter = new OTLPTraceExporter(collectorExporterConfig);
    this.provider.addSpanProcessor(
      new BatchSpanProcessor(exporter, {
        // The maximum queue size. After the size is reached spans are dropped.
        maxQueueSize: 100,
        // The maximum batch size of every export. It must be smaller or equal to maxQueueSize.
        maxExportBatchSize: 10,
        // The interval between two consecutive exports
        scheduledDelayMillis: 500,
        // How long the export can run before it is cancelled
        exportTimeoutMillis: 30000,
      })
    );
    this.provider.register({
      // Changing default contextManager to use ZoneContextManager - supports asynchronous operations - optional
      contextManager: new ZoneContextManager(),
    });
    this.tracer = otel.trace.getTracer('redacted');
  }

...

What did you do?

    const exporter = new OTLPTraceExporter(collectorExporterConfig);

If possible, provide a recipe for reproducing the error.

What did you expect to see?

exporter instantiated properly

What did you see instead?

throws an error

TypeError: Class constructor OTLPExporterBrowserBase cannot be invoked without 'new'
    function OTLPTraceExporter(config) {
        if (config === void 0) { config = {}; }
>>>>>>        var _this = _super.call(this, config) || this;
        _this._headers = Object.assign(_this._headers, baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS));
        return _this;
    }

Additional context

worked prior to 1.2.0 and 0.28.0 update
Angular 13.1 application

@cchatfield cchatfield added the bug Something isn't working label Apr 30, 2022
@cchatfield
Copy link
Author

If I change the import

import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';

to

import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http/build/esnext';

it is working. Not sure why it was defaulting to esm or if the esm module target was below es6/es2015

@dyladan
Copy link
Member

dyladan commented May 4, 2022

The code you provided shown in the error:

    function OTLPTraceExporter(config) {
        if (config === void 0) { config = {}; }
>>>>>>        var _this = _super.call(this, config) || this;
        _this._headers = Object.assign(_this._headers, baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS));
        return _this;
    }

Does not appear in the packages we publish. Are you sure you're not doing some sort of transpilation step?

@cchatfield
Copy link
Author

I was concerned about that as well.

I created a new project with npm init and added "@opentelemetry/exporter-trace-otlp-http": "^0.28.0" and that code is there.

In the node_module folder under @opentelemetry/exporter-trace-otlp-http/build/esm/platform/browser/OTLPTraceExporter.js

/**
 * Collector Trace Exporter for Web
 */
var OTLPTraceExporter = /** @class */ (function (_super) {
    __extends(OTLPTraceExporter, _super);
    function OTLPTraceExporter(config) {
        if (config === void 0) { config = {}; }
        var _this = _super.call(this, config) || this;
        _this._headers = Object.assign(_this._headers, baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS));
        return _this;
    }
    OTLPTraceExporter.prototype.convert = function (spans) {
        return toOTLPExportTraceServiceRequest(spans, this, true);
    };
    OTLPTraceExporter.prototype.getDefaultUrl = function (config) {
        return typeof config.url === 'string'
            ? config.url
            : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0
                ? getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
                : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
                    ? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
                    : DEFAULT_COLLECTOR_URL;
    };
    return OTLPTraceExporter;
}(OTLPExporterBrowserBase));

package.json

{
  "name": "ot-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@opentelemetry/exporter-trace-otlp-http": "^0.28.0"
  }
}

package-lock.json

{
  "name": "ot-test",
  "version": "1.0.0",
  "lockfileVersion": 1,
  "requires": true,
  "dependencies": {
    "@opentelemetry/core": {
      "version": "1.2.0",
      "resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-1.2.0.tgz",
      "integrity": "sha512-QiKp8fBbT9ZhRTP+ZVVMyqH62tD/ZQa4gWPi+GnpNetvK1SWPO/8DmRpaSXHwAhu5FWUDJrbFgpLsrDd1zGPOw==",
      "requires": {
        "@opentelemetry/semantic-conventions": "1.2.0"
      }
    },
    "@opentelemetry/exporter-trace-otlp-http": {
      "version": "0.28.0",
      "resolved": "https://registry.npmjs.org/@opentelemetry/exporter-trace-otlp-http/-/exporter-trace-otlp-http-0.28.0.tgz",
      "integrity": "sha512-5GFN2NSXDikEMUphN5NT3tY+XQnPPkZhGVhhy+czf3rGjrcVRQqyYYqCm8/Q4kxxUr/hUx91UBt+DCxSqQLhpA==",
      "requires": {
        "@opentelemetry/core": "1.2.0",
        "@opentelemetry/otlp-exporter-base": "0.28.0",
        "@opentelemetry/resources": "1.2.0",
        "@opentelemetry/sdk-trace-base": "1.2.0"
      }
    },
    "@opentelemetry/otlp-exporter-base": {
      "version": "0.28.0",
      "resolved": "https://registry.npmjs.org/@opentelemetry/otlp-exporter-base/-/otlp-exporter-base-0.28.0.tgz",
      "integrity": "sha512-RelJBa2rFO63jCPRTzWxs+DWPRBrO4Y5Fag1uXur8dwnjSmKlSBwRzfz7F+pVwLf3kqm5EDzCCoYzdL1/aH1tg==",
      "requires": {
        "@opentelemetry/core": "1.2.0"
      }
    },
    "@opentelemetry/resources": {
      "version": "1.2.0",
      "resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-1.2.0.tgz",
      "integrity": "sha512-S5ZlZa2JF+1qhiF7eb3tTtDfKmTODO//pvam9vEyZvr+/At45rIQ7cyznRdMWCppZbholwXWXnrKml29IIG9vQ==",
      "requires": {
        "@opentelemetry/core": "1.2.0",
        "@opentelemetry/semantic-conventions": "1.2.0"
      }
    },
    "@opentelemetry/sdk-trace-base": {
      "version": "1.2.0",
      "resolved": "https://registry.npmjs.org/@opentelemetry/sdk-trace-base/-/sdk-trace-base-1.2.0.tgz",
      "integrity": "sha512-eHrG9c9OhoDhUmMe63Qzgpcvlgxr2L7BFBbbj2DdZu3vGstayytTT6TDv6mz727lXBqR1HXMbqTGVafS07r3bg==",
      "requires": {
        "@opentelemetry/core": "1.2.0",
        "@opentelemetry/resources": "1.2.0",
        "@opentelemetry/semantic-conventions": "1.2.0"
      }
    },
    "@opentelemetry/semantic-conventions": {
      "version": "1.2.0",
      "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.2.0.tgz",
      "integrity": "sha512-BNKB9fiYVghALJzCuWO3eNYfdTExPVK4ykrtmfNfy0A6UWYhOYjGMXifUmkunDJNL8ju9tBobo8jF0WR9zGy1Q=="
    }
  }
}

@dyladan dyladan self-assigned this May 4, 2022
@dyladan
Copy link
Member

dyladan commented May 4, 2022

Ah i was looking in build/src not build/esm. Seems like the issue is that the base class is in otlp-exporter-base which is missing the esm and esnext directories in the files array of the package.json which makes it fall back to "main": "./build/src/index.js" when `"module": "./build/esm/index.js" is missing.

@domasx2
Copy link
Contributor

domasx2 commented May 19, 2022

Hey, when can we expect a new npm release with fix for this?

@legendecas
Copy link
Member

@domasx2 v0.29.2 containing the fixes has been released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants