# ImqueueInstrumentation class · @imqueue/opentelemetry

Source: https://imqueue.org/api/opentelemetry/latest/opentelemetry.imqueueinstrumentation/
Published: 2026-08-01
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/opentelemetry 4.0.0 — generated reference, not hand-written

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 use `wrapCall` (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:**

```typescript
export declare class ImqueueInstrumentation extends InstrumentationBase 
```
**Extends:** InstrumentationBase

## Example


```typescript
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 |
| --- | --- | --- |
| [(constructor)(config)](https://imqueue.org/api/opentelemetry/latest/opentelemetry.imqueueinstrumentation._constructor_/) |  | Constructs a new instance of the `ImqueueInstrumentation` class |


## Methods


| Method | Modifiers | Description |
| --- | --- | --- |
| [disable()](https://imqueue.org/api/opentelemetry/latest/opentelemetry.imqueueinstrumentation.disable/) |  | 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. |
| [enable()](https://imqueue.org/api/opentelemetry/latest/opentelemetry.imqueueinstrumentation.enable/) |  | Starts tracing: resolves the live `@imqueue/rpc` and attaches the hooks to its default options. |
| [init()](https://imqueue.org/api/opentelemetry/latest/opentelemetry.imqueueinstrumentation.init/) | `protected` | No module-load hook: we patch `@imqueue/rpc`'s mutable default options directly (see the class docs), so there is nothing to intercept at import. |
| [patch(rpc)](https://imqueue.org/api/opentelemetry/latest/opentelemetry.imqueueinstrumentation.patch/) |  | Attaches the tracing hooks to a module's default client/service options. |
| [unpatch(rpc)](https://imqueue.org/api/opentelemetry/latest/opentelemetry.imqueueinstrumentation.unpatch/) |  | Removes the tracing hooks previously attached by [ImqueueInstrumentation.patch()](https://imqueue.org/api/opentelemetry/latest/opentelemetry.imqueueinstrumentation.patch/). |

