opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

RFC: Allow concurrent testing without excessive warning noise

Open cdaringe opened this issue 7 months ago • 3 comments

OTELJS uses @opentelemetry/api/build/src/internal/global-utils.js, which provides value for managing the singleton nature of tracing resources.

Use of globals makes sense in prod at runtime, but during tests, if you bring servers up and down, your console gets littered with warnings/errors, which is highly undesirable:

    console.warn
      Current logger will overwrite one already registered from Error: 
          at DiagAPI.setLogger (/Users/c0d01a5/src/ce-sample-service-2/node_modules/.pnpm/@[email protected]/node_modules/@opentelemetry/api/src/api/diag.ts:97:23)
          at setupOrchestraTracerProvider (/Users/c0d01a5/src/ce-sample-service-2/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@org/orchestra-tracing/src/setup/setup-tracing-provider.ts:79:10)
          at setupPlugIn (/Users/c0d01a5/src/ce-sample-service-2/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@org/orchestra-tracing/src/plug-ins/fastify3-plug-in.ts:239:54)
          at Plugin.Object.<anonymous>.Plugin.exec (/Users/c0d01a5/src/ce-sample-service-2/node_modules/.pnpm/[email protected]/node_modules/avvio/plugin.js:130:19)
          at Boot.loadPlugin (/Users/c0d01a5/src/ce-sample-service-2/node_modules/.pnpm/[email protected]/node_modules/avvio/plugin.js:272:10)
          at processTicksAndRejections (node:internal/process/task_queues:82:21)

      at DiagConsoleLogger.warn (node_modules/.pnpm/@[email protected]/node_modules/@opentelemetry/api/src/diag/consoleLogger.ts:49:28)
      at DiagAPI.setLogger (node_modules/.pnpm/@[email protected]/node_modules/@opentelemetry/api/src/api/diag.ts:99:19)
      at setupOrchestraTracerProvider (node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@org/orchestra-tracing/src/setup/setup-tracing-provider.ts:79:10)
      at setupPlugIn (node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@org/orchestra-tracing/src/plug-ins/fastify3-plug-in.ts:239:54)
      at Plugin.Object.<anonymous>.Plugin.exec (node_modules/.pnpm/[email protected]/node_modules/avvio/plugin.js:130:19)
      at Boot.loadPlugin (node_modules/.pnpm/[email protected]/node_modules/avvio/plugin.js:272:10)

    console.error
      Error: @opentelemetry/api: Attempted duplicate registration of API: trace
          at registerGlobal (/Users/c0d01a5/src/ce-sample-service-2/node_modules/.pnpm/@[email protected]/node_modules/@opentelemetry/api/src/internal/global-utils.ts:47:17)
          at TraceAPI.setGlobalTracerProvider (/Users/c0d01a5/src/ce-sample-service-2/node_modules/.pnpm/@[email protected]/node_modules/@opentelemetry/api/src/api/trace.ts:67:35)
          at BasicTracerProvider.register (/Users/c0d01a5/src/ce-sample-service-2/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@opentelemetry/sdk-trace-base/src/BasicTracerProvider.ts:153:11)
          at setupPlugIn (/Users/c0d01a5/src/ce-sample-service-2/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@org/orchestra-tracing/src/plug-ins/fastify3-plug-in.ts:241:18)
          at Plugin.Object.<anonymous>.Plugin.exec (/Users/c0d01a5/src/ce-sample-service-2/node_modules/.pnpm/[email protected]/node_modules/avvio/plugin.js:130:19)
          at Boot.loadPlugin (/Users/c0d01a5/src/ce-sample-service-2/node_modules/.pnpm/[email protected]/node_modules/avvio/plugin.js:272:10)
          at processTicksAndRejections (node:internal/process/task_queues:82:21)

This repeats for N-1 test cases for which your code registers OTEL entities.

In order to silence all of this in tests, I am forced to meddle with OT globals. I'm not going to share the code snippet, as I don't want to encourage the behavior for other readers.

Solution-wise, it would be preferable to:

  • userland to not meddle with OT globals in order to keep a good signal:noise ratio in test output
  • userland to not mock OT entities in order to keep a good signal:noise ratio in test output

Ideas:

  • check for NODE_ENV=test and disable the logging ** this has the hazard of not reporting true positive error conditions
  • check for NODE_ENV=production to enable the logging ** this has the benefit of giving you warnings where you need them most, albeit late in the development process
  • pick a stronger stance: crash or be silent
  • provide a testing recipe to the associated loggers and/or global settings to silence these warnings
  • provide a global log level override for these global utils
  • ...your ideas here :)
  • [x] This only affects the JavaScript OpenTelemetry library
  • [ ] This may affect other libraries, but I would like to get opinions here first

cdaringe avatar Nov 30 '23 21:11 cdaringe

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] avatar Feb 26 '24 06:02 github-actions[bot]

Not stale

cdaringe avatar Feb 26 '24 16:02 cdaringe

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] avatar May 06 '24 06:05 github-actions[bot]