prisma / docs

📚 Prisma Documentation
https://www.prisma.io/docs
Apache License 2.0
968 stars 749 forks source link

opentelemetry-tracing - document how to use it with NodeSDK #5617

Open mjarosie opened 5 months ago

mjarosie commented 5 months ago

Problem

As far as I understand there are two ways of configuring OpenTelemetry in JavaScript (source):

Most beginners will be more familiar with @opentelemetry/sdk-node as OpenTelemetry's JavaScript getting started guide uses it.

Currently Prisma documentation on enabling OpenTelemetry tracing describes only how to make use of the first approach. Showing how to make it work with new NodeSDK({ /* ... */ }) would make it easier to enable tracing in Prisma.

Suggested solution

Expand the documentation page to also mention how to use it with @opentelemetry/sdk-node.

Additional context

I got really confused when trying to enable tracing in Prisma following the documentation mentioned above after having configured basic instrumentation based on OpenTelemetry's JavaScript getting started guide (also mentioned above).

Jolg42 commented 5 months ago

@mjarosie (I did not try this code, but that should be the idea for Honeycomb here)

import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto'
import { NodeSDK } from '@opentelemetry/sdk-node'
import { PrismaInstrumentation } from '@prisma/instrumentation'

const traceExporter = new OTLPTraceExporter({
  url: `https://api.honeycomb.io/v1/traces`,
  headers: {
    'x-honeycomb-team': "HONEYCOMB_API_KEY",
  },
})

const sdk = new NodeSDK({
  serviceName: "my-service-name",
  traceExporter,
  instrumentations: [
    new PrismaInstrumentation(),
  ],
})

sdk.start()

process.on(`SIGTERM`, () => {
  sdk.shutdown().finally(() => process.exit(0))
})
mjarosie commented 5 months ago

Yes, got it working with a very similar setup 👍 Something similar should probably end up in the documentation (either with traceExporter as you've shown or also with spanProcessor, but not sure if that wouldn't complicate the example too much).