Skip to content
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

Metric attributes with wrong value types fail badly #782

Open
alexmojaki opened this issue Jan 7, 2025 · 0 comments
Open

Metric attributes with wrong value types fail badly #782

alexmojaki opened this issue Jan 7, 2025 · 0 comments

Comments

@alexmojaki
Copy link
Contributor

import logfire

logfire.configure()

counter = logfire.metric_counter('my_counter')
counter.add(1, {'k': object()})

logs:

Failed to encode key k: Invalid type <class 'object'> of value <object object at 0x10864d320>
Traceback (most recent call last):
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py", line 113, in _encode_attributes
    pb2_attributes.append(_encode_key_value(key, value))
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py", line 94, in _encode_key_value
    return PB2KeyValue(key=key, value=_encode_value(value))
                                      ^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py", line 90, in _encode_value
    raise Exception(f"Invalid type {type(value)} of value {value}")
Exception: Invalid type <class 'object'> of value <object object at 0x10864d320>

This happens in the PeriodicExportingMetricReader thread and gives no way for the user to know the original offending code.

We should report this to OTEL if it isn't already and also decide what we want to do about it ourselves. I'm leaning towards warning the user and dropping the attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant