Skip to content

RFC-0011 - Parent-Child Trace/Span Orchestration - #1172

Open
adri1197 wants to merge 1 commit into
fluxcd:mainfrom
adri1197:otel-source
Open

adri1197 wants to merge 1 commit into
fluxcd:mainfrom
adri1197:otel-source

Conversation

@adri1197

@adri1197 adri1197 commented Sep 18, 2025 •

Copy link
Copy Markdown
Contributor

Implements the parent-child span hierarchy from RFC-0011 in the OTEL notifier, so traces mirror the Flux object hierarchy.

Behavior

Each event is still exported as one span. The span is parented as follows:

  1. Managing Kustomization: found through the kustomize.toolkit.fluxcd.io/{name,namespace} labels. The walk has cycle detection and is capped at 10 levels.
  2. event.RelatedObject: used when the event carries one.
  3. Cluster lookup: used only when the event has no related object. It reads a Kustomization's source, or a HelmRelease's chartRef or generated HelmChart.
  • Trace ID: <AlertUID>:<root revision>.
  • Span ID: derived from <object UID>:<revision>, so children can reference their parent deterministically.
  • Events with no resolvable revision get a trace of their own.
  • A source reconciled by the Kustomization that manages it (the flux bootstrap topology) is the root of its own revision's trace.
  • HelmRepository events are skipped and are not used as trace roots.

Closes fluxcd/flux2#5510

@adri1197 adri1197 changed the title [RFC-0011] Support source-revision populated by a kustomization Support source-revision populated by a kustomization Sep 18, 2025
Comment thread internal/notifier/otel.go Resolved
@adri1197

adri1197 commented Mar 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Hello!

After a few iterations, I’ve finalized an initial design for the tracing logic. The core objective is to establish deterministic parent-child relationships across spans by following a consistent ID convention: <UID> + <Revision>.

  • Objects managed by a Kustomization: In this context, the trace is anchored to the Kustomization's lifecycle.

    • TraceID: <alert.UID> + <kust's revision>.
    • ParentSpan
      • For Sources: Relies on the Kustomization's identity: <kust.UID> + <kust.revision>.
      • For HelmRelease objects: Relies on the source's identity: <source.UID> + <event.revision>.

    Source > Kustomization > Kustomization > KRM objects
    image

    Source > Kustomization > Kustomization > Source > HelmReleases

    image
  • Objects NOT managed by a Kustomization

    • TraceID: <alert.UID> + <event's revision>.
    • ParentSpan:
      • For Non-Source objects: Relies on the upstream source's identity: <source.UID> + <event.revision>.

    Helm Repository > HelmChart (source) > HelmReleases
    image

To support this, I introduced a custom generator that manages ID creation based on the involvedObject metadata. This ensures that even across different controllers, all spans follow the unified convention: <involvedObject.UID> + <event.revision>.

Any feedback? 😄

Another point that I wanted to tackle is about having recursive backwards against nested Kustomizations to find the root and therefore, be able to properly find and set Trace revision. Any thoughts on this? @stefanprodan

@matheuscscp

Copy link
Copy Markdown
Member

This is starting to get very interesting!

@adri1197 adri1197 changed the title Support source-revision populated by a kustomization OTEL - Parent-Child Span Orchestration Mar 3, 2026
@adri1197 adri1197 changed the title OTEL - Parent-Child Span Orchestration OTEL - Parent-Child Trace/Span Orchestration Mar 3, 2026
@adri1197

adri1197 commented Mar 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Hello!

After a few iterations, I’ve finalized an initial design for the tracing logic. The core objective is to establish deterministic parent-child relationships across spans by following a consistent ID convention: <UID> + <Revision>.

  • Objects managed by a Kustomization: In this context, the trace is anchored to the Kustomization's lifecycle.

    • TraceID: <alert.UID> + <kust's revision>.

    • ParentSpan

      • For Sources: Relies on the Kustomization's identity: <kust.UID> + <kust.revision>.
      • For HelmRelease objects: Relies on the source's identity: <source.UID> + <event.revision>.

    Source > Kustomization > Kustomization > KRM objects
    image
    Source > Kustomization > Kustomization > Source > HelmReleases
    image

  • Objects NOT managed by a Kustomization

    • TraceID: <alert.UID> + <event's revision>.

    • ParentSpan:

      • For Non-Source objects: Relies on the upstream source's identity: <source.UID> + <event.revision>.

    Helm Repository > HelmChart (source) > HelmReleases
    image

To support this, I introduced a custom generator that manages ID creation based on the involvedObject metadata. This ensures that even across different controllers, all spans follow the unified convention: <involvedObject.UID> + <event.revision>.

Any feedback? 😄

Another point that I wanted to tackle is about having recursive backwards against nested Kustomizations to find the root and therefore, be able to properly find and set Trace revision. Any thoughts on this? @stefanprodan

On top of what was shared above, added some minor adjustments (including Kustomization recursivity) and code improvements to support more advanced use case cases:

Source (GitRepository) > Kustomization > Source (GitRepository) > Kustomization > Source (HelmRepository & OCIRepository) > HelmReleases

image

@adri1197 adri1197 changed the title OTEL - Parent-Child Trace/Span Orchestration RFC-0011 - Parent-Child Trace/Span Orchestration Mar 5, 2026
@adri1197
adri1197 marked this pull request as draft April 12, 2026 17:57
Comment thread internal/notifier/otel.go Outdated
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.34.0"
semconv "go.opentelemetry.io/otel/semconv/v1.40.0"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol never seen something like this.....

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, a bit odd to have the semconv versioning as part of the path 😆

Comment thread internal/notifier/otel.go Fixed
Comment thread internal/notifier/otel.go Resolved
Comment thread internal/notifier/otel.go Resolved
@adri1197
adri1197 force-pushed the otel-source branch 2 times, most recently from a2f45fd to 2398593 Compare October 21, 2026 00:21
@adri1197
adri1197 marked this pull request as ready for review October 21, 2026 00:21
@adri1197

Copy link
Copy Markdown
Contributor Author

Hi @stefanprodan — could you pls have a review on this one? Would be really valuable to get your review here. 🙏

To support the review, I ran the RFC-0011 tracing end-to-end against a local cluster (kind-based). Summary of what was verified:

  • relatedObject population & correlation — confirmed the OTEL notifier consumes event.RelatedObject in collectParentUID(...) to link child spans to their parent. Across all four scenarios, relatedObject is populated with a real UID on every non-source object, so parent/child spans reconstruct directly from the event (no extra API read):

    • test-1: GitRepository → Kustomization(s) → KRM (plain manifests).
    • test-2: GitRepository → Kustomization → OCIRepository → HelmRelease.
    • test-3: HelmChart → HelmRelease (Install + Test events both linked).
    • test-4: GitRepository → Kustomization → GitRepository → Kustomization → {HelmChart, OCIRepository} → HelmRelease.
  • Source objects (GitRepository, OCIRepository, HelmChart, HelmRepository) correctly carry no relatedObject — they're the trace roots, as expected.

  • HelmRepository is intentionally skipped as a tracing parent; chains root at HelmChart, matching the design.

Happy to share fuller logs if useful

@stefanprodan stefanprodan added enhancement New feature or request area/alerting Alerting related issues and PRs labels Oct 21, 2026
@adri1197
adri1197 requested a review from matheuscscp November 27, 2026 15:09
Link each event's span to the span of the object it is managed by or
built from, so OTEL traces mirror the Flux object hierarchy. Walk the
Kustomization labels with cycle detection and a depth cap, fall back
to the event's RelatedObject and the object's spec, and read objects
through a live reader that honours --no-cross-namespace-refs.

Signed-off-by: Adrian Fernandez de la Torre <adri1197@gmail.com>
Assisted-by: Kiro/auto
@adri1197

adri1197 commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Rebase done on latest main and ready for review. @matheuscscp @stefanprodan, I'd appreciate your thoughts on the latest changes. Thanks! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/alerting Alerting related issues and PRs enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC-0011] OTEL: Parent-Child Trace/Span Integration

4 participants