# `InstrumentationConfig\<T\>`

```ts
type InstrumentationConfig<T> = {
  hooks?: {
    onError?: (error: unknown, span: Span) => Error | undefined;
    onResult?: (result: ReturnType<T>, span: Span) => void;
  };
  isSuccessful?: (result: ReturnType<T>) => boolean;
  spanConfig?: SpanOptions & {
    getBaseContext?: (...args: Parameters<T>) => Context;
    spanName?: string;
  };
};
```

Defined in: [types.ts:99](https://github.com/adobe/aio-lib-telemetry/blob/41c5ec13ca6d2cc9f732e352a472d47c3a0d240c/source/types.ts#L99)

The configuration for instrumentation.

## Since

0.1.0

## Extended by

- [`EntrypointInstrumentationConfig`](../interfaces/EntrypointInstrumentationConfig.md)

## Type Parameters

| Type Parameter              |
| --------------------------- |
| `T` _extends_ `AnyFunction` |

## Properties

### hooks?

```ts
optional hooks?: {
  onError?: (error: unknown, span: Span) => Error | undefined;
  onResult?: (result: ReturnType<T>, span: Span) => void;
};
```

Defined in: [types.ts:138](https://github.com/adobe/aio-lib-telemetry/blob/41c5ec13ca6d2cc9f732e352a472d47c3a0d240c/source/types.ts#L138)

Hooks that can be used to act on a span depending on the result of the function.

#### onError?

```ts
optional onError?: (error: unknown, span: Span) => Error | undefined;
```

A function that will be called when the instrumented function fails.
You can use it to do something with the Span.

##### Parameters

| Parameter | Type      | Description                                      |
| --------- | --------- | ------------------------------------------------ |
| `error`   | `unknown` | The error produced by the instrumented function. |
| `span`    | `Span`    | The span of the instrumented function.           |

##### Returns

`Error` \| `undefined`

##### Since

0.1.0

#### onResult?

```ts
optional onResult?: (result: ReturnType<T>, span: Span) => void;
```

A function that will be called with the result of the instrumented function (if any, and no error was thrown).
You can use it to do something with the Span.

##### Parameters

| Parameter | Type                | Description                              |
| --------- | ------------------- | ---------------------------------------- |
| `result`  | `ReturnType`\<`T`\> | The result of the instrumented function. |
| `span`    | `Span`              | The span of the instrumented function.   |

##### Returns

`void`

##### Since

0.1.0

---

### isSuccessful?

```ts
optional isSuccessful?: (result: ReturnType<T>) => boolean;
```

Defined in: [types.ts:135](https://github.com/adobe/aio-lib-telemetry/blob/41c5ec13ca6d2cc9f732e352a472d47c3a0d240c/source/types.ts#L135)

A function that will be called to determine if the instrumented function was successful.
By default, the function is considered successful if it doesn't throw an error.

#### Parameters

| Parameter | Type                | Description                              |
| --------- | ------------------- | ---------------------------------------- |
| `result`  | `ReturnType`\<`T`\> | The result of the instrumented function. |

#### Returns

`boolean`

Whether the instrumented function was successful.

#### Since

0.1.0

---

### spanConfig?

```ts
optional spanConfig?: SpanOptions & {
  getBaseContext?: (...args: Parameters<T>) => Context;
  spanName?: string;
};
```

Defined in: [types.ts:106](https://github.com/adobe/aio-lib-telemetry/blob/41c5ec13ca6d2cc9f732e352a472d47c3a0d240c/source/types.ts#L106)

Configuration options related to the span started by the instrumented function.
See also the [SpanOptions](https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_api._opentelemetry_api.SpanOptions.html) interface.

#### Type Declaration

##### getBaseContext?

```ts
optional getBaseContext?: (...args: Parameters<T>) => Context;
```

The base context to use for the started span.

###### Parameters

| Parameter | Type                | Description                                 |
| --------- | ------------------- | ------------------------------------------- |
| ...`args` | `Parameters`\<`T`\> | The arguments of the instrumented function. |

###### Returns

`Context`

The base context to use for the started span.

###### Since

0.1.0

##### spanName?

```ts
optional spanName?: string;
```

The name of the span. Defaults to the name of given function.
You must use a named function or a provide a name here.

###### Since

0.1.0

#### Since

0.1.0
