> ## Documentation Index
> Fetch the complete documentation index at: https://prefect-bd373955-pytest-markdown.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Track activity through events

> An event is a notification of a change, creating a history of activity in your stack.

Events can represent API calls, state transitions, or changes in your execution environment or infrastructure.

Events power several features in Prefect Cloud, including flow run logs, audit logs, and automations.

Events enable observability into your data stack through the [event feed in the UI](#events-in-the-cloud-ui) and the
configuration of Prefect's reactivity through [automations](/3.0rc/automate/events/automations-triggers/).

## Event specification

Events adhere to a structured [specification](https://app.prefect.cloud/api/docs#tag/Events).

![Prefect UI](https://mintlify.s3-us-west-1.amazonaws.com/prefect-bd373955-pytest-markdown/3.0rc/img/ui/event-spec.png)

| Name     | Type   | Required? | Description                                                     |
| -------- | ------ | --------- | --------------------------------------------------------------- |
| occurred | String | yes       | When the event happened                                         |
| event    | String | yes       | Name of the event that happened                                 |
| resource | Object | yes       | Primary resource this event concerns                            |
| related  | Array  | no        | List of additional Resources involved in this event             |
| payload  | Object | no        | Open-ended set of data describing what happened                 |
| id       | String | yes       | Client-provided identifier of this event                        |
| follows  | String | no        | ID of an event that is known to have occurred prior to this one |

## Event grammar

Events have a consistent and informative grammar: an event describes a resource and an action it took—
or that was taken—on that resource. For example, events emitted by Prefect objects take the form of:

```
prefect.block.write-method.called
prefect-cloud.automation.action.executed
prefect-cloud.user.logged-in
```

## Event sources

Prefect objects automatically emit events, including flows, tasks, deployments, work queues, and logs.
Prefect-emitted events contain the `prefect` or `prefect-cloud` resource prefix.
You can also send events to the Prefect
[events API](https://app.prefect.cloud/api/docs#tag/Events) through an authenticated HTTP request.

### Emit custom events from Python code

The Prefect Python SDK provides an `emit_event` function that emits a Prefect event when called. You can call
`emit_event` inside or outside of a task or flow. For example, running this code emits an event to Prefect Cloud,
which validates and ingests the event data:

```python
from prefect.events import emit_event

def some_function(name: str="kiki") -> None:
    print(f"hi {name}!")
    emit_event(event=f"{name}.sent.event!", resource={"prefect.resource.id": f"coder.{name}"})

some_function()
```

You must pass `emit_event` two arguments: `event`, the name of the event, and `resource={"prefect.resource.id": "my_string"}`,
the resource ID.

To get data into an event for use in an automation action, specify a dictionary of values for the `payload` parameter.

### Emit events through webhooks

Prefect Cloud offers [programmable webhooks](/3.0rc/automate/events/webhook-triggers/) to receive HTTP requests
from other systems and translate them into events within your workspace. Webhooks can emit
[pre-defined static events](/3.0rc/automate/events/webhook-triggers/#static-webhook-events),
dynamic events that [use portions of the incoming HTTP request](/3.0rc/automate/events/webhook-triggers/#dynamic-webhook-events),
or events derived from [CloudEvents](/3.0rc/automate/events/webhook-triggers/#accepting-cloudevents).

Events emitted from any source appear in the event feed, where you can visualize activity in context and configure
[automations](/3.0rc/automate/events/automations-triggers/) to react to the presence or absence of events in the future.

## Resources

Every event has a primary resource, which describes the object that emitted an event. Resources are used as quasi-stable
identifiers for sources of events, and are constructed as dot-delimited strings, for example:

```
prefect-cloud.automation.5b9c5c3d-6ca0-48d0-8331-79f4b65385b3.action.0
acme.user.kiki.elt_script_1
prefect.flow-run.e3755d32-cec5-42ca-9bcd-af236e308ba6
```

Resources can optionally have additional arbitrary labels which can be used in event aggregation queries, such as:

```json
"resource": {
    "prefect.resource.id": "prefect-cloud.automation.5b9c5c3d-6ca0-48d0-8331-79f4b65385b3",
    "prefect-cloud.action.type": "call-webhook"
    }
```

Events can optionally contain related resources, used to associate the event with other resources, such as in the case
that the primary resource acted on or with another resource:

```json
"resource": {
    "prefect.resource.id": "prefect-cloud.automation.5b9c5c3d-6ca0-48d0-8331-79f4b65385b3.action.0",
    "prefect-cloud.action.type": "call-webhook"
  },
"related": [
  {
      "prefect.resource.id": "prefect-cloud.automation.5b9c5c3d-6ca0-48d0-8331-79f4b65385b3",
      "prefect.resource.role": "automation",
      "prefect-cloud.name": "webhook_body_demo",
      "prefect-cloud.posture": "Reactive"
  }
]
```

## Events in the Cloud UI

Prefect Cloud provides an interactive dashboard to analyze and take action on events that occurred in your workspace on
the event feed page.

![Event feed](https://mintlify.s3-us-west-1.amazonaws.com/prefect-bd373955-pytest-markdown/3.0rc/img/ui/event-feed.png)

The event feed is the primary place to view, search, and filter events to understand activity across your stack.
Each entry displays data on the resource, related resource, and event that took place.

View more information about an event by clicking into it. You will see full details of an event's
resource, related resources, and its payload.

## Respond to events

From an event page, you can configure an [automation](/3.0rc/automate/events/automations-triggers) to trigger on
the observation of matching events—or a lack of matching events—by clicking the automate button in the overflow menu:

![Automation from event](https://mintlify.s3-us-west-1.amazonaws.com/prefect-bd373955-pytest-markdown/3.0rc/img/ui/automation-from-event.png)

The default trigger configuration fires every time it sees an event with a matching resource identifier. Advanced
configuration is possible through [custom triggers](/3.0rc/automate/events/automations-triggers/).
