# Relations between components

## Overview

Component and span relations show the relationship between components in StackState. For example, the image below shows a relation running from a parent to a child component, that child also then has another component as a child component:

```
Service Name: Parent Component
|
---> Service Name: Child Component
     |
     ---> Service Name: Child 2 Component
```

An example of the above displayed in StackState will show up as follows:

![Topology Perspective - Unmerged OTEL Components](https://2702698828-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ft9xRpVRApnyVQrX3f8HH%2Fuploads%2Fgit-blob-e510278f5e42b4b8afcdfd2586cc9a010394ffa4%2Fv51_otel_topology_perspective_healthy_component.png?alt=media)

These relations are based on the parent and child structure. A relationship is drawn from a parent component to a child component.

This means that:

* `Service Name: Child Component` has the parent ID set as `Service Name: Parent Component`
* `Service Name: Child 2 Component` has the parent ID set as `Service Name: Child Component`

## Health state propagation

In StackState, the health state of a component will propagate upwards through the dependency tree. This means that in the following situation:

```
Service Name: Parent Component
|
---> Service Name: Child Component [400 Status]
     |
     ---> Service Name: Child 2 Component
```

The following components will have a propagated CRITICAL state:

```
Service Name: Parent Component [Propagated 400 Status]
|
---> Service Name: Child Component [400 Status]
     |
     ---> Service Name: Child 2 Component
```

A visual example of this in the StackState UI will be as follows:

![Topology Perspective - OTEL Components CRITICAL State](https://2702698828-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ft9xRpVRApnyVQrX3f8HH%2Fuploads%2Fgit-blob-cbbe4c65e107ea20a43953a8cd567f55f9514e01%2Fv51_otel_topology_perspective_critical_component.png?alt=media)

So remember to create your parent and children spans in the correct order as it may affect the propagation of health state.

➡️ [Learn more about health state propagation](https://archivedocs.stackstate.com/5.1/use/concepts/health-state#element-propagated-health-state)

## Relations when merging

Relations are retained when merging components; this allows you to create a parent component, create a child component for this parent and then merge that child component with an existing component. This will then create a relationship between the pre-existing component that the child component merged with and the parent component. For example, here we have the three components as described above:

![Topology Perspective - OTEL Components and Pre-Existing Components](https://2702698828-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ft9xRpVRApnyVQrX3f8HH%2Fuploads%2Fgit-blob-df164adf5cbef2c2965550a96e0ff0ee43c3ce11%2Fv51_otel_scenario_pre-existing_components.png?alt=media)

If we then merge our middle component `Service Name: Child Component` with the existing healthy Lambda component `otel-example-custom-instrumentation-dev-create-custom-component` in the bottom right corner:

* The middle component will disappear (merged with the Lambda component)
* The Lambda component will have relations to the first and third components (inherited relation mappings from the middle component).

![Topology Perspective - Merged with Healthy Component](https://2702698828-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ft9xRpVRApnyVQrX3f8HH%2Fuploads%2Fgit-blob-84926485250e8de8de791595156f81289d292bb0%2Fv51_otel_traces_merge_with_healthy_complete.png?alt=media)

## Multiple children

It's also good to know that a single parent can have multiple children. This allows you to build a tree with branches of relations, for example:

```
Service Name: Parent Component
|
---> Service Name: Child Component
|
---> Service Name: Child 2 Component
```

![Topology Perspective - OTEL Components with Multiple Children](https://2702698828-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ft9xRpVRApnyVQrX3f8HH%2Fuploads%2Fgit-blob-0bd4704c13a08dbd019d8ce2a036d861315dc6f3%2Fv51_otel_traces_multiple_children.png?alt=media)
