# TraceHeader | @aa-sdk/core

> Some tools that are useful when dealing with the values of the trace header. Follows the W3C trace context standard.

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

{/* This file is auto-generated by TypeDoc. Do not edit manually. */}

Defined in: [aa-sdk/core/src/utils/traceHeader.ts:31](https://github.com/alchemyplatform/aa-sdk/blob/main/aa-sdk/core/src/utils/traceHeader.ts#L31)

Some tools that are useful when dealing with the values
of the trace header. Follows the W3C trace context standard.

## See

https://www.w3.org/TR/trace-context/

## Constructors

### Constructor

```ts
new TraceHeader(
   traceId,
   parentId,
   traceFlags,
   traceState): TraceHeader;
```

Defined in: [aa-sdk/core/src/utils/traceHeader.ts:45](https://github.com/alchemyplatform/aa-sdk/blob/main/aa-sdk/core/src/utils/traceHeader.ts#L45)

Initializes a new instance with the provided trace identifiers and state information.

#### Parameters

<table>
  <thead>
    <tr>
      <th align="left">Parameter</th>
      <th align="left">Type</th>
      <th align="left">Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `traceId`
      </td>

      <td>
        `string`
      </td>

      <td>
        The unique identifier for the trace
      </td>
    </tr>

    <tr>
      <td>
        `parentId`
      </td>

      <td>
        `string`
      </td>

      <td>
        The identifier of the parent trace
      </td>
    </tr>

    <tr>
      <td>
        `traceFlags`
      </td>

      <td>
        `string`
      </td>

      <td>
        Flags containing trace-related options
      </td>
    </tr>

    <tr>
      <td>
        `traceState`
      </td>

      <td>
        `Record`\<`string`, `string`>
      </td>

      <td>
        The trace state information for additional trace context
      </td>
    </tr>

  </tbody>
</table>

#### Returns

`TraceHeader`

## Properties

<table>
  <thead>
    <tr>
      <th align="left">Property</th>
      <th align="left">Type</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        <a id="parentid" /> `parentId`
      </td>

      <td>
        `string`
      </td>
    </tr>

    <tr>
      <td>
        <a id="traceflags" /> `traceFlags`
      </td>

      <td>
        `string`
      </td>
    </tr>

    <tr>
      <td>
        <a id="traceid" /> `traceId`
      </td>

      <td>
        `string`
      </td>
    </tr>

    <tr>
      <td>
        <a id="tracestate" /> `traceState`
      </td>

      <td>
        `Record`\<`string`, `string`>
      </td>
    </tr>

  </tbody>
</table>

## Methods

### toTraceHeader()

```ts
toTraceHeader(): object;
```

Defined in: [aa-sdk/core/src/utils/traceHeader.ts:126](https://github.com/alchemyplatform/aa-sdk/blob/main/aa-sdk/core/src/utils/traceHeader.ts#L126)

Should be able to convert the trace header to the format that is used in the headers of an http request

#### Example

```ts
const traceHeader =
  TraceHeader.fromTraceHeader(headers) || TraceHeader.default();
const headers = traceHeader.toTraceHeader();
```

#### Returns

`object`

The trace header in the format of a record, used in our http client

<table>
  <thead>
    <tr>
      <th align="left">Name</th>
      <th align="left">Type</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `traceparent`
      </td>

      <td>
        `` `00-${string}-${string}-${string}` ``
      </td>
    </tr>

    <tr>
      <td>
        `tracestate`
      </td>

      <td>
        `string`
      </td>
    </tr>

  </tbody>
</table>

---

### withEvent()

```ts
withEvent(eventName): TraceHeader;
```

Defined in: [aa-sdk/core/src/utils/traceHeader.ts:149](https://github.com/alchemyplatform/aa-sdk/blob/main/aa-sdk/core/src/utils/traceHeader.ts#L149)

Should be able to create a new trace header with a new event in the trace state,
as the key of the eventName as breadcrumbs appending onto previous breadcrumbs with the - infix if exists. And the
trace parent gets updated as according to the docs

#### Example

```ts
const traceHeader =
  TraceHeader.fromTraceHeader(headers) || TraceHeader.default();
const newTraceHeader = traceHeader.withEvent("newEvent");
```

#### Parameters

<table>
  <thead>
    <tr>
      <th align="left">Parameter</th>
      <th align="left">Type</th>
      <th align="left">Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `eventName`
      </td>

      <td>
        `string`
      </td>

      <td>
        The key of the new event
      </td>
    </tr>

  </tbody>
</table>

#### Returns

`TraceHeader`

The new trace header

---

### default()

```ts
static default(): TraceHeader;
```

Defined in: [aa-sdk/core/src/utils/traceHeader.ts:67](https://github.com/alchemyplatform/aa-sdk/blob/main/aa-sdk/core/src/utils/traceHeader.ts#L67)

Creating a default trace id that is a random setup for both trace id and parent id

#### Example

```ts
const traceHeader =
  TraceHeader.fromTraceHeader(headers) || TraceHeader.default();
```

#### Returns

`TraceHeader`

A default trace header

---

### fromTraceHeader()

```ts
static fromTraceHeader(headers): undefined | TraceHeader;
```

Defined in: [aa-sdk/core/src/utils/traceHeader.ts:86](https://github.com/alchemyplatform/aa-sdk/blob/main/aa-sdk/core/src/utils/traceHeader.ts#L86)

Should be able to consume a trace header from the headers of an http request

#### Example

```ts
const traceHeader = TraceHeader.fromTraceHeader(headers);
```

#### Parameters

<table>
  <thead>
    <tr>
      <th align="left">Parameter</th>
      <th align="left">Type</th>
      <th align="left">Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `headers`
      </td>

      <td>
        `Record`\<`string`, `string`>
      </td>

      <td>
        The headers from the http request
      </td>
    </tr>

  </tbody>
</table>

#### Returns

`undefined` | `TraceHeader`

The trace header object, or nothing if not found