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

Error when opentelemetry is enabled #3854

Open
christophflick-toast opened this issue Dec 8, 2023 · 3 comments
Open

Error when opentelemetry is enabled #3854

christophflick-toast opened this issue Dec 8, 2023 · 3 comments
Labels
bug Something isn't working open-telemetry

Comments

@christophflick-toast
Copy link
Contributor

Hi!
We're getting the following error after configuring opentelemetry support in dd-trace-js.

"TypeError: Cannot read properties of undefined (reading 'sample')",
"    at DatadogSpan._addTags (/usr/src/app/node_modules/dd-trace/packages/dd-trace/src/opentracing/span.js:238:27)",
"    at DatadogSpan.addTags (/usr/src/app/node_modules/dd-trace/packages/dd-trace/src/opentracing/span.js:138:10)",
"    at Span.setAttributes (/usr/src/app/node_modules/dd-trace/packages/dd-trace/src/opentelemetry/span.js:92:18)",
"    at Tracer.startSpan (/usr/src/app/node_modules/dd-trace/packages/dd-trace/src/opentelemetry/tracer.js:96:10)",
"    at Tracer.startActiveSpan (/usr/src/app/node_modules/dd-trace/packages/dd-trace/src/opentelemetry/tracer.js:113:23)",
"    at ApolloGateway.executor [as gatewayExecutor] (/usr/src/app/node_modules/@apollo/gateway/dist/index.js:53:43)",
"    at execute (/usr/src/app/node_modules/@apollo/server/dist/cjs/requestPipeline.js:225:44)",
"    at processGraphQLRequest (/usr/src/app/node_modules/@apollo/server/dist/cjs/requestPipeline.js:158:38)",
"    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
"    at async internalExecuteOperation (/usr/src/app/node_modules/@apollo/server/dist/cjs/ApolloServer.js:634:16)"

The project is basically a apollo server / gateway.

Any clue where to look on how to resolve this in case that's not a bug?

Expected behaviour
Shouldn't crash I guess.

Actual behaviour
Is crashing

Steps to reproduce
That's our tracer initialization code:

const tracer = require('dd-trace')
const { TracerProvider } = tracer
tracer.init({
  plugins: true,
  runtimeMetrics: true
})

tracer.use('express')

tracer.use('graphql', {
  signature: false,
  source: true
})

const provider = new TracerProvider()
provider.register()

module.exports = tracer

When removing the

const provider = new TracerProvider()
provider.register()

it works just fine - but then we don't get the opentelemetry spans emitted by the apollo gateway.

Environment

  • Operation system: Linux
  • Node.js version: 18
  • Tracer version: 4.17.0
  • Agent version: unknown
  • Relevant library versions:
"@apollo/gateway": "^2.5.6",
"@apollo/server": "^4.9.5",
@christophflick-toast christophflick-toast added the bug Something isn't working label Dec 8, 2023
@theJC
Copy link
Contributor

theJC commented Dec 12, 2023

FYI, at my company we are using 4.17.0 on Node 18, gateway 2.6.1 and server@4.4.0 without issue
the biggest difference I can see between our setup is we use koa and not express, and we disable the ddtrace graphql plugin altogether.

@ViktorCollin
Copy link

ViktorCollin commented Dec 15, 2023

I have a very similar issue but with Prisma and some manual span creation instead of Apollo. For me the issue only occurs when i develop locally so I think that it may be related to the DD_TRACE_ENABLED environment variable:
DD_TRACE_ENABLED=false node index.js - fails
DD_TRACE_ENABLED=true node index.js - no issue

dd-trace: 4.20.0
Node.js: v18.18.1

@christophflick-toast
Copy link
Contributor Author

christophflick-toast commented Dec 15, 2023

Yeah, I also just tracked it down to the DD_TRACE_ENABLED flag.
We "solved it" now by wrapping the opentelemetry code in a condition like that:

if (process.env.DD_TRACE_ENABLED === 'true') {
  const provider = new TracerProvider()
  provider.register()
}

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

No branches or pull requests

4 participants