import { Callout, Card, Cards, Steps, Tabs } from "nextra/components";
import UniversalTabs from "@/components/UniversalTabs";
import { Snippet } from "@/components/code";
import { snippets } from "@/lib/generated/snippets";

# Additional Metadata

Hatchet allows you to attach arbitrary key-value string pairs to events and task runs, which can be used for filtering, searching, or any other lookup purposes. This additional metadata is not part of the event payload or task input data but provides supplementary information for better organization and discoverability.

<Callout type="info">
  Additional metadata can be added to `Runs`, `Scheduled Runs`, `Cron Runs`, and
  `Events`. The data is propagated from parents to children or from events to
  runs.
</Callout>

You can attach additional metadata when pushing events or triggering task runs using the Hatchet client libraries:

<Tabs items={['Event Push', 'Task Run Trigger']}>
  <Tabs.Tab>
<UniversalTabs items={['Python', 'Typescript', 'Go', "Ruby"]}>
  <Tabs.Tab>

<Snippet src={snippets.python.events.event.event_trigger_with_metadata} />

  </Tabs.Tab>
  <Tabs.Tab>

<Snippet src={snippets.typescript.on_event.event.push_an_event_with_metadata} />

  </Tabs.Tab>
  <Tabs.Tab>

<Snippet src={snippets.go.run_with_metadata.main.push_an_event_with_metadata} />

  </Tabs.Tab>
  <Tabs.Tab title="Ruby">
    <Snippet src={snippets.ruby.events.event.event_trigger_with_metadata} />
  </Tabs.Tab>
</UniversalTabs>
  </Tabs.Tab>
  <Tabs.Tab>
<UniversalTabs items={['Python', 'Typescript', 'Go', "Ruby"]} variant="hidden">
  <Tabs.Tab>

<Snippet
  src={snippets.python.simple.trigger_with_metadata.trigger_with_metadata}
/>

  </Tabs.Tab>
  <Tabs.Tab>
<Snippet
  src={snippets.typescript.simple.run.run_with_metadata}
/>

  </Tabs.Tab>
  <Tabs.Tab>

<Snippet src={snippets.go.run_with_metadata.main.run_with_metadata} />

  </Tabs.Tab>
  <Tabs.Tab title="Ruby">
    <Snippet src={snippets.ruby.simple.trigger_with_metadata.trigger_with_metadata} />
  </Tabs.Tab>
</UniversalTabs>
  </Tabs.Tab>
</Tabs>

## Filtering in the Dashboard

Once you've attached additional metadata to events or task runs, this data will be available in the Event and Task Run list views in the Hatchet dashboard. You can use the filter input field to search for events or task runs based on the additional metadata key-value pairs you've attached.

For example, you can filter events by the `source` metadata keys to quickly find events originating from a specific source or environment.

![Blocks](/addl-meta.gif)

## Filtering Semantics

When filtering **runs** with `additional_metadata`, Hatchet returns runs that match **any** of the provided pairs (logical `OR`), not all of them.

<Callout type="info">
  For example, filtering runs with `{ first_name: "john", last_name: "doe" }`
  returns runs whose metadata matches *either* `first_name: "john"` *or*
  `last_name: "doe"`, not only runs that match both.
</Callout>

Event filtering behaves differently: filtering **events** with multiple `additional_metadata` pairs requires all pairs to match (logical `AND`), since events use `JSONB` containment under the hood.

<Callout type="info">
  For example, filtering events with `{ first_name: "john", last_name: "doe" }`
  returns only events whose metadata matches *both* `first_name: "john"` *and*
  `last_name: "doe"`.
</Callout>

## Use Cases

Some common use cases for additional metadata include:

- Tagging events or task runs with environment information (e.g., `production`, `staging`, `development`)
- Specifying the source or origin of events (e.g., `api`, `webhook`, `manual`)
- Categorizing events or task runs based on business-specific criteria (e.g., `priority`, `region`, `product`)

By leveraging additional metadata, you can enhance the organization, searchability, and discoverability of your events and task runs within Hatchet.
