Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should Tracer#WithSpan take options? #149

Closed
iredelmeier opened this issue Sep 26, 2019 · 15 comments · Fixed by #472
Closed

Should Tracer#WithSpan take options? #149

iredelmeier opened this issue Sep 26, 2019 · 15 comments · Fixed by #472
Labels
good first issue Good for newcomers

Comments

@iredelmeier
Copy link
Member

No description provided.

@jmacd
Copy link
Contributor

jmacd commented Oct 8, 2019

I support the idea in principle, but it feels like it clutters the API too, because you'll have to write a []pkg.Option{} boilerplate to use this. I'd probably rather see calls like

return trace.WithSpan(ctx, trace.SpanName("abc").More(...).Optionals(...).Here(...), func(ctx) error {
    ...
})

@freeformz
Copy link
Contributor

@jmacd You don't have to create a slice to pass var args. WithSpan could be:

    WithSpan(
        ctx context.Context,
        operation string,
        body func(ctx context.Context) error,
        opts ...Option,
    ) error

@freeformz
Copy link
Contributor

This would also make it symmetric to NewHandler and the like.

@jmacd
Copy link
Contributor

jmacd commented Oct 10, 2019 via email

@freeformz
Copy link
Contributor

It's not great, but IMO, it is better than the odd chaining thing.

return trace.WithSpan(ctx,"op",
  func(c context.Context) error {
    ...
  },
  trace.WithMore(...),trace.WithHere(...),
)

Additionally, adding the variable options at the end is compatible with the existing signature.

@jmacd
Copy link
Contributor

jmacd commented Oct 10, 2019

It's not bad, I agree. I support this.

It's a bit of a "buried lede", where potentially most important information is a distance away from the start of the statement. I'd accompany this with a recommendation to avoid lengthy in-line func definitions when options are present.

@paivagustavo
Copy link
Member

Just throwing another idea, what if we change this a little bit and do something like:

return trace.WithSpan(ctx,"op", trace.WithMore(...),trace.WithHere(...))
	.Do(func(c context.Context) error {
			...
	})

@freeformz
Copy link
Contributor

I like that.

@jmacd
Copy link
Contributor

jmacd commented Oct 10, 2019

What happens if .Do(...) is left off, what type is returned by WithSpan?

@paivagustavo
Copy link
Member

paivagustavo commented Oct 11, 2019

Having a hard time thinking of a good name for the intermediate type returned by WithSpan.

edit: I'm not liking this ideia anymore, please ignore.

I have been thinking about the experience of using the API, would be possible to change add a .Do(...) method to the Span type? With this possible could drop WithSpan altogether (specs doesn't actually forces us to have it, or did I missed it?).

trace.StartSpan(ctx, "name", ...).Do(...) seems a very natural way of using the API.

I don't know if this is a change that may needs to go to specs?

@paivagustavo
Copy link
Member

paivagustavo commented Oct 11, 2019

I think that SpanScope maybe a good start name if are going to keep this structure.

We could create the span when the Do method is called, so if one does not call Do, nothing happens.

@freeformz
Copy link
Contributor

That is one problem with chaining in that way. As for a type name: SpanDoer (an interface), SpanFuture, SpanScope, etc.

Given that .Do may require another type I'd prefer the inline func, with trailing ...opts.

@iredelmeier
Copy link
Member Author

Any more thoughts on this? It seems like the trailing varargs is most straightforward.

@jmacd
Copy link
Contributor

jmacd commented Nov 26, 2019

🤷‍♂ Sure!

@jmacd
Copy link
Contributor

jmacd commented Jan 2, 2020

Let's go with trailing varargs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants