-
Notifications
You must be signed in to change notification settings - Fork 850
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
Add SpanData.Builder to allow modifying the information in a SpanData… #1502
Conversation
…, for example in an Exporter.
…uld include the SDK.
Codecov Report
@@ Coverage Diff @@
## master #1502 +/- ##
============================================
- Coverage 92.33% 91.82% -0.52%
- Complexity 951 956 +5
============================================
Files 117 117
Lines 3380 3413 +33
Branches 281 302 +21
============================================
+ Hits 3121 3134 +13
- Misses 172 173 +1
- Partials 87 106 +19
Continue to review full report at Codecov.
|
/cc @iNikem |
Yeah, I saw it, but was yet unable to formulate my feedback :) I feel like I don't like it, but cannot give anything constructive yet. Will ponder it more. |
One of the bummers with this approach is that every time you want to modify the SpanData, you end up copying all of it, even if all you care about it modifying one particular field. If you had a abstract wrapper class, you could, in your constructor, alter or augment only the pieces that you cared about, keeping the delegate implementation in place for all other fields, potentially saving a lot of allocation overhead. |
@jkwatson Could you? How can you alter or augment |
You could read them (they are Readable, after all), and create your own Attributes to return, based on them, with some kind of augmentation. Maybe I'm missing the confusion? |
It sounds like people want to see the wrapper approach as well so will send a PR for comparison :) |
I think that my brain refuses to think about a solution which involves iterating over attributes and copying them one by one into new attributes instance :) |
@iNikem Yep attributes are copied, if we find this to be a significant performance issue we'd need to add |
Wait, I have read https://github.com/google/auto/blob/master/value/userguide/builders-howto.md#to_builder and think we have overcomplicated things. What if we make Then the only question that will remain is how to add new attributes. If we make |
@iNikem I'd have to try to be sure, but I'm not expecting AutoValue's Builder to work in this case. There's only one AutoValue implementation , It also only partly solves the copying allocation issue that @jkwatson refers to I think #1502 (comment) I think you can see when comparing to #1507 |
I don't understand this part. There is already Here is my attempt
|
@iNikem Apologies, status was a bad example. |
Yes, only subset of |
I think the delegation of Also, FWIW I have mutated the trace ID before in an exporter It's not a normal use case at all but helped a lot and I was glad it was allowed. If we're giving a user the ability to mutate a |
So instead of digging too much into AutoValue, let's not be constrained by it, if there's general direction on an API I'll try to clean up duplication, etc that I can. AFAICT the proposed APIs right now are And open to other ideas too :) |
I guess after seeing both implementations, my original thoughts still stand. Anyone who want to modify the SpanData that is handed to them can do it in whatever way makes sense for them. Our providing a wrapper, or a builder, or whatever doesn't add a huge value in the general case. It sounds like @iNikem is more concerned with the overall immutability that we've built into the our data structures, that we've done explicitly to enable performance optimizations. |
@jkwatson do you propose that every "anyone" who wants to do that should create their own implementation of |
If all you want is a simple wrapper, it seems reasonable to wait until we have one implementation in the real world before we preemptively put it into the SDK itself as something official. If this is needed in the instrumentation project, how about starting by creating it there, and getting all the kinks worked out, and then consider moving it into the official SDK? |
Yeah, I suppose I will go this way :( |
They seem fairly general to me (at least full builder or delegator) - they make it very simple to modify just a small part of I don't mind the idea of developing it in instrumentation repo, but a couple points I want to bring up are
Actually I'm more happy of trying to solve the second point in this PR than even the first :P Which is a reason I slightly favor this one over #1507. @jkwatson Let me know if you have any thoughts on these points, especially what to do with |
I 100% agree that |
So extracted the point that had concensus into #1512 :) I do still think we should add something since maintaining a wrapper is hard for a user if we add methods to the |
I am interested in this whole discussion because I have to make a POC Splunk specific distribution where I want to add some attributes. So any solution that will allow me to do that is good for me atm. Including me following John advice and just writing it myself in my own codebase :) |
…, for example in an Exporter.
This is an approach that adds
toBuilder
toSpanData
instead of exposing aDelegatingSpanData
wrapper since it seemed to have some more votes. I found we actually already have a similar class,TestSpanData
, only for tests. So I made that explicit by movingTestSpanData
to a separate testing module instead of in our codebase and just delegate to a newly restoredSpanDataImpl
in tests.A lot of the pain in this approach comes from supporting both the types of
SpanData
, one that delegates to the span and one that contains all the information after mutation. I was sad that I couldn't seem to find a way to haveAutoValue
generate equals for me in a way that supports the base interface, meaning this is almost as much maintainance burden as a wrapper class (where I would have to define equals and hashCode in code).Let me know if you have thoughts, I can also send a version using the delegating pattern if it seems to have merit. Other options are to add some benchmarks of
Span.toSpanData
that use the delegating vs just copying everything and if there's only a small difference, we could consolidate on one.Fixes #1321