Skip to content

Add a thin wrapper around otel Span object#7655

Merged
fuweid merged 1 commit intocontainerd:mainfrom
swagatbora90:tracing-refactor
Nov 11, 2022
Merged

Add a thin wrapper around otel Span object#7655
fuweid merged 1 commit intocontainerd:mainfrom
swagatbora90:tracing-refactor

Conversation

@swagatbora90
Copy link
Copy Markdown
Contributor

Follow up to the one of the comments in #7453 (comment)

This PR wraps the otel Span object and implements related methods which is used during tracing instrumentation.

Also, adds a new SpanName method as discussed in https://github.com/containerd/containerd to add a common seaprator in span names /pull/7453#discussion_r1012469550

Signed-off-by: Swagat Bora [email protected]

@k8s-ci-robot
Copy link
Copy Markdown

Hi @swagatbora90. Thanks for your PR.

I'm waiting for a containerd 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.

Details

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/test-infra repository.

@swagatbora90
Copy link
Copy Markdown
Contributor Author

/cc @mxpv

@k8s-ci-robot k8s-ci-robot requested a review from mxpv November 10, 2022 23:26
Comment thread tracing/tracing.go
// StartSpan starts child span in a context.
func StartSpan(ctx context.Context, opName string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
// StartSan starts child span in a context.
func StartSpan(ctx context.Context, opName string, opts ...trace.SpanStartOption) (context.Context, *Span) {
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.

I thought we could have tracing.Span(ctx, prefix, name) but then it cannot take SpanStartOption...

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.

You are right Kaz. We can have a separate methods that pass either StartSpanOption or names. I am not sure if this is something we want.

Copy link
Copy Markdown
Member

@mxpv mxpv left a comment

Choose a reason for hiding this comment

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

This is great! I have a few nit suggestions.

Comment thread pkg/unpack/unpacker.go Outdated
)
return images.HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
ctx, span := tracing.StartSpan(ctx, "pkg.unpack.unpacker.UnpackHandler")
ctx, span := tracing.StartSpan(ctx, tracing.SpanName(unpackSpanPrefix, "UnpackHandler"))
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.

Do we need both StartSpan and SpanName ?

I'd suggest

ctx, span := tracing.StartSpan(ctx, unpackSpanPrefix, "UnpackHandler")

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.

tracing.StartSpan already accepts SpanStartOption...

func StartSpan(ctx context.Context, opName string, opts ...trace.SpanStartOption) (context.Context, *Span)

so I had to use tracing.SpanName to pass the list of strings to create the span name.

The other options were to use interface{} and infer the type later, or create a new method that accepts StartSpan(ctx, name ...string) but then it cannot take SpanStartOption...

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.

Oh, ok, that make sense.
In this case I'd suggest tracing.Name instead of tracing.SpanName to keep it more laconic.

Comment thread pkg/unpack/unpacker.go Outdated

for i, desc := range layers {
_, layerSpan := tracing.StartSpan(ctx, "pkg.unpack.unpacker.unpackLayer")
_, layerSpan := tracing.StartSpan(ctx, tracing.SpanName(unpackSpanPrefix, "unpackLayer"))
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.

Too many "spans", possibly:

layerSpan.SetAttributes(
    tracing.Attribute("layer.media.type", desc.MediaType),
    tracing.Attribute("layer.media.size", desc.Size),
    tracing.Attribute("layer.media.digest", desc.Digest.String()),
)

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.

Yes, this will track unpacking of each layer and create one span for each. This was added in response to #7453 (comment)

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.

What I mean here is whether we could rename tracing.SpanAttribute to tracing.Attribute

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.

Ahh I see. I have changed SpanAttribute to Attribute.

Copy link
Copy Markdown
Member

@mxpv mxpv left a comment

Choose a reason for hiding this comment

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

LGTM

@fuweid fuweid merged commit 669230c into containerd:main Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants