-
Notifications
You must be signed in to change notification settings - Fork 836
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 type #72
Closed
danielkhan
wants to merge
3
commits into
open-telemetry:master
from
danielkhan:danielkhan-add-span-data
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* Copyright 2019, OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { SpanContext } from './span_context'; | ||
import { Resource } from '../resources/Resource'; | ||
import { SpanKind } from './span_kind'; | ||
import { Attributes } from './attributes'; | ||
import { Link } from './link'; | ||
import { Status } from './status'; | ||
|
||
/** | ||
* SpanData an object that is used to report out-of-band completed spans. | ||
* The object and its members have to be treated as immutable. | ||
*/ | ||
export interface SpanData { | ||
/** | ||
* Returns the name of this SpanData. | ||
*/ | ||
getName(): string; | ||
|
||
/** | ||
* Returns the SpanKind of this SpanData. | ||
*/ | ||
getKind(): SpanKind; | ||
|
||
/** | ||
* Returns the start timestamp of this SpanData. | ||
*/ | ||
getStartTimestamp(): number; | ||
|
||
/** | ||
* Returns the end timestamp of this SpanData. | ||
*/ | ||
getEndTimestamp: number; | ||
|
||
/** | ||
* Returns the SpanContext associated with this SpanData. | ||
*/ | ||
getContext(): SpanContext; | ||
|
||
/** | ||
* Returns the SpanId of the parent of this SpanData. | ||
*/ | ||
getParentSpanId(): string; | ||
|
||
/** | ||
* Returns the Resource associated with this SpanData. | ||
* When null is returned the assumption is that Resource | ||
* will be taken from the Tracer that is used to record this SpanData. | ||
*/ | ||
getResource(): Resource; | ||
|
||
/** | ||
* Returns the Attributes collection associated with this SpanData. | ||
* The order of attributes in this collection is not significant. | ||
* This collection MUST be immutable. | ||
*/ | ||
getAttributes(): Attributes; | ||
|
||
/** | ||
* Return the collection of Events with the timestamps associated with this SpanData. | ||
* The order of events in collection is not guaranteed. | ||
* This collection MUST be immutable. | ||
* | ||
* @todo: Add Event type | ||
*/ | ||
getTimedEvents(): unknown[]; | ||
|
||
/** | ||
* Returns the Links collection associated with this SpanData. | ||
* The order of links in this collection is not significant. | ||
* This collection MUST be immutable. | ||
*/ | ||
getLinks(): Link[]; | ||
|
||
/** | ||
* Returns the Status of this SpanData. | ||
*/ | ||
getStatus(): Status; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would you think about having this just be a structural object type, so something like
The advantage of a structural type is that you can easily create it and it also doesn't take extra JS code for the methods that would be added to the JS bundles (especially relevant for browsers)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@draffensperger I did it like that because SpanData MUST be immutable.
So modeling it this way in TypeScript made sense to me.
But I am not a TypeScript wizard and I can also imagine simply using
readonly
for the properties. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the motivation for making SpanData immutable? My understanding is that is important for multi-threaded languages like Java/Go (looking at Concurrency and Thread-Safety of OpenTelemetry API).
However, in Node and the browser, due to the evented model, it's not actually possible for two threads to modify the same object, so the concerns about immutability for the sake of thread safety don't apply. (Multiple threads can mutate a SharedArrayBuffer, but that's a low level type, whereas objects get cloned when passed between say the browser UI thread and a WebWorker).
Would there be another reason for making this immutable besides thread safety?
Having the types be
readonly
is a nice way to document and enforce immutability if all consumers of the API used TypeScript, but for plain JS users of the API, thereadonly
just gets compiled away. So I agree that having getter methods or evenget
property accessors is the way to go if we need immutability.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpanData is used to report out-of-band spans. The spec emphasizes the immutability of the members and also the members' contents if they are compound types.
Example:
SpanData is passed into the tracer.
Now let's assume that this is not immediately passed to the exporter but buffered somewhere.
If someone starts to modify the object itself after it has been passed to the tracer - like setting new links or another resource or just changing SpanKind - the exported Span would be different from what has been passed to the tracer in the first place because of pass-by-reference.
Or let's say that
links
orcontext
is changed somewhere else while the Span has not yet been exported.The spec demands to make sure that this must not happen.
To tackle compounds, we might even need to clone the objects.
This is also emphasized in the spec.
This is why I kept the immutability rule to make sure that implementors are fully aware of that.
This may be a fallacy - I'm open for discussions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining more of how this would be used! Makes sense on immutability making it more clear that you can't modify it after passing to the tracer, and that it keeps consistency with other languages.
I still have some lingering feelings of wishing this could just be a structure, but I think I can put those to rest particularly if others like this design. I also just learned about Object.freeze, and wonder if that could help us in some way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpanData
is specified here.I need
SpanData
inTracer
as specified here.Here is the discussion and Sergeys reasons to keep it like that for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpanData
andLocalContext
are 2 different things.SpanData
is used only for exporters, whileLocalContext
is to be used within the tracer.I strongly disagree with this design. It's a prime example of over-engineering. In its current state, it also doesn't provide a way to access the
LocalContext
, so how can vendor-specific properties be retrieved? Having only a singleSpanContext
to hold everything would be much simpler and easier to work with, both for vendors and for users. Especially since the 3 classes will basically hold the same kind of information and return them in different ways, which is unnecessary and confusing.As @draffensperger mentioned, the main goals of immutability are specific to threaded languages, and there are no reasons to block the user from modifying the object in JavaScript if they want to do it. Immutability must be a hint and not enforced or it could block certain use cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpanData
is passed to the tracer and it's part of the spec as is immutability.Further above I describe how mutation can lead to unexpected results and this has nothing to do with thread safety.
I think all these API design discussions should be done within the specification SIG.
I don't find it efficient to discuss that again for every language and platform.
I don't mind implementation details. The only strong opinion I have is that if there is a spec we should stick to it or request a change if we disagree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with a restrictive spec is that it cannot work cross-language. The spec should only describe concepts and a loose reference API. Since the current iteration is only for Java, we should experiment with an API that works better for JavaScript and then we'll be able to change the spec accordingly.
Also, an API that is 100% theoretical never works. We need to prove that it works, similar to the current Java work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can also prevent vendors to do certain things that they need. I think the idea is that APM vendors will be able to use the project implementation. If we end up needing to reimplement everything because of limitations that were added on purpose, then the value of OpenTelemetry becomes null. We can document that this should not be changed at a certain point in the lifecycle (mostly for users), but it should not be completely blocked.