# traced() function · @imqueue/datadog

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

Builds a method decorator that wraps each call to the decorated method in its own span, finishing it when the method returns — or when the promise it returned settles.

**Signature:**

```typescript
export declare function traced(options?: Partial<TracedOptions>): (target: any, methodName: string | symbol, descriptor: TypedPropertyDescriptor<(...args: any[]) => any>) => void;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| options | Partial<[TracedOptions](https://imqueue.org/api/datadog/latest/datadog.tracedoptions/)> | _(Optional)_ span kind and extra tags. `kind` defaults to [TraceKind.SERVER](https://imqueue.org/api/datadog/latest/datadog.tracekind/); tags given here are applied last and override the automatic ones. |


**Returns:**

(target: any, methodName: string \| symbol, descriptor: TypedPropertyDescriptor<(...args: any\[\]) => any>) => void

a method decorator to apply to the methods you want traced

## Remarks

Use this for work worth seeing in a trace that is not itself an RPC, so the automatic `imq.request`/`imq.response` spans do not already cover it: a cache rebuild, a report query, a third-party call.

Async methods are handled: a returned thenable keeps the span open until it settles, so the span duration reflects the real work rather than the time to return a promise. A rejection, or a synchronous throw, tags the span with the error, finishes it, and re-throws — the decorator never swallows a failure.

Every span it creates is named `method.call`; the decorated method is identified by the `resource.name` tag (`ClassName.methodName`), with the host package name reported separately as `package.name`. The span attaches to the active span when there is one, so a traced method called while handling an RPC nests inside that call's span.

## Example


```typescript
import { traced, TraceKind } from '@imqueue/datadog';

class Reports {
    @traced()
    public async rebuild(day: string): Promise<void> {
        // span stays open until this promise settles
    }

    @traced({ kind: TraceKind.CLIENT, tags: { 'peer.service': 'billing' } })
    public async fetchInvoices(userId: string): Promise<Invoice[]> {
        return this.http.get(`/invoices/${ userId }`);
    }
}
```

