prisma: `parentTracer.getSpanLimits is not a function`

Bug description

Upgrading to Prisma v5.4.1 caused the following error to appear

TypeError: parentTracer.getSpanLimits is not a function
    at new Span (/var/task/node_modules/@prisma/instrumentation/node_modules/@opentelemetry/sdk-trace-base/build/src/Span.js:59:41)
    at /var/task/node_modules/@prisma/instrumentation/dist/ActiveTracingHelper.js:59:20
    at Array.forEach (<anonymous>)
    at ActiveTracingHelper.createEngineSpan (/var/task/node_modules/@prisma/instrumentation/dist/ActiveTracingHelper.js:44:27)
    at Wi.createEngineSpan (/var/task/node_modules/@prisma/client/runtime/library.js:123:1687)
    at dr.propagateResponseExtensions (/var/task/node_modules/@prisma/client/runtime/library.js:112:4691)
    at Object.callback (/var/task/node_modules/@prisma/client/runtime/library.js:112:6604)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at dr.withRetry (/var/task/node_modules/@prisma/client/runtime/library.js:112:8713)
    at Object.singleLoader (/var/task/node_modules/@prisma/client/runtime/library.js:123:5333) {
  clientVersion: '5.4.1'
}

Before the upgrade, everything was running smoothly and the only change was upgrading Prisma

How to reproduce

  • Upgrade to Prisma v5.4.1 (you must have open telemetry configured too

Expected behavior

No response

Prisma information

"@prisma/client": "^5.4.1",
"@prisma/instrumentation": "^5.4.1",
"prisma": "^5.4.1"

Environment & setup

  • OS: macOs
  • Database: PostgreSQL
  • Node.js version: 18

Prisma Version

8.11.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 10
  • Comments: 18 (6 by maintainers)

Most upvoted comments

Is there any update on this? I am running into the same issue.

@aqrln I think we were missing @opentelemetry/api from our deps - adding that fixed the issue, thank you!

That dependency is missing in the documentation. Would be great if you could add that.

I just now faced the same problem in one of my local test projects, updating all OpenTelemetry packages fixed this.

Seems like one of dependency updates in @prisma/instrumentation caused this. I think we should make @opentelemetry/api and other peerDependencies and not dependencies to prevent issues like this.

IMO this shouldn’t be relegated to documentation but should be fixed so that the problem does not occur in the first place (or so that the package manager tells you what to install if anything needs to be installed manually, and detects conflicts). I haven’t looked into it, but it sounds like we are bundling OpenTelemetry dependencies while we should probably be using peer dependencies instead.

There’s another issue that I recently saw (https://github.com/prisma/prisma/issues/21473), let’s use that as the main one.

As for https://www.prisma.io/docs/orm/prisma-client/observability-and-logging/opentelemetry-tracing#step-3-install-opentelemetry-packages, it is possible that we should add @opentelemetry/api there, but optimally it shouldn’t be the case since it’s not explicitly used or imported in the example. We should investigate and figure out.

@aqrln actually which version of @opentelemetry/api did you install to fix the issue?

As far as I see, that issue mentions this error specifically in the context of Datadog’s dd-trace library, are you using it as well by any chance?

Actually we don’t, we use Jaeger (OTLPTraceExporter)

Our code is something like

import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { SimpleSpanProcessor, BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { AsyncHooksContextManager } from "@opentelemetry/context-async-hooks";
import { PrismaInstrumentation } from "@prisma/instrumentation";
import { TraceIdRatioBasedSampler } from "@opentelemetry/sdk-trace-base";
import { Resource } from "@opentelemetry/resources";
import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express";
import { HttpInstrumentation } from "@opentelemetry/instrumentation-http";
import * as api from "@opentelemetry/api";

export default function setup() {
  const connectorUrl = process.env.JAEGER_CONNECTOR_URL;
  if (!connectorUrl) {
    return;
  }

  // a context manager is required to propagate the context
  const contextManager = new AsyncHooksContextManager().enable();
  // it's for node.js for span nesting and ctx propagation
  api.context.setGlobalContextManager(contextManager);

  // Configure the trace provider
  const provider = new NodeTracerProvider({
    sampler: new TraceIdRatioBasedSampler(0.3),
    resource: new Resource({
      [SemanticResourceAttributes.SERVICE_NAME]: "xxxxxxxx"
    })
  });

  // exporter that natively works with jaeger without extras
  const exporter = new OTLPTraceExporter({
    url: connectorUrl
  });

  // Configure how spans are processed and exported. In this case we're sending spans
  // as we receive them to an OTLP-compatible collector (e.g. Jaeger).
  if (process.env.NODE_ENV === "production") {
    provider.addSpanProcessor(new BatchSpanProcessor(exporter));
  } else {
    provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
  }

  provider.register();
  registerInstrumentations({
    tracerProvider: provider,
    instrumentations: [
      new HttpInstrumentation(),
      new ExpressInstrumentation(),
      new PrismaInstrumentation()
    ]
  });
}