autotelic / fastify-opentelemetry

A Fastify plugin that utilizes the OpenTelemetry API to provide request tracing.
MIT License
72 stars 12 forks source link

noop API when tracing is disabled #67

Closed 10xLaCroixDrinker closed 2 months ago

10xLaCroixDrinker commented 6 months ago

In my application, I enable and disable tracing through an environment variable. When tracing is disabled, the request.openTelemetry() API is still required as to not throw any errors when attempting to create spans. I've added a plugin that is registered when tracing is disabled that adds the API as noops to handle this. While I don't see significant difference in CPU and memory usage using the actual plugin with tracing disabled, I did find a measurable difference in latency.

Is this something you'd be interested in adding to your plugin?

HW13 commented 6 months ago

Hi @10xLaCroixDrinker, this plugin should already be compatible with OpenTelemetry's built-in noop defaults. If tracing is disabled at the SDK level or never configured to begin with, the request.openTelemetry decorator should still function the same. When the noop plugin is removed, what error is being thrown?

10xLaCroixDrinker commented 6 months ago

Its not that there is an error, but I see a difference in latency.

I'm not explicitly disabling tracing through the SDK though. I'm just not starting the application with --require=tracer.js. Am I missing something more?

HW13 commented 3 months ago

Apologies for the delay @10xLaCroixDrinker. Nope you're not missing something - not loading the tracer file would have the same effect. Some latency is to be expected, even if Otel's noops are being used the plugin is still doing a bit of work starting and stoping spans. If there's anything that can be done to reduce latency while the plugin is active we would really appreciate a PR. But including an additional plugin for noops adds overhead that we'd rather not have to maintain.