ImqueueInstrumentation class
OpenTelemetry instrumentation for @imqueue/rpc.
@imqueue/rpc exposes its default client/service options as mutable singletons and calls their beforeCall/afterCall/wrapCall hooks around every RPC. Rather than intercepting module loading (which, for an ESM package, needs import-in-the-middle and rewrites the whole module graph), this patches those singletons directly on enable() — robust and free of ESM-hook fragility.
- Client calls use
beforeCall/afterCall: a CLIENT span is started as a child of the active context and its trace context is injected into the request metadata for propagation, then ended on response. - Service calls usewrapCall(the around-hook): the SERVER span is started from the propagated parent and the handler is run **inside** that span's context (context.with), so any spans it or its downstream calls create nest correctly.
Two consequences of patching singletons rather than intercepting imports. Clients and services constructed BEFORE enable() copy the defaults at construction time and are not traced — so register the instrumentation before building any of them, which registerInstrumentations at start-up does naturally. And if the @imqueue/rpc this resolves is a different copy from the one the application imported (duplicate installs at different tree depths), the patch lands on the wrong singletons and no spans appear.
Signature:
export declare class ImqueueInstrumentation extends InstrumentationBase
Extends: InstrumentationBase
Example
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { ImqueueInstrumentation } from '@imqueue/opentelemetry';
new NodeTracerProvider().register();
registerInstrumentations({
instrumentations: [new ImqueueInstrumentation()],
});
Constructors
|
Constructor |
Modifiers |
Description |
|---|---|---|
|
Constructs a new instance of the |
Methods
|
Method |
Modifiers |
Description |
|---|---|---|
|
Stops tracing by removing the hooks again. Clients and services already constructed keep the hooks they copied at construction time, so spans from them may continue after this returns. | ||
|
Starts tracing: resolves the live | ||
|
|
No module-load hook: we patch | |
|
Attaches the tracing hooks to a module's default client/service options. | ||
|
Removes the tracing hooks previously attached by ImqueueInstrumentation.patch(). |
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.