Skip to content

Conversation

@AwesomePatrol
Copy link
Contributor

@AwesomePatrol AwesomePatrol commented Jul 8, 2025

Part of #12460.

context.Context argument is added to replace returning traceutil.Trace. This solves the problem of "merging" two traces and makes it easy to transition to nested spans possible in OpenTelemetry tracing.

Some occurrences of context.TODO() were also replaced with actual context.

@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: AwesomePatrol
Once this PR has been reviewed and has the lgtm label, please assign jmhbnz for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
Copy link

Hi @AwesomePatrol. Thanks for your PR.

I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@AwesomePatrol AwesomePatrol marked this pull request as draft July 8, 2025 09:57
@AwesomePatrol AwesomePatrol force-pushed the migration-to-otel-tracing-first-step branch from d26a817 to fb00ff4 Compare July 8, 2025 12:29
@AwesomePatrol AwesomePatrol changed the title Reduce traceutil API in preparation for OpenTelemetry migration Replace returned Trace with Context argument in internal Applier interface Jul 8, 2025
@AwesomePatrol AwesomePatrol force-pushed the migration-to-otel-tracing-first-step branch 2 times, most recently from ecb7674 to 1ec3f46 Compare July 8, 2025 12:41
case r.Range != nil:
op = "Range"
ar.Resp, ar.Trace, ar.Err = a.applyV3.Range(r.Range)
ctx := context.Background()
Copy link
Member

Choose a reason for hiding this comment

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

Do you need to have separate context constructor in each switch ? Moving it outside of switch should not be a problem and will be more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

EnsureTrace takes op as an argument; the only other option would be adding a wrapper, but it would also add ~2 lines

It further decouples traceutil from the internal interface as now any
(OTEL or other) tracing library, which relies on context, can be used.

applyResult struct still needs to keep Trace field as "process raft
request" doesn't propagate the caller's context (nor Trace ID).

Signed-off-by: Aleksander Mistewicz <[email protected]>
@AwesomePatrol AwesomePatrol force-pushed the migration-to-otel-tracing-first-step branch from 1ec3f46 to 68968dd Compare July 8, 2025 12:50
case r.Range != nil:
op = "Range"
ar.Resp, ar.Trace, ar.Err = a.applyV3.Range(r.Range)
ctx, trace := traceutil.EnsureTrace(context.Background(), a.lg, op)
Copy link
Member

Choose a reason for hiding this comment

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

Please move context.Background() to outside of switch to encourage other branches to also use it.

case r.Range != nil:
op = "Range"
ar.Resp, ar.Trace, ar.Err = a.applyV3.Range(r.Range)
ctx, trace := traceutil.EnsureTrace(context.Background(), a.lg, op)
Copy link
Member

Choose a reason for hiding this comment

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

Calling EnsureTrace here means the calls in apply will be skipped. It means this changes names of operations and removes fields that are passed to EnsureTrace.

@github-actions
Copy link

github-actions bot commented Sep 7, 2025

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

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

Development

Successfully merging this pull request may close these issues.

3 participants