-
Notifications
You must be signed in to change notification settings - Fork 705
Use extended attributes everywhere #4587
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
base: main
Are you sure you want to change the base?
Use extended attributes everywhere #4587
Conversation
@@ -180,7 +195,7 @@ class Counter(Synchronous): | |||
def add( | |||
self, | |||
amount: Union[int, float], | |||
attributes: Optional[Attributes] = None, | |||
attributes: Optional[_MetricAttributes] = None, |
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.
TODO: we can use Attributes
and let users use complex attributes on metrics without any restrictions. We can also introduce an alias for a limited attribute set.
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.
I like the idea of allowing it at runtime but blocking it at type checking time. It gives users feedback that they're doing something probably wrong but is easy to override.
...xporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py
Show resolved
Hide resolved
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.
Overall this looks pretty straightforward to me. It goes to show that there's not much of a change for the SDKs to support complex attributes.
@@ -180,7 +195,7 @@ class Counter(Synchronous): | |||
def add( | |||
self, | |||
amount: Union[int, float], | |||
attributes: Optional[Attributes] = None, | |||
attributes: Optional[_MetricAttributes] = None, |
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.
I like the idea of allowing it at runtime but blocking it at type checking time. It gives users feedback that they're doing something probably wrong but is easy to override.
root.set_attributes( | ||
{"correct-value": "foo", "non-primitive-data-type": {}} | ||
) | ||
|
||
with self.assertLogs(level=WARNING): | ||
root.set_attribute("non-primitive-data-type", {}) | ||
with self.assertLogs(level=WARNING): | ||
root.set_attribute( | ||
"list-of-mixed-data-types-numeric-first", | ||
[123, False, "string"], | ||
) | ||
with self.assertLogs(level=WARNING): | ||
root.set_attribute( | ||
"list-of-mixed-data-types-non-numeric-first", | ||
[False, 123, "string"], | ||
) | ||
with self.assertLogs(level=WARNING): | ||
root.set_attribute( | ||
"list-with-non-primitive-data-type", [{}, 123] | ||
) | ||
with self.assertLogs(level=WARNING): | ||
root.set_attribute("list-with-numeric-and-bool", [1, True]) |
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.
Maybe keep these tests but remove the assertLogs
context manager / i.e. they should pass?
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.
I like this approach, LGTM
This is a prototype of open-telemetry/opentelemetry-specification#4485:
TODO:
Benchmarks:
Perf is not a priority - we don't really want people to use complex attributes on metrics, to goal here to show that even if they do, the impact is not huge.
Based on the results, the cost of reporting complex attribute is ~1.5-2 times higher than a standard one.