opened
sebright
username_0
This PR adds methods for getting the current TagContext and setting the TagContext in a scope.  It also adds convenience methods for creating a builder from the current tags and setting the scoped tags with a builder.

The new methods correspond to methods for working with the current span.  (There are some differences, because the TagContext doesn't need to be started, and it doesn't have a parent-child relationship.)

Tagging                                                                    | Tracing
-------------------------------------------------------------------|------------------------------------------------------
`TagContexts.getCurrentTagContext()`                   | `Tracer.getCurrentSpan()`
`TagContexts.withTagContext(TagContext tags)`    | `Tracer.withSpan(Span span)`
`TagContexts.currentBuilder()`                                | `Tracer.spanBuilder(String spanName)`
`TagContextBuilder.buildScoped()`                          | `SpanBuilder.startScopedSpan()`

Existing methods that don't use the current context:

Tagging                                                      | Tracing
--------------------------------------------------------|------------------------------------------------------
`TagContexts.emptyBuilder()` and `TagContexts.toBuilder(TagContext tags)` | `Tracer.spanBuilderWithExplicitParent(String spanName, @Nullable Span parent)`
`TagContextBuilder.build()`                        | `SpanBuilder.startSpan()`

/cc @username_1
Add methods for interacting with the current TagContext.
issue
created
adriancole
username_1
Dunno about the currentBuilder and buildScoped.. tag context doesnt have a
lifecycle like a span. Do we really need these methods? How worse would it
be if there was only a scoping method?
comment
created
sebright
username_0
@username_1 `currentBuilder` and `buildScoped` are just convenience methods.  My goal was to make it no harder to update the current TagContext than to create a new TagContext, since using the current context is the expected use case.  I wanted to shorten the code required to update tags and also make it harder to accidentally clear the existing tags.

With the convenience methods, a user can update the tags with

```java
try (Scope scope = tagContexts.currentBuilder().set(KEY, VALUE).buildScoped()) {
  ...
}
```

instead of

```java
try (Scope scope =
    tagContexts.withTagContext(
        tagContexts.toBuilder(tagContexts.getCurrentTagContext()).set(KEY, VALUE).build())) {
  ...
}
```
comment
created
adriancole
username_1
Thanks for giving an example of this. I see your point!
comment
created
sebright
username_0
Thanks!
comment