-
Notifications
You must be signed in to change notification settings - Fork 651
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
Events should be immutable and should preserve the order in which they are set #1038
Comments
Hi there! I was interested in trying my hand at this but had a couple of questions first. When the specification says
obviously that means And when the specification says
I read that as meaning that an event could appear in the list of events after another event that had a later s._add_event(Event('a', timestamp=1))
s._add_event(Event('b', timestamp=3))
s._add_event(Event('c', timestamp=2))
list(s.events)
>>> [Event('a', timestamp=1), Event('b', timestamp=3), Event('c', timestamp=2)] Is that correct or would we expect |
I believe so.
I believe the former. |
Ok, maybe recursively transforming If |
You can do something similar to this or simply use nested tuples. I don't think you can override I believe your second question is correct, only about immutability if order is already preserved. |
I just want to make sure we want to go this far into the internals. As the code stands right now something like this will fail: with self.tracer.start_as_current_span("root") as root:
root.add_event("event0")
root.events[0].name = "event1"
>>> AttributeError: can't set attribute This is because we already wrap most of the properties of What I do think still needs to be addressed is something like this: with self.tracer.start_as_current_span("root") as root:
root.add_event("event0", {"name": ["birthday"]})
root.events[0].attributes["name"][0] = "hello" # Fails because `root.events[0].attributes["name"]` is a tuple
root.events[0].attributes["name"] = "hello" # Succeeds because `root.events[0].attributes` is a dict You can assign this issue to me and I can work on that specific example of editing the contents of |
I think we would still want to prevent users from modifying the dict elements like in |
This PR makes it more difficult for someone to edit the attributes of an `Event` once it has been added to a `Span`, as well as adding some regression tests around the other properties of an `Event` to ensure they have similar protections. It isn't particularly straightforward or idiomatic to make objects truly immutable in Python, but if these steps don't go far enough let me know! Fixes open-telemetry#1038
https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#add-events
The text was updated successfully, but these errors were encountered: