Hello @channel. Can someone please help with the ...
# support
j
Hello @channel. Can someone please help with the automatic instrumentation for Express Nodejs app. I followed the guidelines here : Express OpenTelemetry Instrumentation | SigNoz I am still having this error:
Copy code
const resource = new Resource({
                 ^

TypeError: Resource is not a constructor
    at Object.<anonymous>
I have also tried the pinned Github repo example and it still did not work. Can someone please help.
h
It looks like you're halfway down the page where the Typescript example shows:
Copy code
resource: new Resource({
    [SemanticResourceAttributes.SERVICE_NAME]: '<service_name>',
  }),
have you tried the sample near the top of the page?
Copy code
resource:  resourceFromAttributes({
    // highlight-next-line
    [SemanticResourceAttributes.SERVICE_NAME]: '<service_name>'
  })
because in TypeScript that's just an interface that can't be directly instantiated, so I think one of the examples is stale and wasn't updated when this OTel refactor happened. I didn't check the semvers of the packages, but the examples might be valid if they're version locked and you happened to install latest.
j
Can you please give me full code example. I am not using Typescript. Just ES6 JavaScript. And yes I required the tracing.js in my app's entry point , hence the errors. Can you provide the list of packages with their locked versions that works. Its been frustrating to net get going with instrumentation. Thanks
h
Sorry, I'm using the OTel operator so don't have my own tracing.js. I'd recommend this example from the page:
Copy code
import * as opentelemetry from '@opentelemetry/sdk-node';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
import { resourceFromAttributes } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';

const sdk = new opentelemetry.NodeSDK({
  traceExporter: new OTLPTraceExporter({
    // optional - default url is <http://localhost:4318/v1/traces>
    url: '<https://ingest>.<region>.signoz.cloud:443/v1/traces', // url is optional and can be omitted 
      headers: {
        "signoz-access-token": "<your-ingestion-key>"
      } // an optional object containing custom headers to be sent with each request
  }),
  instrumentations: [getNodeAutoInstrumentations()],
  resource:  resourceFromAttributes({
    // highlight-next-line
    [SemanticResourceAttributes.SERVICE_NAME]: '<service_name>'
  })
});
sdk.start();
That example has these specific versions:
Copy code
npm install --save @opentelemetry/api@^1.6.0                                                                       
npm install --save @opentelemetry/sdk-node@^0.45.0
npm install --save @opentelemetry/auto-instrumentations-node@^0.39.4
npm install --save @opentelemetry/exporter-trace-otlp-http@^0.45.0
were those what you installed?
j
Yes they were aparently some slight version mismatch due to these 2 packages:
Copy code
import { resourceFromAttributes } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
Which from your list of versioned packages were not listed why please?
Does that mean we are not meant to install them or can you list the packages and their working version?
h
Those two are transitive dependencies of
sdk-node
so that's likely why they weren't explicitly listed. https://www.npmjs.com/package/@opentelemetry/sdk-node?activeTab=dependencies
It looks like the semver filter used in those install commands is too loose:
Copy code
npm install --save @opentelemetry/api@^1.6.0
ends up installing
Copy code
"@opentelemetry/api": "^1.9.0"
which are a year apart. You can try locking down to the exact/patch versions by switching
^
for
~
, e.g.:
Copy code
npm install --save @opentelemetry/api@~1.6.0                                                                       
npm install --save @opentelemetry/sdk-node@~0.45.0
npm install --save @opentelemetry/auto-instrumentations-node@~0.39.4
npm install --save @opentelemetry/exporter-trace-otlp-http@~0.45.0
that'll still leave you using 2yr old libraries, but might at least unblock you for now
j
Ok thanks will work with this