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

(instrumentation-mongodb) - Cannot find name 'Document'. #1190

Closed
97amarnathk opened this issue Sep 20, 2022 · 4 comments · Fixed by #1194
Closed

(instrumentation-mongodb) - Cannot find name 'Document'. #1190

97amarnathk opened this issue Sep 20, 2022 · 4 comments · Fixed by #1194
Assignees
Labels
bug Something isn't working priority:p1 Bugs which cause problems in end-user applications such as crashes, data inconsistencies

Comments

@97amarnathk
Copy link

What version of OpenTelemetry are you using?

@opentelemetry-api 1.2.0

What version of Node are you using?

14.17.1

What did you do?

I have a private nodejs service to which I am trying to add openTelemetry

  1. install open telemetry and http, grpc instrumentation (this is working fine)
  2. installed mongodb instrumentation
yarn add @opentelemetry/instrumentation-mongodb                                   
  1. built my node module
yarn build

What did you expect to see?

My module should have been built successfully

What did you see instead?

Typescript fails to build it, with error -

../../node_modules/@opentelemetry/instrumentation-mongodb/build/src/types.d.ts:86:27 - error TS2304: Cannot find name 'Document'.

86     command(ns: any, cmd: Document, options: undefined | unknown, callback: any): void;
                             ~~~~~~~~


Found 1 error.

Additional context

Working code

import { Tracer } from '@opentelemetry/api';
import { JaegerExporter } from '@opentelemetry/exporter-jaeger';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { GrpcInstrumentation } from '@opentelemetry/instrumentation-grpc';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { MongoDBInstrumentation } from '@opentelemetry/instrumentation-mongodb';
import { Resource } from '@opentelemetry/resources';
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';

export function initTracer(serviceName: string): Tracer {
  const resource = Resource.default().merge(
    new Resource({
      [SemanticResourceAttributes.SERVICE_NAME]: serviceName,
    })
  );

  const provider = new NodeTracerProvider({
    resource: resource,
  });

  const exporter = new JaegerExporter({ endpoint: 'http://localhost:14268/api/traces' });
  const processor = new BatchSpanProcessor(exporter);

  provider.addSpanProcessor(processor);
  provider.register();

  registerInstrumentations({
    instrumentations: [new HttpInstrumentation(), new GrpcInstrumentation(), new MongoDBInstrumentation()],
  });

  const tracer = provider.getTracer(serviceName);

  return tracer;
}

Failing build

import { Tracer } from '@opentelemetry/api';
import { JaegerExporter } from '@opentelemetry/exporter-jaeger';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { GrpcInstrumentation } from '@opentelemetry/instrumentation-grpc';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { Resource } from '@opentelemetry/resources';
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';

export function initTracer(serviceName: string): Tracer {
  const resource = Resource.default().merge(
    new Resource({
      [SemanticResourceAttributes.SERVICE_NAME]: serviceName,
    })
  );

  const provider = new NodeTracerProvider({
    resource: resource,
  });

  const exporter = new JaegerExporter({ endpoint: 'http://localhost:14268/api/traces' });
  const processor = new BatchSpanProcessor(exporter);

  provider.addSpanProcessor(processor);
  provider.register();

  registerInstrumentations({
    instrumentations: [new HttpInstrumentation(), new GrpcInstrumentation()],
  });

  const tracer = provider.getTracer(serviceName);

  return tracer;
}
@97amarnathk 97amarnathk added the bug Something isn't working label Sep 20, 2022
@97amarnathk
Copy link
Author

I think we need to import type for Document from library bson
ref: https://github.com/mongodb/node-mongodb-native/blob/v4.2.2/src/cmap/connection.ts#L38

@Flarna
Copy link
Member

Flarna commented Sep 21, 2022

Which version of @opentelemetry/instrumentation-mongodb do you use? Latest is 0.32.0.

@dyladan dyladan added the priority:p1 Bugs which cause problems in end-user applications such as crashes, data inconsistencies label Sep 21, 2022
@dyladan
Copy link
Member

dyladan commented Sep 21, 2022

Added p1 label because this causes a compilation failure in an end user app. @Flarna if you're looking into this can you assign yourself? If not let me know and I'll find someone to look at it.

@Flarna
Copy link
Member

Flarna commented Sep 21, 2022

will take a look. Looks like our typescript setup include lib dom everywhere therefore we didn't notice that Document is missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority:p1 Bugs which cause problems in end-user applications such as crashes, data inconsistencies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants