# @arizeai/openinference-core

**JavaScript · Core**

OpenInference Core provides utilities shared by all OpenInference SDK packages.

- **Version**: 2.8.4

[npm](https://www.npmjs.com/package/@arizeai/openinference-core) · [README](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/README.md) · [Source](https://github.com/Arize-ai/openinference/tree/main/js/packages/openinference-core)

## Install

```sh
npm install @arizeai/openinference-core
```

## `@arizeai/openinference-core`

### `toInputType`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/attributeHelpers.ts#L50)

```typescript
function toInputType(...args: unknown[]): SpanInput | undefined
```

Converts function arguments into a standardized SpanInput format for tracing.

This function processes variable arguments and determines the appropriate MIME type based on the input. Single string arguments are preserved as text, while other types are JSON stringified.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `...args` | `unknown[]` | The function arguments to process into span input format |

**Returns**

| Type | Description |
| - | - |
| `SpanInput \| undefined` | A SpanInput object with value and mimeType, or undefined if no args provided |

**Examples**

```typescript
// String input
toInputType("hello") // { value: "hello", mimeType: MimeType.TEXT }

// Object input
toInputType({ key: "value" }) // { value: '{"key":"value"}', mimeType: MimeType.JSON }

// Multiple arguments
toInputType("arg1", 42) // { value: '["arg1",42]', mimeType: MimeType.JSON }
```

### `toOutputType`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/attributeHelpers.ts#L102)

```typescript
function toOutputType(result: unknown): SpanOutput | undefined
```

Converts function output into a standardized SpanOutput format for tracing.

This function processes the return value of a traced function and determines the appropriate MIME type. String outputs are preserved as text, while other types are JSON stringified.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `result` | `unknown` | The function’s return value to process into span output format |

**Returns**

| Type | Description |
| - | - |
| `SpanOutput \| undefined` | A SpanOutput object with value and mimeType, or undefined if result is null/undefined |

**Examples**

```typescript
// String output
toOutputType("success") // { value: "success", mimeType: MimeType.TEXT }

// Object output
toOutputType({ status: "ok" }) // { value: '{"status":"ok"}', mimeType: MimeType.JSON }

// Null/undefined output
toOutputType(null) // undefined
```

### `defaultProcessInput`

_constant_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/attributeHelpers.ts#L133)

```typescript
const defaultProcessInput: InputToAttributesFn
```

Default input processing function that converts function arguments to OpenTelemetry attributes.

This is a convenience function that combines `toInputType` and `getInputAttributes` to provide a complete input processing pipeline for tracing decorators.

**Returns**

| Description |
| - |
| OpenTelemetry attributes representing the input |

**Examples**

```typescript
const attrs = defaultProcessInput("hello", { key: "value" });
// Returns: { [INPUT_VALUE]: '["hello",{"key":"value"}]', [INPUT_MIME_TYPE]: MimeType.JSON }
```

### `defaultProcessOutput`

_constant_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/attributeHelpers.ts#L151)

```typescript
const defaultProcessOutput: OutputToAttributesFn
```

Default output processing function that converts function results to OpenTelemetry attributes.

This is a convenience function that combines `toOutputType` and `getOutputAttributes` to provide a complete output processing pipeline for tracing decorators.

**Returns**

| Description |
| - |
| OpenTelemetry attributes representing the output |

**Examples**

```typescript
const attrs = defaultProcessOutput({ status: "success" });
// Returns: { [OUTPUT_VALUE]: '{"status":"success"}', [OUTPUT_MIME_TYPE]: MimeType.JSON }
```

### `getOutputAttributes`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/attributeHelpers.ts#L177)

```typescript
function getOutputAttributes(
  output: string | SpanOutput | null | undefined,
): Attributes
```

Converts a SpanOutput object or string into OpenTelemetry attributes.

This function transforms span output data into the standardized attribute format used by OpenTelemetry, mapping values to the appropriate semantic convention keys.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `output` | `string \| SpanOutput \| null \| undefined` | The SpanOutput object, string, or undefined to convert |

**Returns**

| Type | Description |
| - | - |
| `Attributes` | OpenTelemetry attributes with OUTPUT_VALUE and OUTPUT_MIME_TYPE keys |

**Examples**

```typescript
// SpanOutput object
getOutputAttributes({ value: "result", mimeType: MimeType.TEXT })
// Returns: { [OUTPUT_VALUE]: "result", [OUTPUT_MIME_TYPE]: MimeType.TEXT }

// String input
getOutputAttributes("simple string")
// Returns: { [OUTPUT_VALUE]: "simple string", [OUTPUT_MIME_TYPE]: MimeType.TEXT }

// Undefined input
getOutputAttributes(undefined) // Returns: {}
```

### `getInputAttributes`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/attributeHelpers.ts#L216)

```typescript
function getInputAttributes(input: string | SpanInput | undefined): Attributes
```

Converts a SpanInput object or string into OpenTelemetry attributes.

This function transforms span input data into the standardized attribute format used by OpenTelemetry, mapping values to the appropriate semantic convention keys.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `input` | `string \| SpanInput \| undefined` | The SpanInput object, string, or undefined to convert |

**Returns**

| Type | Description |
| - | - |
| `Attributes` | OpenTelemetry attributes with INPUT_VALUE and INPUT_MIME_TYPE keys |

**Examples**

```typescript
// SpanInput object
getOutputAttributes({ value: "query", mimeType: MimeType.TEXT })
// Returns: { [INPUT_VALUE]: "query", [INPUT_MIME_TYPE]: MimeType.TEXT }

// String input
getOutputAttributes("simple string")
// Returns: { [INPUT_VALUE]: "simple string", [INPUT_MIME_TYPE]: MimeType.TEXT }

// Undefined input
getOutputAttributes(undefined) // Returns: {}
```

### `getEmbeddingAttributes`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/attributeHelpers.ts#L254)

```typescript
function getEmbeddingAttributes(
  options: { modelName?: string; embeddings?: Embedding[] },
): Attributes
```

Generates attributes for embedding operations.

Creates OpenTelemetry attributes for embedding-related data including model name and embedding vectors with associated text.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `options` | `{ modelName?: string; embeddings?: Embedding[] }` | Configuration object for embedding attributes |
| `options.modelName?` | `string` | The name of the embedding model used |
| `options.embeddings?` | `Embedding[]` | Array of embedding objects containing text and vector data |

**Returns**

| Type | Description |
| - | - |
| `Attributes` | OpenTelemetry attributes for embedding operations |

**Examples**

```typescript
const attrs = getEmbeddingAttributes({
  modelName: "text-embedding-ada-002",
  embeddings: [
    { text: "hello world", vector: [0.1, 0.2, 0.3] },
    { text: "goodbye", vector: [0.4, 0.5, 0.6] }
  ]
});
```

### `getRetrieverAttributes`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/attributeHelpers.ts#L303)

```typescript
function getRetrieverAttributes(options: { documents: Document[] }): Attributes
```

Generates attributes for retriever operations.

Creates OpenTelemetry attributes for document retrieval operations, including document content, IDs, metadata, and scores.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `options` | `{ documents: Document[] }` | Configuration object for retriever attributes |
| `options.documents` | `Document[]` | Array of documents retrieved |

**Returns**

| Type | Description |
| - | - |
| `Attributes` | OpenTelemetry attributes for retriever operations |

**Examples**

```typescript
const attrs = getRetrieverAttributes({
  documents: [
    { content: "Document 1", id: "doc1", score: 0.95 },
    { content: "Document 2", id: "doc2", metadata: { source: "web" } }
  ]
});
```

### `getDocumentAttributes`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/attributeHelpers.ts#L360)

```typescript
function getDocumentAttributes(
  document: Document,
  documentIndex: number,
  keyPrefix: string,
): Attributes
```

Generates attributes for document operations.

Creates OpenTelemetry attributes for individual document processing, including content, ID, metadata, and score information.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `document` | `Document` | The document to generate attributes for |
| `documentIndex` | `number` | The index of the document in a collection |
| `keyPrefix` | `string` | The prefix for attribute keys (e.g., “reranker.input_documents”) |

**Returns**

| Type | Description |
| - | - |
| `Attributes` | OpenTelemetry attributes for the document |

**Examples**

```typescript
const attrs = getDocumentAttributes(
  { content: "Sample document", id: "doc123", score: 0.8 },
  0,
  "reranker.input_documents"
);
```

### `getAnnotationAttributes`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/attributeHelpers.ts#L499)

```typescript
function getAnnotationAttributes(
  options: { annotations: readonly Annotation[]; scope?: AnnotationScope },
): Attributes
```

Generates annotation attributes for a span, trace, or session.

Collection indices are assigned in input order. Metadata objects are JSON-stringified, while metadata strings are preserved as provided.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `options` | `{ annotations: readonly Annotation[]; scope?: AnnotationScope }` | Annotation values and target scope |
| `options.annotations` | `readonly Annotation[]` | Ordered annotations to flatten |
| `options.scope?` | `AnnotationScope` | Target scope; defaults to `span` |

**Returns**

| Type | Description |
| - | - |
| `Attributes` | OpenTelemetry attributes using annotation terminology |

**Examples**

```typescript
getAnnotationAttributes({
  annotations: [{ name: "correctness", score: 0.95 }],
  scope: "trace",
});
```

### `getEvaluationAttributes`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/attributeHelpers.ts#L529)

```typescript
function getEvaluationAttributes(
  options: { evaluations: readonly Annotation[]; scope?: AnnotationScope },
): Attributes
```

Generates annotations using evaluation terminology for a span, trace, or session.

Collection indices are assigned in input order. Metadata objects are JSON-stringified, while metadata strings are preserved as provided.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `options` | `{ evaluations: readonly Annotation[]; scope?: AnnotationScope }` | Annotation values and target scope |
| `options.evaluations` | `readonly Annotation[]` | Ordered annotations to encode using evaluation terminology |
| `options.scope?` | `AnnotationScope` | Target scope; defaults to `span` |

**Returns**

| Type | Description |
| - | - |
| `Attributes` | OpenTelemetry attributes using evaluation terminology |

**Examples**

```typescript
getEvaluationAttributes({
  evaluations: [{ name: "correctness", label: "correct" }],
  scope: "session",
});
```

### `getMetadataAttributes`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/attributeHelpers.ts#L551)

```typescript
function getMetadataAttributes(metadata: Record<string, unknown>): Attributes
```

Generates attributes for metadata information.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `metadata` | `Record<string, unknown>` | The metadata to include in attributes |

**Returns**

| Type | Description |
| - | - |
| `Attributes` | OpenTelemetry attributes containing the metadata |

**Examples**

```typescript
const attrs = getMetadataAttributes({ version: "1.0", env: "prod" });
```

### `getToolAttributes`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/attributeHelpers.ts#L578)

```typescript
function getToolAttributes(
  options: {
    name: string;
    description?: string;
    parameters: Record<string, unknown>;
  },
): Attributes
```

Generates attributes for tool definitions.

Creates OpenTelemetry attributes for tool information including name, description, and parameters schema.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `options` | `{ name: string; description?: string; parameters: Record<string, unknown> }` | Configuration object for tool attributes |
| `options.name` | `string` | The name of the tool |
| `options.description?` | `string` | Optional description of the tool |
| `options.parameters` | `Record<string, unknown>` | Tool parameters as string or object |

**Returns**

| Type | Description |
| - | - |
| `Attributes` | OpenTelemetry attributes for the tool |

**Examples**

```typescript
const attrs = getToolAttributes({
  name: "search_tool",
  description: "Search for information",
  parameters: { query: { type: "string" } }
});
```

### `getLLMAttributes`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/attributeHelpers.ts#L684)

```typescript
function getLLMAttributes(
  options: {
    provider?: string;
    system?: string;
    modelName?: string;
    requestModelName?: string;
    responseModelName?: string;
    invocationParameters?: Record<string, unknown>;
    inputMessages?: Message[];
    outputMessages?: Message[];
    tokenCount?: TokenCount;
    tools?: Tool[];
  },
): Attributes
```

Generates attributes for LLM operations.

Creates comprehensive OpenTelemetry attributes for LLM interactions including provider, model, messages, token counts, and tools.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `options` | `{ provider?: string; system?: string; modelName?: string; requestModelName?: string; responseModelName?: string; invocationParameters?: Record<string, unknown>; inputMessages?: Message[]; outputMessages?: Message[]; tokenCount?: TokenCount; tools?: Tool[] }` | Configuration object for LLM attributes |
| `options.provider?` | `string` | The LLM provider (e.g., “openai”, “anthropic”) |
| `options.system?` | `string` | The LLM system type |
| `options.modelName?` | `string` | The name of the LLM model |
| `options.requestModelName?` | `string` | The model requested by the caller, as sent in the request. When modelName is omitted, llm.model_name is mirrored from responseModelName ?? requestModelName |
| `options.responseModelName?` | `string` | The model that actually generated the response, as reported by the provider |
| `options.invocationParameters?` | `Record<string, unknown>` | Parameters used for the LLM invocation |
| `options.inputMessages?` | `Message[]` | Input messages sent to the LLM |
| `options.outputMessages?` | `Message[]` | Output messages received from the LLM |
| `options.tokenCount?` | `TokenCount` | Token usage information |
| `options.tools?` | `Tool[]` | Tools available to the LLM |

**Returns**

| Type | Description |
| - | - |
| `Attributes` | OpenTelemetry attributes for LLM operations |

**Examples**

```typescript
const attrs = getLLMAttributes({
  provider: "openai",
  modelName: "gpt-4",
  inputMessages: [{ role: "user", content: "Hello" }],
  outputMessages: [{ role: "assistant", content: "Hi there!" }],
  tokenCount: { prompt: 10, completion: 5, total: 15 }
});
```

### `getDecisionAttributes`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/attributeHelpers.ts#L983)

```typescript
function getDecisionAttributes(
  options: {
    provider?: string;
    system?: string;
    modelName?: string;
    requestModelName?: string;
    responseModelName?: string;
    tokenCount?: DecisionTokenCount;
  },
): Attributes
```

Generates attributes for DECISION operations.

Creates OpenTelemetry attributes for a call to a decision model: a model that scores or selects among candidate options supplied in the request rather than generating free-form text. Decision spans identify the model under the `decision.*` namespace instead of `llm.*`, with the same semantics as [`getLLMAttributes`](https://openinf.dev/js/openinference-core.html.md#getLLMAttributes): `system` names the decision API ecosystem the call conforms to, `provider` names who hosts the model, and the model name keys follow the same request/response mirroring rules.

Record the raw request and response with `getInputAttributes` and `getOutputAttributes` (or the default processors); decision spans have no input or output messages.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `options` | `{ provider?: string; system?: string; modelName?: string; requestModelName?: string; responseModelName?: string; tokenCount?: DecisionTokenCount }` | Configuration object for DECISION attributes |
| `options.provider?` | `string` | Who hosts the decision model (e.g., “typesafe”, “openai”). See `DecisionProvider` in the semantic conventions for well-known values |
| `options.system?` | `string` | The decision API ecosystem the call conforms to (e.g., “typesafe” for the System One / Jev API, “openai” for the OpenAI Decisions API). See `DecisionSystem` in the semantic conventions for well-known values |
| `options.modelName?` | `string` | The name of the decision model (e.g., “jev-1.13.0”) |
| `options.requestModelName?` | `string` | The model requested by the caller, as sent in the request (e.g., the alias “jev-latest”). When modelName is omitted, decision.model_name is mirrored from responseModelName ?? requestModelName |
| `options.responseModelName?` | `string` | The model that actually produced the decision, as reported by the provider |
| `options.tokenCount?` | `DecisionTokenCount` | Token usage: the tokens sent (`input`) and the tokens that make up the typed answers (`output`) |

**Returns**

| Type | Description |
| - | - |
| `Attributes` | OpenTelemetry attributes for DECISION operations |

**Examples**

```typescript
const attrs = getDecisionAttributes({
  system: "typesafe",
  provider: "typesafe",
  requestModelName: "jev-latest",
  responseModelName: "jev-1.13.0",
  tokenCount: { input: 412, output: 2 },
});
```

### `observe`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/decorators.ts#L38)

```typescript
function observe<Fn extends AnyFn>(
  options?: SpanTraceOptions,
): (originalMethod: Fn, ctx: ClassMethodDecoratorContext) => (this: unknown, ...args: Parameters<Fn>) => any & Fn
```

A decorator factory for tracing operations in an LLM application.

This decorator wraps class methods to automatically create OpenTelemetry spans for tracing purposes. It leverages the `withSpan` function internally to ensure consistent tracing behavior across the library.

The decorator binds the original method at call time so the traced wrapper runs with the correct `this` value for each invocation.

This API is experimental and may change in future versions

**Parameters**

| Name | Type | Description |
| - | - | - |
| `options?` | `SpanTraceOptions` | Configuration options for the tracing behavior |

**Returns**

| Type | Description |
| - | - |
| `(originalMethod: Fn, ctx: ClassMethodDecoratorContext) => (this: unknown, ...args: Parameters<Fn>) => any & Fn` | A decorator function that can be applied to class methods |

**Examples**

```typescript
class MyService {
  @observe({ name: "processData", kind: "LLM" })
  async processData(input: string) {
    // Method implementation
    return `processed: ${input}`;
  }
}
```

### `wrapTracer`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/tracerHelpers.ts#L13)

```typescript
function wrapTracer(tracer: Tracer): OITracer
```

A function that ensures the tracer is wrapped in an OITracer if necessary.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `tracer` | `Tracer` | The tracer to wrap if necessary |

**Returns**

| Type | Description |
| - | - |
| `OITracer` | an OpenInferenceTracer that wraps the OTel Tracer |

### `getTracer`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/tracerHelpers.ts#L25)

```typescript
function getTracer(name?: string): OITracer
```

A helper function to get a tracer for the decorators.

### `AnyFn`

_type alias_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L14)

```typescript
type AnyFn = (...args: any[]) => any
```

### `SpanInput`

_type alias_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L36)

```typescript
type SpanInput = 
```

Represents the input data structure for OpenInference spans.

This type defines how function arguments or input data should be structured when creating span attributes. It provides both the serialized content and metadata about the content format for proper interpretation and display.

**Examples**

```typescript
const textInput: SpanInput = {
  value: "Hello, world!",
  mimeType: MimeType.TEXT
};

const jsonInput: SpanInput = {
  value: '{"query": "search term", "limit": 10}',
  mimeType: MimeType.JSON
};
```

### `SpanOutput`

_type alias_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L73)

```typescript
type SpanOutput = 
```

Represents the output data structure for OpenInference spans.

This type defines how function return values or output data should be structured when creating span attributes. It provides both the serialized content and metadata about the content format for proper interpretation and display.

**Examples**

```typescript
const textOutput: SpanOutput = {
  value: "Operation completed successfully",
  mimeType: MimeType.TEXT
};

const jsonOutput: SpanOutput = {
  value: '{"status": "success", "result": {"id": 123}}',
  mimeType: MimeType.JSON
};
```

### `InputToAttributesFn`

_type alias_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L115)

```typescript
type InputToAttributesFn<Fn extends AnyFn = AnyFn> = (...args: Parameters<Fn>) => Attributes
```

Function type for processing function arguments into OpenTelemetry attributes.

This function type defines the signature for custom input processors that convert function arguments into OpenTelemetry attributes for span enrichment. The function receives the original function arguments and should return an attributes object that will be added to the span.

**Examples**

```typescript
const customInputProcessor: InputToAttributesFn = (...args) => {
  if (args.length === 1 && typeof args[0] === 'object') {
    const input = args[0] as Record<string, unknown>;
    return {
      'input.type': typeof input,
      'input.value': JSON.stringify(input)
    };
  }
  return { 'input.args_count': args.length };
};
```

### `OutputToAttributesFn`

_type alias_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L142)

```typescript
type OutputToAttributesFn<Fn extends AnyFn = AnyFn> = (result: Awaited<ReturnType<Fn>>) => Attributes
```

Function type for processing function results into OpenTelemetry attributes.

This function type defines the signature for custom output processors that convert function return values into OpenTelemetry attributes for span enrichment. The function receives the original function’s return value and should return an attributes object that will be added to the span.

**Examples**

```typescript
const customOutputProcessor: OutputToAttributesFn = (result) => {
  if (result && typeof result === 'object') {
    return {
      'output.value': JSON.stringify(result)
    };
  }
  return {
    'output.value': String(result)
  };
};
```

### `SpanTraceOptions`

_interface_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L189)

```typescript
interface SpanTraceOptions<Fn extends AnyFn = AnyFn>
```

Configuration options for span tracing in OpenInference.

This interface defines all the available options for customizing how functions are traced, including span naming, tracer selection, span classification, and custom input/output processing. These options are used by tracing decorators and wrapper functions to control the tracing behavior.

**Examples**

```typescript
// Basic configuration with custom name
const basicOptions: SpanTraceOptions = {
  name: "my-custom-operation"
};

// Advanced configuration with custom processing and base attributes
const advancedOptions: SpanTraceOptions = {
  name: "llm-call",
  kind: "LLM",
  openTelemetrySpanKind: SpanKind.CLIENT,
  attributes: {
    'service.name': 'ai-assistant',
    'llm.model_name': 'gpt-4',
    'environment': 'production'
  },
  processInput: (...args) => ({ "llm.prompt": args[0] }),
  processOutput: (result) => ({ "llm.response": result })
};

// Agent-specific configuration with context attributes
const agentOptions: SpanTraceOptions = {
  kind: "AGENT",
  attributes: {
    'agent.type': 'decision-maker',
    'agent.version': '2.1.0'
  },
  processInput: (...args) => ({
    "agent.input": JSON.stringify(args[0]),
    "agent.context": args[1]?.context || "none"
  })
};
```

**Properties**

| Name | Type |
| - | - |
| [`name?`](https://openinf.dev/js/openinference-core.html.md#SpanTraceOptions.name) | `string`Custom name for the span.If not provided, the name of the decorated function or wrapped function will be used as the span name. This is useful for providing more descriptive or standardized names for operations.**Examples**```ts
"user-authentication", "data-processing-pipeline", "llm-inference"
``` |
| [`tracer?`](https://openinf.dev/js/openinference-core.html.md#SpanTraceOptions.tracer) | `Tracer`Custom OpenTelemetry tracer instance to use for this span.If not provided, the current global tracer provider is consulted when the wrapped function is invoked. This allows wrappers created before provider registration or replacement to pick up the latest global tracer unless you pin a specific tracer here.**Examples**```typescript
const customTracer = trace.getTracer('my-service', '1.0.0');
const options: SpanTraceOptions = { tracer: customTracer };
``` |
| [`openTelemetrySpanKind?`](https://openinf.dev/js/openinference-core.html.md#SpanTraceOptions.openTelemetrySpanKind) | `SpanKind`The OpenTelemetry span kind to classify the span’s role in a trace.This determines how the span is categorized in the OpenTelemetry ecosystem and affects how tracing tools display and analyze the span.> **Default**
>
> ```ts
> SpanKind.INTERNAL
> ```**Examples**```ts
- `SpanKind.CLIENT` for outbound requests
- `SpanKind.SERVER` for inbound request handling
- `SpanKind.INTERNAL` for internal operations
``` |
| [`kind?`](https://openinf.dev/js/openinference-core.html.md#SpanTraceOptions.kind) | `OpenInferenceSpanKind \| "LLM" \| "CHAIN" \| "TOOL" \| "RETRIEVER" \| "RERANKER" \| "EMBEDDING" \| "AGENT" \| "GUARDRAIL" \| "EVALUATOR" \| "PROMPT" \| "DECISION"`The OpenInference span kind for semantic categorization in LLM applications.This provides domain-specific classification for AI/ML operations, helping to organize and understand the different types of operations in an LLM workflow.> **Default**
>
> ```ts
> OpenInferenceSpanKind.CHAIN
> ```**Examples**```ts
- `LLM` for language model inference
- `CHAIN` for workflow sequences
- `AGENT` for autonomous decision-making
- `TOOL` for external tool usage
``` |
| [`processInput?`](https://openinf.dev/js/openinference-core.html.md#SpanTraceOptions.processInput) | `InputToAttributesFn<Fn>`Custom function to process input arguments into span attributes.This allows for custom serialization and attribute extraction from function arguments. If not provided, the default input processor will be used, which safely JSON-stringifies the arguments.**Returns**Description&#xA;&#xA;&#xA;OpenTelemetry attributes object**Examples**```typescript
processInput: (...args) => ({
  'input.value': JSON.stringify(args),
  'input.mime_type': MimeType.JSON
})
``` |
| [`processOutput?`](https://openinf.dev/js/openinference-core.html.md#SpanTraceOptions.processOutput) | `OutputToAttributesFn<Fn>`Custom function to process output values into span attributes.This allows for custom serialization and attribute extraction from function return values. If not provided, the default output processor will be used, which safely JSON-stringifies the result.**Returns**Description&#xA;&#xA;&#xA;OpenTelemetry attributes object**Examples**```typescript
processOutput: (result) => ({
  'output.value': JSON.stringify(result),
  'output.mime_type': MimeType.JSON
})
``` |
| [`attributes?`](https://openinf.dev/js/openinference-core.html.md#SpanTraceOptions.attributes) | `Attributes`Base attributes to be added to every span created with these options.These attributes will be merged with any attributes generated by input/output processors and OpenInference semantic attributes. Base attributes are useful for adding consistent metadata like service information, version numbers, environment details, or any other static attributes that should be present on all spans.**Examples**```typescript
// Custom business context
attributes: {
  'metadata': JSON.stringify({ tenant: 'tenant-123', feature: 'new-algorithm-enabled', request: 'mobile-app' })
}
``` |

### `Image`

_interface_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L314)

```typescript
interface Image
```

Image reference for message content.

Represents an image that can be included in message content, typically containing a URL or other reference to the image data.

**Properties**

| Name | Type |
| - | - |
| [`url?`](https://openinf.dev/js/openinference-core.html.md#Image.url) | `string` |

### `TextMessageContent`

_interface_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L324)

```typescript
interface TextMessageContent
```

Text-based message content.

Represents textual content within a message, used for standard text-based communication in LLM interactions.

**Properties**

| Name | Type |
| - | - |
| [`type`](https://openinf.dev/js/openinference-core.html.md#TextMessageContent.type) | `"text"` |
| [`text`](https://openinf.dev/js/openinference-core.html.md#TextMessageContent.text) | `string` |

### `ImageMessageContent`

_interface_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L335)

```typescript
interface ImageMessageContent
```

Image-based message content.

Represents image content within a message, used for multimodal LLM interactions that can process visual information.

**Properties**

| Name | Type |
| - | - |
| [`type`](https://openinf.dev/js/openinference-core.html.md#ImageMessageContent.type) | `"image"` |
| [`image?`](https://openinf.dev/js/openinference-core.html.md#ImageMessageContent.image) | `Image` |

### `ReasoningMessageContent`

_interface_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L349)

```typescript
interface ReasoningMessageContent
```

Reasoning-based message content.

Represents an opaque reasoning entry produced by an LLM. The fields are vendor-issued echo tokens that should be preserved verbatim for stateless replay (e.g. Gemini `thoughtSignature`, Anthropic `redacted_thinking.data`, OpenAI Responses `encrypted_content`). No `id` is emitted for reasoning content — providers either omit it or it is captured separately.

**Properties**

| Name | Type |
| - | - |
| [`type`](https://openinf.dev/js/openinference-core.html.md#ReasoningMessageContent.type) | `"reasoning"` |
| [`text?`](https://openinf.dev/js/openinference-core.html.md#ReasoningMessageContent.text) | `string`Human-readable reasoning text emitted by the model (e.g. Anthropic `thinking` blocks, OpenAI Responses reasoning summary text). Emitted as `message_content.text` and therefore subject to `hideInputText` / `hideOutputText` masking. |
| [`signature?`](https://openinf.dev/js/openinference-core.html.md#ReasoningMessageContent.signature) | `string`Opaque vendor-issued signature captured verbatim. Maps to provider signature fields and to Gemini `thoughtSignature` when the signature is attached to a non-tool content part. |
| [`data?`](https://openinf.dev/js/openinference-core.html.md#ReasoningMessageContent.data) | `string`Opaque vendor-issued data captured verbatim. Maps to Anthropic `redacted_thinking.data`. |
| [`encryptedContent?`](https://openinf.dev/js/openinference-core.html.md#ReasoningMessageContent.encryptedContent) | `string`OpenAI `encrypted_content` captured verbatim. |

### `MessageContent`

_type alias_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L381)

```typescript
type MessageContent = TextMessageContent | ImageMessageContent | ReasoningMessageContent
```

Union type for different types of message content.

Supports text, image, and reasoning content types for multimodal LLM applications that can handle various input formats.

### `ToolCallFunction`

_interface_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L389)

```typescript
interface ToolCallFunction
```

Function call details for tool invocations.

Contains the function name and arguments for tool calls made by LLMs during execution.

**Properties**

| Name | Type |
| - | - |
| [`name?`](https://openinf.dev/js/openinference-core.html.md#ToolCallFunction.name) | `string` |
| [`arguments?`](https://openinf.dev/js/openinference-core.html.md#ToolCallFunction.arguments) | `string \| Record<string, unknown>` |

### `ToolCall`

_interface_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L400)

```typescript
interface ToolCall
```

Tool call information.

Represents a complete tool call made by an LLM, including the call ID and function details.

**Properties**

| Name | Type |
| - | - |
| [`id?`](https://openinf.dev/js/openinference-core.html.md#ToolCall.id) | `string` |
| [`function?`](https://openinf.dev/js/openinference-core.html.md#ToolCall.function) | `ToolCallFunction` |
| [`reasoningSignature?`](https://openinf.dev/js/openinference-core.html.md#ToolCall.reasoningSignature) | `string`Opaque vendor-issued reasoning echo token attached to a tool call. Maps to Gemini `thoughtSignature` when it is attached to a `functionCall` part. The value is preserved verbatim for stateless replay. |

### `Message`

_interface_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L417)

```typescript
interface Message
```

Message structure for LLM conversations.

Represents a single message in an LLM conversation, supporting various content types, roles, and tool interactions.

**Properties**

| Name | Type |
| - | - |
| [`role?`](https://openinf.dev/js/openinference-core.html.md#Message.role) | `string` |
| [`content?`](https://openinf.dev/js/openinference-core.html.md#Message.content) | `string` |
| [`contents?`](https://openinf.dev/js/openinference-core.html.md#Message.contents) | `MessageContent[]` |
| [`toolCallId?`](https://openinf.dev/js/openinference-core.html.md#Message.toolCallId) | `string` |
| [`toolCalls?`](https://openinf.dev/js/openinference-core.html.md#Message.toolCalls) | `ToolCall[]` |

### `PromptDetails`

_interface_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L431)

```typescript
interface PromptDetails
```

Detailed prompt token usage information.

Provides granular information about token usage in prompts, including cache read/write operations and audio processing.

**Properties**

| Name | Type |
| - | - |
| [`audio?`](https://openinf.dev/js/openinference-core.html.md#PromptDetails.audio) | `number` |
| [`cacheRead?`](https://openinf.dev/js/openinference-core.html.md#PromptDetails.cacheRead) | `number` |
| [`cacheWrite?`](https://openinf.dev/js/openinference-core.html.md#PromptDetails.cacheWrite) | `number` |

### `TokenCount`

_interface_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L443)

```typescript
interface TokenCount
```

Token count information for LLM operations.

Tracks token usage across different parts of LLM interactions, including prompt, completion, and total token counts.

**Properties**

| Name | Type |
| - | - |
| [`prompt?`](https://openinf.dev/js/openinference-core.html.md#TokenCount.prompt) | `number` |
| [`completion?`](https://openinf.dev/js/openinference-core.html.md#TokenCount.completion) | `number` |
| [`total?`](https://openinf.dev/js/openinference-core.html.md#TokenCount.total) | `number` |
| [`promptDetails?`](https://openinf.dev/js/openinference-core.html.md#TokenCount.promptDetails) | `PromptDetails` |

### `DecisionTokenCount`

_interface_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L458)

```typescript
interface DecisionTokenCount
```

Token count information for DECISION operations.

Decision models have no prompt/completion split, only the tokens sent (state, questions, and candidate options) and the tokens that make up the typed answers. There is no total: it is derivable as the sum when both counts are present.

**Properties**

| Name | Type |
| - | - |
| [`input?`](https://openinf.dev/js/openinference-core.html.md#DecisionTokenCount.input) | `number` |
| [`output?`](https://openinf.dev/js/openinference-core.html.md#DecisionTokenCount.output) | `number` |

### `Tool`

_interface_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L469)

```typescript
interface Tool
```

Tool definition for LLM function calling.

Defines a tool that can be called by an LLM, including its JSON schema for parameter validation.

**Properties**

| Name | Type |
| - | - |
| [`jsonSchema`](https://openinf.dev/js/openinference-core.html.md#Tool.jsonSchema) | `string \| Record<string, unknown>` |

### `Embedding`

_interface_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L479)

```typescript
interface Embedding
```

Embedding representation with associated text.

Contains both the original text and its vector representation for embedding-based operations and similarity searches.

**Properties**

| Name | Type |
| - | - |
| [`text?`](https://openinf.dev/js/openinference-core.html.md#Embedding.text) | `string` |
| [`vector?`](https://openinf.dev/js/openinference-core.html.md#Embedding.vector) | `number[]` |

### `Document`

_interface_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L490)

```typescript
interface Document
```

Document structure for retrieval and search operations.

Represents a document in a knowledge base or search system, including content, metadata, and relevance scoring.

**Properties**

| Name | Type |
| - | - |
| [`content?`](https://openinf.dev/js/openinference-core.html.md#Document.content) | `string` |
| [`id?`](https://openinf.dev/js/openinference-core.html.md#Document.id) | `string \| number` |
| [`metadata?`](https://openinf.dev/js/openinference-core.html.md#Document.metadata) | `string \| Record<string, unknown>` |
| [`score?`](https://openinf.dev/js/openinference-core.html.md#Document.score) | `number` |

### `AnnotationScope`

_type alias_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L498)

```typescript
type AnnotationScope = "span" | "trace" | "session"
```

The target scope described by an annotation or evaluation.

### `Annotation`

_type alias_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/types.ts#L522)

```typescript
type Annotation = AnnotationBase & AnnotationResult
```

A single annotation or evaluation result.

Every result requires a name and at least one of `score`, `label`, or `explanation`.

### `withSpan`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/withSpan.ts#L96)

```typescript
function withSpan<Fn extends AnyFn = AnyFn>(
  fn: Fn,
  options?: SpanTraceOptions<Fn>,
): Fn
```

Wraps a function with openinference tracing capabilities, creating spans for execution monitoring.

This function provides comprehensive tracing for both synchronous and asynchronous functions, automatically handling span lifecycle, input/output processing, error tracking, and promise resolution.

Agent-facing behavior to rely on:

- Preserves the call-time `this` value, so wrapped methods still work when invoked as methods or via `.call()` / `.apply()`
- Records both synchronous throws and rejected promises on the span, marks the span as ERROR, ends the span, and re-throws the original error
- Resolves the default tracer when the wrapped function is invoked, so wrappers created before a global tracer provider change pick up the latest provider unless `options.tracer` was set

This API is experimental and may change in future versions

**Parameters**

| Name | Type | Description |
| - | - | - |
| `fn` | `Fn` | The function to wrap with tracing capabilities |
| `options?` | `SpanTraceOptions<Fn>` | Configuration options for tracing behavior |

**Returns**

| Type | Description |
| - | - |
| `Fn` | A wrapped function with identical signature that creates spans during execution |

**Examples**

```typescript
// Basic function wrapping
const add = (a: number, b: number) => a + b;
const tracedAdd = withSpan(add);
const result = tracedAdd(2, 3); // Creates a span named "add"

// Async function with custom options
const fetchData = async (url: string) => {
  const response = await fetch(url);
  return response.json();
};
const tracedFetch = withSpan(fetchData, {
  name: "api-request",
  kind: "LLM"
});

// Custom input/output processing with base attributes
const processUser = (user: User) => ({ ...user, processed: true });
const tracedProcess = withSpan(processUser, {
  attributes: {
    'service.name': 'user-processor',
    'service.version': '1.0.0'
  },
  processInput: (user) => ({ "user.id": user.id }),
  processOutput: (result) => ({ "result.processed": result.processed })
});
```

### `traceChain`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/wrappers.ts#L45)

```typescript
function traceChain<Fn extends AnyFn>(
  fn: Fn,
  options?: Omit<SpanTraceOptions<AnyFn>, "kind">,
): Fn
```

Wraps a function with tracing capabilities, specifically marking it as a CHAIN span.

This is a convenience function that wraps `withSpan` with the OpenInference span kind pre-configured to CHAIN. Chain spans represent a sequence of operations or a workflow in an LLM application, such as a series of processing steps or a pipeline.

This API is experimental and may change in future versions

**Parameters**

| Name | Type | Description |
| - | - | - |
| `fn` | `Fn` | The function to wrap with CHAIN span tracing |
| `options?` | `Omit<SpanTraceOptions<AnyFn>, "kind">` | Configuration options for tracing behavior (excluding kind) |

**Returns**

| Type | Description |
| - | - |
| `Fn` | A wrapped function with identical signature that creates CHAIN spans during execution |

**Examples**

```typescript
// Trace a data processing pipeline
const processData = (data: any[]) => {
  return data.map(item => transform(item)).filter(item => validate(item));
};
const tracedProcess = traceChain(processData, { name: "data-pipeline" });

// Trace a multi-step workflow
const executeWorkflow = async (input: WorkflowInput) => {
  const step1 = await preprocessInput(input);
  const step2 = await processStep(step1);
  return await finalizeOutput(step2);
};
const tracedWorkflow = traceChain(executeWorkflow);
```

### `traceAgent`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/wrappers.ts#L94)

```typescript
function traceAgent<Fn extends AnyFn>(
  fn: Fn,
  options?: Omit<SpanTraceOptions<AnyFn>, "kind">,
): Fn
```

Wraps a function with tracing capabilities, specifically marking it as an AGENT span.

This is a convenience function that wraps `withSpan` with the OpenInference span kind pre-configured to AGENT. Agent spans represent autonomous decision-making entities in an LLM application, such as AI agents, chat bots, or intelligent assistants that can reason, plan, and execute actions.

This API is experimental and may change in future versions

**Parameters**

| Name | Type | Description |
| - | - | - |
| `fn` | `Fn` | The function to wrap with AGENT span tracing |
| `options?` | `Omit<SpanTraceOptions<AnyFn>, "kind">` | Configuration options for tracing behavior (excluding kind) |

**Returns**

| Type | Description |
| - | - |
| `Fn` | A wrapped function with identical signature that creates AGENT spans during execution |

**Examples**

```typescript
// Trace an AI agent's decision-making process
const makeDecision = async (context: AgentContext) => {
  const analysis = await analyzeContext(context);
  const plan = await createPlan(analysis);
  return await executePlan(plan);
};
const tracedAgent = traceAgent(makeDecision, { name: "decision-agent" });

// Trace a chatbot response generation
const generateResponse = (userMessage: string, history: Message[]) => {
  const intent = classifyIntent(userMessage);
  const context = buildContext(history);
  return generateReply(intent, context);
};
const tracedChatbot = traceAgent(generateResponse);
```

### `traceTool`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/wrappers.ts#L143)

```typescript
function traceTool<Fn extends AnyFn>(
  fn: Fn,
  options?: Omit<SpanTraceOptions<AnyFn>, "kind">,
): Fn
```

Wraps a function with tracing capabilities, specifically marking it as a TOOL span.

This is a convenience function that wraps `withSpan` with the OpenInference span kind pre-configured to TOOL. Tool spans represent external tools, utilities, or services that an LLM application can invoke, such as APIs, databases, calculators, web scrapers, or any external function that provides specific capabilities.

This API is experimental and may change in future versions

**Parameters**

| Name | Type | Description |
| - | - | - |
| `fn` | `Fn` | The function to wrap with TOOL span tracing |
| `options?` | `Omit<SpanTraceOptions<AnyFn>, "kind">` | Configuration options for tracing behavior (excluding kind) |

**Returns**

| Type | Description |
| - | - |
| `Fn` | A wrapped function with identical signature that creates TOOL spans during execution |

**Examples**

```typescript
// Trace an API call tool
const fetchWeather = async (city: string) => {
  const response = await fetch(`/api/weather?city=${city}`);
  return response.json();
};
const tracedWeatherTool = traceTool(fetchWeather, { name: "weather-api" });

// Trace a calculator tool
const calculate = (expression: string) => {
  return eval(expression); // Note: eval is dangerous, use proper parser
};
const tracedCalculator = traceTool(calculate, { name: "calculator" });

// Trace a database query tool
const queryDatabase = async (query: string, params: any[]) => {
  return await db.query(query, params);
};
const tracedDbTool = traceTool(queryDatabase);
```

### `traceLLM`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/wrappers.ts#L178)

```typescript
function traceLLM<Fn extends AnyFn>(
  fn: Fn,
  options?: Omit<SpanTraceOptions<AnyFn>, "kind">,
): Fn
```

Wraps a function with tracing capabilities, specifically marking it as an LLM span.

This is a convenience function that wraps `withSpan` with the OpenInference span kind pre-configured to LLM. LLM spans represent invocations of a large language model, such as chat completions, text completions, or other inference calls to a foundation model.

This API is experimental and may change in future versions

**Parameters**

| Name | Type | Description |
| - | - | - |
| `fn` | `Fn` | The function to wrap with LLM span tracing |
| `options?` | `Omit<SpanTraceOptions<AnyFn>, "kind">` | Configuration options for tracing behavior (excluding kind) |

**Returns**

| Type | Description |
| - | - |
| `Fn` | A wrapped function with identical signature that creates LLM spans during execution |

**Examples**

```typescript
// Trace a chat completion call
const chatCompletion = async (messages: Message[]) => {
  return await client.chat.completions.create({ model: "gpt-4", messages });
};
const tracedCompletion = traceLLM(chatCompletion, { name: "chat-completion" });
```

### `traceRetriever`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/wrappers.ts#L214)

```typescript
function traceRetriever<Fn extends AnyFn>(
  fn: Fn,
  options?: Omit<SpanTraceOptions<AnyFn>, "kind">,
): Fn
```

Wraps a function with tracing capabilities, specifically marking it as a RETRIEVER span.

This is a convenience function that wraps `withSpan` with the OpenInference span kind pre-configured to RETRIEVER. Retriever spans represent operations that fetch relevant documents or context from a knowledge base, vector store, or search index, typically as part of a retrieval-augmented generation (RAG) workflow.

This API is experimental and may change in future versions

**Parameters**

| Name | Type | Description |
| - | - | - |
| `fn` | `Fn` | The function to wrap with RETRIEVER span tracing |
| `options?` | `Omit<SpanTraceOptions<AnyFn>, "kind">` | Configuration options for tracing behavior (excluding kind) |

**Returns**

| Type | Description |
| - | - |
| `Fn` | A wrapped function with identical signature that creates RETRIEVER spans during execution |

**Examples**

```typescript
// Trace a vector store similarity search
const retrieveDocuments = async (query: string) => {
  return await vectorStore.similaritySearch(query, 5);
};
const tracedRetriever = traceRetriever(retrieveDocuments, { name: "vector-search" });
```

### `traceReranker`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/wrappers.ts#L256)

```typescript
function traceReranker<Fn extends AnyFn>(
  fn: Fn,
  options?: Omit<SpanTraceOptions<AnyFn>, "kind">,
): Fn
```

Wraps a function with tracing capabilities, specifically marking it as a RERANKER span.

This is a convenience function that wraps `withSpan` with the OpenInference span kind pre-configured to RERANKER. Reranker spans represent operations that reorder or score a set of candidate documents by relevance to a query, commonly used to refine the results returned by a retriever before passing them to a language model.

This API is experimental and may change in future versions

**Parameters**

| Name | Type | Description |
| - | - | - |
| `fn` | `Fn` | The function to wrap with RERANKER span tracing |
| `options?` | `Omit<SpanTraceOptions<AnyFn>, "kind">` | Configuration options for tracing behavior (excluding kind) |

**Returns**

| Type | Description |
| - | - |
| `Fn` | A wrapped function with identical signature that creates RERANKER spans during execution |

**Examples**

```typescript
// Trace a document reranking operation
const rerankDocuments = async (query: string, documents: Document[]) => {
  return await reranker.rerank(query, documents);
};
const tracedReranker = traceReranker(rerankDocuments, { name: "rerank" });
```

### `traceEmbedding`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/wrappers.ts#L295)

```typescript
function traceEmbedding<Fn extends AnyFn>(
  fn: Fn,
  options?: Omit<SpanTraceOptions<AnyFn>, "kind">,
): Fn
```

Wraps a function with tracing capabilities, specifically marking it as an EMBEDDING span.

This is a convenience function that wraps `withSpan` with the OpenInference span kind pre-configured to EMBEDDING. Embedding spans represent operations that convert text or other data into vector representations, such as generating embeddings for documents or queries used in semantic search and retrieval.

This API is experimental and may change in future versions

**Parameters**

| Name | Type | Description |
| - | - | - |
| `fn` | `Fn` | The function to wrap with EMBEDDING span tracing |
| `options?` | `Omit<SpanTraceOptions<AnyFn>, "kind">` | Configuration options for tracing behavior (excluding kind) |

**Returns**

| Type | Description |
| - | - |
| `Fn` | A wrapped function with identical signature that creates EMBEDDING spans during execution |

**Examples**

```typescript
// Trace an embedding generation call
const embedText = async (text: string) => {
  return await client.embeddings.create({ model: "text-embedding-3-small", input: text });
};
const tracedEmbedding = traceEmbedding(embedText, { name: "embed-text" });
```

### `traceGuardrail`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/wrappers.ts#L337)

```typescript
function traceGuardrail<Fn extends AnyFn>(
  fn: Fn,
  options?: Omit<SpanTraceOptions<AnyFn>, "kind">,
): Fn
```

Wraps a function with tracing capabilities, specifically marking it as a GUARDRAIL span.

This is a convenience function that wraps `withSpan` with the OpenInference span kind pre-configured to GUARDRAIL. Guardrail spans represent safety, validation, or policy checks applied to inputs or outputs of an LLM application, such as content moderation, PII detection, or compliance enforcement.

This API is experimental and may change in future versions

**Parameters**

| Name | Type | Description |
| - | - | - |
| `fn` | `Fn` | The function to wrap with GUARDRAIL span tracing |
| `options?` | `Omit<SpanTraceOptions<AnyFn>, "kind">` | Configuration options for tracing behavior (excluding kind) |

**Returns**

| Type | Description |
| - | - |
| `Fn` | A wrapped function with identical signature that creates GUARDRAIL spans during execution |

**Examples**

```typescript
// Trace a content moderation check
const moderateContent = async (text: string) => {
  return await moderationClient.check(text);
};
const tracedGuardrail = traceGuardrail(moderateContent, { name: "content-moderation" });
```

### `traceEvaluator`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/wrappers.ts#L379)

```typescript
function traceEvaluator<Fn extends AnyFn>(
  fn: Fn,
  options?: Omit<SpanTraceOptions<AnyFn>, "kind">,
): Fn
```

Wraps a function with tracing capabilities, specifically marking it as an EVALUATOR span.

This is a convenience function that wraps `withSpan` with the OpenInference span kind pre-configured to EVALUATOR. Evaluator spans represent operations that assess or score the quality of an LLM application’s output, such as relevance scoring, correctness checks, or LLM-as-a-judge evaluations.

This API is experimental and may change in future versions

**Parameters**

| Name | Type | Description |
| - | - | - |
| `fn` | `Fn` | The function to wrap with EVALUATOR span tracing |
| `options?` | `Omit<SpanTraceOptions<AnyFn>, "kind">` | Configuration options for tracing behavior (excluding kind) |

**Returns**

| Type | Description |
| - | - |
| `Fn` | A wrapped function with identical signature that creates EVALUATOR spans during execution |

**Examples**

```typescript
// Trace an LLM-as-a-judge evaluation
const evaluateAnswer = async (question: string, answer: string) => {
  return await judge.score({ question, answer });
};
const tracedEvaluator = traceEvaluator(evaluateAnswer, { name: "answer-evaluation" });
```

### `tracePrompt`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/wrappers.ts#L421)

```typescript
function tracePrompt<Fn extends AnyFn>(
  fn: Fn,
  options?: Omit<SpanTraceOptions<AnyFn>, "kind">,
): Fn
```

Wraps a function with tracing capabilities, specifically marking it as a PROMPT span.

This is a convenience function that wraps `withSpan` with the OpenInference span kind pre-configured to PROMPT. Prompt spans represent operations that construct, render, or template a prompt before it is sent to a language model, such as formatting a prompt template with variables or assembling a set of messages.

This API is experimental and may change in future versions

**Parameters**

| Name | Type | Description |
| - | - | - |
| `fn` | `Fn` | The function to wrap with PROMPT span tracing |
| `options?` | `Omit<SpanTraceOptions<AnyFn>, "kind">` | Configuration options for tracing behavior (excluding kind) |

**Returns**

| Type | Description |
| - | - |
| `Fn` | A wrapped function with identical signature that creates PROMPT spans during execution |

**Examples**

```typescript
// Trace a prompt template rendering
const renderPrompt = (variables: Record<string, string>) => {
  return promptTemplate.format(variables);
};
const tracedPrompt = tracePrompt(renderPrompt, { name: "render-prompt" });
```

### `traceDecision`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/helpers/wrappers.ts#L461)

```typescript
function traceDecision<Fn extends AnyFn>(
  fn: Fn,
  options?: Omit<SpanTraceOptions<AnyFn>, "kind">,
): Fn
```

Wraps a function with tracing capabilities, specifically marking it as a DECISION span.

This is a convenience function that wraps `withSpan` with the OpenInference span kind pre-configured to DECISION. Decision spans represent calls to a decision model that scores or selects among candidate options provided in the request rather than generating free-form text, such as choosing a route, judging a condition, or scoring an item against a rubric.

This API is experimental and may change in future versions

**Parameters**

| Name | Type | Description |
| - | - | - |
| `fn` | `Fn` | The function to wrap with DECISION span tracing |
| `options?` | `Omit<SpanTraceOptions<AnyFn>, "kind">` | Configuration options for tracing behavior (excluding kind) |

**Returns**

| Type | Description |
| - | - |
| `Fn` | A wrapped function with identical signature that creates DECISION spans during execution |

**Examples**

```typescript
// Trace a route selection decision
const selectRoute = async (query: string, routes: Route[]) => {
  return await decisionModel.choose({ query, candidates: routes });
};
const tracedDecision = traceDecision(selectRoute, { name: "route-selection" });
```

### `ContextAttributes`

_constant_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L26)

```typescript
const ContextAttributes
```

**Properties**

| Name | Type |
| - | - |
| [`llm.prompt_template.template`](https://openinf.dev/js/openinference-core.html.md#ContextAttributes.llm.prompt_template.template) | `symbol = ...` |
| [`llm.prompt_template.variables`](https://openinf.dev/js/openinference-core.html.md#ContextAttributes.llm.prompt_template.variables) | `symbol = ...` |
| [`llm.prompt_template.version`](https://openinf.dev/js/openinference-core.html.md#ContextAttributes.llm.prompt_template.version) | `symbol = ...` |
| [`session.id`](https://openinf.dev/js/openinference-core.html.md#ContextAttributes.session.id) | `symbol = ...` |
| [`metadata`](https://openinf.dev/js/openinference-core.html.md#ContextAttributes.metadata) | `symbol = ...` |
| [`user.id`](https://openinf.dev/js/openinference-core.html.md#ContextAttributes.user.id) | `symbol = ...` |
| [`tag.tags`](https://openinf.dev/js/openinference-core.html.md#ContextAttributes.tag.tags) | `symbol = ...` |
| [`attributes`](https://openinf.dev/js/openinference-core.html.md#ContextAttributes.attributes) | `symbol = ...` |

### `setPromptTemplate`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L74)

```typescript
function setPromptTemplate(
  context: Context,
  promptTemplate: PromptTemplate,
): Context
```

Sets the prompt template in the given OpenTelemetry context. If OI tracer is used in spans created during this active context, the prompt template will be added to the span as an attribute.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `context` | `Context` | The context to set the prompt template on. |
| `promptTemplate` | `PromptTemplate` | The prompt template to set on the context. |

**Returns**

| Type | Description |
| - | - |
| `Context` | The context |

**Examples**

```typescript
context.with(
  setPromptTemplate(context.active(), {
    template: "hello {name}",
    variables: { name: "world" },
    version: "V1.0"
  }),
  () => {
    // Spans created here will have prompt template attributes
  }
);
```

### `clearPromptTemplate`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L91)

```typescript
function clearPromptTemplate(context: Context): Context
```

Clears the prompt template from the given OpenTelemetry context.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `context` | `Context` | The context to clear the prompt template from. |

**Returns**

| Type | Description |
| - | - |
| `Context` | The context |

### `getPromptTemplate`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L104)

```typescript
function getPromptTemplate(
  context: Context,
): Partial<PromptTemplate> | undefined
```

Gets the prompt template from the given OpenTelemetry context.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `context` | `Context` | The context to get the prompt template from. |

**Returns**

| Type | Description |
| - | - |
| `Partial<PromptTemplate> \| undefined` | The prompt template |

**Examples**

```ts
const promptTemplate = getPromptTemplate(context.active());
```

### `setSession`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L144)

```typescript
function setSession(context: Context, session: Session): Context
```

Sets the session ID in the given OpenTelemetry context. If OI tracer is used in spans created during this active context, the session ID will be added to the span as an attribute.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `context` | `Context` | The context to set the session ID on. |
| `session` | `Session` | The session to set on the context. |

**Returns**

| Type | Description |
| - | - |
| `Context` | The context |

**Examples**

```typescript
context.with(
  setSession(context.active(), { sessionId: "session-123" }),
  () => {
    // Spans created here will have session ID attribute
  }
);
```

### `clearSession`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L149)

```typescript
function clearSession(context: Context): Context
```

### `getSession`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L158)

```typescript
function getSession(context: Context): Session | undefined
```

Retrieves the session ID from the given context.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `context` | `Context` | The context object. |

**Returns**

| Type | Description |
| - | - |
| `Session \| undefined` | The session ID if it exists, otherwise undefined. |

### `setMetadata`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L182)

```typescript
function setMetadata(context: Context, metadata: Metadata): Context
```

Sets the metadata in the given OpenTelemetry context. If OI tracer is used in spans created during this active context, the metadata will be added to the span as an attribute.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `context` | `Context` | The context to set the metadata on. |
| `metadata` | `Metadata` | The metadata to set on the context. |

**Returns**

| Type | Description |
| - | - |
| `Context` | The context |

**Examples**

```typescript
context.with(
  setMetadata(context.active(), { key: "value", numeric: 1 }),
  () => {
    // Spans created here will have metadata attribute
  }
);
```

### `clearMetadata`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L191)

```typescript
function clearMetadata(context: Context): Context
```

Clears the metadata from the given OpenTelemetry context.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `context` | `Context` | The context to clear the metadata from. |

**Returns**

| Type | Description |
| - | - |
| `Context` | The context |

### `getMetadata`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L201)

```typescript
function getMetadata(context: Context): Metadata | undefined
```

Gets the metadata from the given OpenTelemetry context.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `context` | `Context` | The context to get the metadata from. |

**Returns**

| Type | Description |
| - | - |
| `Metadata \| undefined` | The metadata |

**Examples**

```ts
const metadata = getMetadata(context.active());
```

### `setUser`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L226)

```typescript
function setUser(context: Context, user: User): Context
```

Sets the user ID in the given OpenTelemetry context.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `context` | `Context` | The context to set the user ID on. |
| `user` | `User` | The user to set on the context. |

**Returns**

| Type | Description |
| - | - |
| `Context` | The context |

**Examples**

```typescript
context.with(
  setUser(context.active(), { userId: "user-123" }),
  () => {
    // Spans created here will have user ID attribute
  }
);
```

### `clearUser`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L236)

```typescript
function clearUser(context: Context): Context
```

Clears the user ID from the given OpenTelemetry context.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `context` | `Context` | The context to clear the user ID from. |

**Returns**

| Type | Description |
| - | - |
| `Context` | The context |

### `getUser`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L246)

```typescript
function getUser(context: Context): User | undefined
```

Gets the user ID from the given OpenTelemetry context.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `context` | `Context` | The context to get the user ID from. |

**Returns**

| Type | Description |
| - | - |
| `User \| undefined` | The user |

**Examples**

```ts
const user = getUser(context.active());
```

### `setTags`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L270)

```typescript
function setTags(context: Context, tags: Tags): Context
```

Sets the tags in the given OpenTelemetry context. If OI tracer is used in spans created during this active context, the tags will be added to the span as an attribute.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `context` | `Context` | The context to set the tags on. |
| `tags` | `Tags` | The tags to set on the context. |

**Returns**

| Type | Description |
| - | - |
| `Context` | The context |

**Examples**

```typescript
context.with(
  setTags(context.active(), ["tag1", "tag2"]),
  () => {
    // Spans created here will have tags attribute
  }
);
```

### `clearTags`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L279)

```typescript
function clearTags(context: Context): Context
```

Clears the tags from the given OpenTelemetry context.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `context` | `Context` | The context to clear the tags from. |

**Returns**

| Type | Description |
| - | - |
| `Context` | The context |

### `getTags`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L289)

```typescript
function getTags(context: Context): Tags | undefined
```

Gets the tags from the given OpenTelemetry context.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `context` | `Context` | The context to get the tags from. |

**Returns**

| Type | Description |
| - | - |
| `Tags \| undefined` | The tags |

**Examples**

```ts
const tags = getTags(context.active());
```

### `setAttributes`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L314)

```typescript
function setAttributes(context: Context, attributes: Attributes): Context
```

Sets the attributes in the given OpenTelemetry context. If OI tracer is used in spans created during this active context, the attributes will be added to the span as an attribute.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `context` | `Context` | The context to set the attributes on. |
| `attributes` | `Attributes` | The attributes to set on the context. |

**Returns**

| Type | Description |
| - | - |
| `Context` | The context |

**Examples**

```typescript
context.with(
  setAttributes(context.active(), { custom: "value", test: "attribute" }),
  () => {
    // Spans created here will have custom attributes
  }
);
```

### `clearAttributes`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L323)

```typescript
function clearAttributes(context: Context): Context
```

Clears the attributes from the given OpenTelemetry context.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `context` | `Context` | The context to clear the attributes from. |

**Returns**

| Type | Description |
| - | - |
| `Context` | The context |

### `getAttributes`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L333)

```typescript
function getAttributes(context: Context): Attributes | undefined
```

Gets the attributes from the given OpenTelemetry context.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `context` | `Context` | The context to get the attributes from. |

**Returns**

| Type | Description |
| - | - |
| `Attributes \| undefined` | The attributes |

**Examples**

```ts
const attributes = getAttributes(context.active());
```

### `getAttributesFromContext`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/contextAttributes.ts#L366)

```typescript
function getAttributesFromContext(context: Context): Attributes
```

Gets the OpenInference attributes from the given context

**Examples**

```typescript
// Chaining multiple attributes
context.with(
  setSession(
    setPromptTemplate(context.active(), {
      template: "hello {name}",
      variables: { name: "world" },
      version: "V1.0"
    }),
    { sessionId: "session-123" }
  ),
  () => {
    // Extract all attributes for span
    const attributes = getAttributesFromContext(context.active());
    span.setAttributes(attributes);
  }
);
```

**Returns**

| Type | Description |
| - | - |
| `Attributes` | The OpenInference attributes formatted as OpenTelemetry span attributes. |

### `OISpan`

_interface_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/OISpan.ts#L18)

```typescript
interface OISpan implements Span
```

A wrapper around the OpenTelemetry [Span](https://opentelemetry.io/docs/specs/otel/trace/api/#span) interface that masks sensitive information based on the passed in [`TraceConfig`](https://openinf.dev/js/openinference-core.html.md#TraceConfig).

#### `setAttribute`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/OISpan.ts#L27)

```typescript
setAttribute(key: string, value: AttributeValue): this
```

Sets an attribute to the span.

Sets a single Attribute with the key and value passed as arguments.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `key` | `string` | the key for this attribute. |
| `value` | `AttributeValue` | the value for this attribute. Setting a value null or undefined is invalid and will result in undefined behavior. |

#### `setAttributes`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/OISpan.ts#L35)

```typescript
setAttributes(attributes: Attributes): this
```

Sets attributes to the span.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `attributes` | `Attributes` | the attributes that will be added. null or undefined attribute values are invalid and will result in undefined behavior. |

#### `addEvent`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/OISpan.ts#L44)

```typescript
addEvent(
  name: string,
  attributesOrStartTime?: Attributes | TimeInput,
  startTime?: TimeInput,
): this
```

Adds an event to the Span.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `name` | `string` | the name of the event. |
| `attributesOrStartTime?` | `Attributes \| TimeInput` | the attributes that will be added; these are associated with this event. Can be also a start time if type is TimeInput and 3rd param is undefined |
| `startTime?` | `TimeInput` | start time of the event. |

#### `setStatus`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/OISpan.ts#L53)

```typescript
setStatus(status: SpanStatus): this
```

Sets a status to the span. If used, this will override the default Span status. Default is `SpanStatusCode.UNSET`. SetStatus overrides the value of previous calls to SetStatus on the Span.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `status` | `SpanStatus` | the SpanStatus to set. |

#### `updateName`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/OISpan.ts#L58)

```typescript
updateName(name: string): this
```

Updates the Span name.

This will override the name provided via `Tracer.startSpan`.

Upon this update, any sampling behavior based on Span name will depend on the implementation.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `name` | `string` | the Span name. |

#### `end`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/OISpan.ts#L63)

```typescript
end(endTime?: TimeInput): void
```

Marks the end of Span execution.

Call to End of a Span MUST not have any effects on child spans. Those may still be running and can be ended later.

Do not return `this`. The Span generally should not be used after it is ended so chaining is not desired in this context.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `endTime?` | `TimeInput` | the time to set as Span’s end time. If not provided, use the current time as the span’s end time. |

#### `isRecording`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/OISpan.ts#L67)

```typescript
isRecording(): boolean
```

Returns the flag whether this span will be recorded.

**Returns**

| Type | Description |
| - | - |
| `boolean` | true if this Span is active and recording information like events with the `AddEvent` operation and attributes using `setAttributes`. |

#### `recordException`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/OISpan.ts#L71)

```typescript
recordException(exception: Exception, time?: TimeInput): void
```

Sets exception as a span event

**Parameters**

| Name | Type | Description |
| - | - | - |
| `exception` | `Exception` | the exception the only accepted values are string or Error |
| `time?` | `TimeInput` | the time to set as Span’s event time. If not provided, use the current time. |

#### `spanContext`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/OISpan.ts#L75)

```typescript
spanContext(): SpanContext
```

Returns the [SpanContext](https://opentelemetry.io/docs/specs/otel/trace/api/#spancontext) object associated with this Span.

Get an immutable, serializable identifier for this span that can be used to create new child spans. Returned SpanContext is usable even after the span ends.

**Returns**

| Type | Description |
| - | - |
| `SpanContext` | the SpanContext object associated with this Span. |

#### `addLink`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/OISpan.ts#L79)

```typescript
addLink(link: Link): this
```

Adds a single link to the span.

Links added after the creation will not affect the sampling decision. It is preferred span links be added at span creation.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `link` | `Link` | the link to add. |

#### `addLinks`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/OISpan.ts#L84)

```typescript
addLinks(links: Link[]): this
```

Adds multiple links to the span.

Links added after the creation will not affect the sampling decision. It is preferred span links be added at span creation.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `links` | `Link[]` | the links to add. |

### `OITracer`

_class_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/OITracer.ts#L46)

```typescript
class OITracer implements Tracer
```

A wrapper around the OpenTelemetry [Tracer](https://opentelemetry.io/docs/specs/otel/trace/api/#tracer) interface that masks sensitive information based on the passed in [`TraceConfig`](https://openinf.dev/js/openinference-core.html.md#TraceConfig).

#### `new OITracer`

_constructor_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/OITracer.ts#L54)

```typescript
new OITracer(
  params: { tracer: Tracer; traceConfig?: TraceConfigOptions },
): OITracer
```

**Parameters**

| Name | Type | Description |
| - | - | - |
| `params` | `{ tracer: Tracer; traceConfig?: TraceConfigOptions }` | The parameters for the OITracer constructor |
| `params.tracer` | `Tracer` | The OpenTelemetry [Tracer](https://opentelemetry.io/docs/specs/otel/trace/api/#tracer) to wrap |
| `params.traceConfig?` | `TraceConfigOptions` | The [`TraceConfigOptions`](https://openinf.dev/js/openinference-core.html.md#TraceConfigOptions) to set to control the behavior of the tracer |

#### `startActiveSpan`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/OITracer.ts#L58)

```typescript
startActiveSpan<F extends (span: OISpan) => unknown>(
  name: string,
  fn: F,
): ReturnType<F>
```

```typescript
startActiveSpan<F extends (span: OISpan) => unknown>(
  name: string,
  options: SpanOptions,
  fn: F,
): ReturnType<F>
```

```typescript
startActiveSpan<F extends (span: OISpan) => unknown>(
  name: string,
  options: SpanOptions,
  context: Context,
  fn: F,
): ReturnType<F>
```

**Overload 1**

Starts a new [Span](https://opentelemetry.io/docs/specs/otel/trace/api/#span) and calls the given function passing it the created span as first argument. Additionally the new span gets set in context and this context is activated for the duration of the function call.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `name` | `string` | The name of the span |
| `fn` | `F` | function called in the context of the span and receives the newly created span as an argument |

**Returns**

| Type | Description |
| - | - |
| `ReturnType<F>` | return value of fn |

**Examples**

```ts
const something = tracer.startActiveSpan('op', span => {
      try {
        do some work
        span.setStatus({code: SpanStatusCode.OK});
        return something;
      } catch (err) {
        span.setStatus({
          code: SpanStatusCode.ERROR,
          message: err.message,
        });
        throw err;
      } finally {
        span.end();
      }
    });
```

**Examples**

```ts
const span = tracer.startActiveSpan('op', span => {
      try {
        do some work
        return span;
      } catch (err) {
        span.setStatus({
          code: SpanStatusCode.ERROR,
          message: err.message,
        });
        throw err;
      }
    });
    do some more work
    span.end();
```

#### `startSpan`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/OITracer.ts#L99)

```typescript
startSpan(name: string, options?: SpanOptions, context?: Context): OISpan
```

Starts a new [Span](https://opentelemetry.io/docs/specs/otel/trace/api/#span). Start the span without setting it on context.

This method do NOT modify the current Context.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `name` | `string` | The name of the span |
| `options?` | `SpanOptions` | SpanOptions used for span creation |
| `context?` | `Context` | Context to use to extract parent |

**Returns**

| Type | Description |
| - | - |
| `OISpan` | Span The newly created span |

**Examples**

```ts
const span = tracer.startSpan('op');
    span.setAttribute('key', 'value');
    span.end();
```

### `generateTraceConfig`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/traceConfig.ts#L70)

```typescript
function generateTraceConfig(options?: TraceConfigOptions): TraceConfig
```

Generates a full trace config object based on passed in options, environment variables, and default values. The order of precedence is: optionValue > envValue > defaultValue

**Parameters**

| Name | Type | Description |
| - | - | - |
| `options?` | `TraceConfigOptions` | The user provided TraceConfigOptions. |

**Returns**

| Type | Description |
| - | - |
| `TraceConfig` | A full TraceConfig object with all options set to their final values. |

### `TraceConfigOptions`

_type alias_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/types.ts#L8)

```typescript
type TraceConfigOptions = 
```

Tracing configuration options that can be set to hide or redact sensitive information from traces

### `TraceConfig`

_type alias_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/trace-config/types.ts#L26)

```typescript
type TraceConfig = Readonly<Required<TraceConfigOptions>>
```

A full tracing configuration object that includes all possible options with their final values

### `Session`

_type alias_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/types.ts#L4)

```typescript
type Session = 
```

A session that can be attached to context

### `Metadata`

_type alias_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/types.ts#L11)

```typescript
type Metadata = Record<string, unknown>
```

Metadata that can be attached to context

### `User`

_type alias_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/types.ts#L16)

```typescript
type User = 
```

A user that can be attached to context

### `PromptTemplate`

_type alias_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/types.ts#L23)

```typescript
type PromptTemplate = 
```

A prompt template that can be attached to context

### `Tags`

_type alias_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/trace/types.ts#L32)

```typescript
type Tags = string[]
```

A set of tags that can be attached to context

### `withSafety`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/utils/index.ts#L9)

```typescript
function withSafety<T extends GenericFunction>(
  fn: { fn: T; onError?: (error: unknown) => void },
): SafeFunction<T>
```

Wraps a function with a try-catch block to catch and log any errors.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `fn` | `{ fn: T; onError?: (error: unknown) => void }` | A function to wrap with a try-catch block. |
| `fn.fn` | `T` | |
| `fn.onError?` | `(error: unknown) => void` | |

**Returns**

| Type | Description |
| - | - |
| `SafeFunction<T>` | A function that returns null if an error is thrown. |

### `safelyJSONStringify`

_constant_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/utils/index.ts#L32)

```typescript
const safelyJSONStringify: SafeFunction<(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number) => string>
```

### `safelyJSONParse`

_constant_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/utils/index.ts#L34)

```typescript
const safelyJSONParse: SafeFunction<(...args: [text: string, reviver?: (this: any, key: string, value: any) => any]) => unknown>
```

### `isStringArray`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/utils/typeUtils.ts#L9)

```typescript
function isStringArray(value: unknown): value is string[]
```

Type guard to determine whether or not a value is an array of strings.

**Returns**

| Type | Description |
| - | - |
| `value is string[]` | true if the value is an array of strings, false otherwise. |

### `isObjectWithStringKeys`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/utils/typeUtils.ts#L27)

```typescript
function isObjectWithStringKeys(
  value: unknown,
): value is Record<string, unknown>
```

Type guard to determine whether or not a value is an object with string keys.

**Returns**

| Type | Description |
| - | - |
| `value is Record<string, unknown>` | true if the value is an object with string keys, false otherwise. |

### `isPromise`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/utils/typeUtils.ts#L36)

```typescript
function isPromise<T = unknown>(value: unknown): value is Promise<T>
```

Type guard for if a function is a Promise

**Returns**

| Type | Description |
| - | - |
| `value is Promise<T>` | true if it is a Promise |

### `isAttributes`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/utils/typeUtils.ts#L45)

```typescript
function isAttributes(value: unknown): value is Attributes
```

Type guard to determine whether or not a value is an object with string keys and attribute values.

**Returns**

| Type | Description |
| - | - |
| `value is Attributes` | true if the value is an object with string keys and attribute values, false otherwise. |

### `assertUnreachable`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/utils/typeUtils.ts#L72)

```typescript
function assertUnreachable(value: never): never
```

A type check function to ensure that a switch or set of conditionals is exhaustive. Typescript will throw an error if the switch or conditionals are not exhaustive.

**Examples**

```typescript
type MyType = "a" | "b";
function myFunction(value: MyType) {
  switch (value) {
    case "a":
     return "A";
   case "b":
     return "B";
   default:
     assertUnreachable(value);
  }
}
```

### `GenericFunction`

_type alias_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/utils/types.ts#L2)

```typescript
type GenericFunction = (...args: any[]) => any
```

### `SafeFunction`

_type alias_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-core/src/utils/types.ts#L4)

```typescript
type SafeFunction<T extends GenericFunction> = (...args: Parameters<T>) => ReturnType<T> | null
```

**Constants**

| Name | Value |
| - | - |
| [`OPENINFERENCE_HIDE_LLM_TOOLS`](https://openinf.dev/js/openinference-core.html.md#OPENINFERENCE_HIDE_LLM_TOOLS) | `"OPENINFERENCE_HIDE_LLM_TOOLS"`Hides the tool definitions advertised to the LLM |
| [`OPENINFERENCE_HIDE_INPUTS`](https://openinf.dev/js/openinference-core.html.md#OPENINFERENCE_HIDE_INPUTS) | `"OPENINFERENCE_HIDE_INPUTS"`Hides input value & messages |
| [`OPENINFERENCE_HIDE_OUTPUTS`](https://openinf.dev/js/openinference-core.html.md#OPENINFERENCE_HIDE_OUTPUTS) | `"OPENINFERENCE_HIDE_OUTPUTS"`Hides output value & messages |
| [`OPENINFERENCE_HIDE_INPUT_MESSAGES`](https://openinf.dev/js/openinference-core.html.md#OPENINFERENCE_HIDE_INPUT_MESSAGES) | `"OPENINFERENCE_HIDE_INPUT_MESSAGES"`Hides all input messages |
| [`OPENINFERENCE_HIDE_OUTPUT_MESSAGES`](https://openinf.dev/js/openinference-core.html.md#OPENINFERENCE_HIDE_OUTPUT_MESSAGES) | `"OPENINFERENCE_HIDE_OUTPUT_MESSAGES"`Hides all output messages |
| [`OPENINFERENCE_HIDE_INPUT_IMAGES`](https://openinf.dev/js/openinference-core.html.md#OPENINFERENCE_HIDE_INPUT_IMAGES) | `"OPENINFERENCE_HIDE_INPUT_IMAGES"`Hides images from input messages |
| [`OPENINFERENCE_HIDE_INPUT_TEXT`](https://openinf.dev/js/openinference-core.html.md#OPENINFERENCE_HIDE_INPUT_TEXT) | `"OPENINFERENCE_HIDE_INPUT_TEXT"`Hides text from input messages |
| [`OPENINFERENCE_HIDE_OUTPUT_TEXT`](https://openinf.dev/js/openinference-core.html.md#OPENINFERENCE_HIDE_OUTPUT_TEXT) | `"OPENINFERENCE_HIDE_OUTPUT_TEXT"`Hides text from output messages |
| [`OPENINFERENCE_HIDE_EMBEDDING_VECTORS`](https://openinf.dev/js/openinference-core.html.md#OPENINFERENCE_HIDE_EMBEDDING_VECTORS) | `"OPENINFERENCE_HIDE_EMBEDDING_VECTORS"`Hides embedding vectors |
| [`OPENINFERENCE_BASE64_IMAGE_MAX_LENGTH`](https://openinf.dev/js/openinference-core.html.md#OPENINFERENCE_BASE64_IMAGE_MAX_LENGTH) | `"OPENINFERENCE_BASE64_IMAGE_MAX_LENGTH"`Limits characters of a base64 encoding of an image |
| [`OPENINFERENCE_HIDE_PROMPTS`](https://openinf.dev/js/openinference-core.html.md#OPENINFERENCE_HIDE_PROMPTS) | `"OPENINFERENCE_HIDE_PROMPTS"`Hides LLM prompts |
| [`DEFAULT_HIDE_LLM_TOOLS`](https://openinf.dev/js/openinference-core.html.md#DEFAULT_HIDE_LLM_TOOLS) | `false` |
| [`DEFAULT_HIDE_INPUTS`](https://openinf.dev/js/openinference-core.html.md#DEFAULT_HIDE_INPUTS) | `false` |
| [`DEFAULT_HIDE_OUTPUTS`](https://openinf.dev/js/openinference-core.html.md#DEFAULT_HIDE_OUTPUTS) | `false` |
| [`DEFAULT_HIDE_INPUT_MESSAGES`](https://openinf.dev/js/openinference-core.html.md#DEFAULT_HIDE_INPUT_MESSAGES) | `false` |
| [`DEFAULT_HIDE_OUTPUT_MESSAGES`](https://openinf.dev/js/openinference-core.html.md#DEFAULT_HIDE_OUTPUT_MESSAGES) | `false` |
| [`DEFAULT_HIDE_INPUT_IMAGES`](https://openinf.dev/js/openinference-core.html.md#DEFAULT_HIDE_INPUT_IMAGES) | `false` |
| [`DEFAULT_HIDE_INPUT_TEXT`](https://openinf.dev/js/openinference-core.html.md#DEFAULT_HIDE_INPUT_TEXT) | `false` |
| [`DEFAULT_HIDE_OUTPUT_TEXT`](https://openinf.dev/js/openinference-core.html.md#DEFAULT_HIDE_OUTPUT_TEXT) | `false` |
| [`DEFAULT_HIDE_EMBEDDING_VECTORS`](https://openinf.dev/js/openinference-core.html.md#DEFAULT_HIDE_EMBEDDING_VECTORS) | `false` |
| [`DEFAULT_BASE64_IMAGE_MAX_LENGTH`](https://openinf.dev/js/openinference-core.html.md#DEFAULT_BASE64_IMAGE_MAX_LENGTH) | `32000` |
| [`REDACTED_VALUE`](https://openinf.dev/js/openinference-core.html.md#REDACTED_VALUE) | `"__REDACTED__"`When a value is hidden, it will be replaced by this redacted value |
