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

Exception while exporting metrics 'MetricsData' object has no attribute 'to_json' #2716

Closed
ebarti opened this issue May 25, 2022 · 2 comments · Fixed by #2722
Closed

Exception while exporting metrics 'MetricsData' object has no attribute 'to_json' #2716

ebarti opened this issue May 25, 2022 · 2 comments · Fixed by #2722
Assignees
Labels
bug Something isn't working metrics

Comments

@ebarti
Copy link

ebarti commented May 25, 2022

Describe your environment

Python 3.10. Docker compose.

opentelemetry-sdk = "1.12.0rc1"
opentelemetry-exporter-otlp = "1.12.0rc1"
opentelemetry-exporter-otlp-proto-grpc = "1.12.0rc1"

Steps to reproduce

Just following the getting started example...

from opentelemetry import metrics
from opentelemetry.metrics import (
     Counter,
)
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader, ConsoleMetricExporter

exporter = ConsoleMetricExporter()
reader = PeriodicExportingMetricReader(exporter)
provider = MeterProvider(metric_readers=[reader])
metrics.set_meter_provider(provider)
meter = metrics.get_meter(__name__)
counter = meter.create_counter("test")
counter.add(1)

What is the expected behavior?
Metrics printed to console

What is the actual behavior?

Traceback (most recent call last):
   File "/usr/local/lib/python3.10/site-packages/opentelemetry/sdk/metrics/_internal/export/__init__.py", line 404, in _receive_metrics
     self._exporter.export(metrics_data, timeout_millis=timeout_millis)
   File "/usr/local/lib/python3.10/site-packages/opentelemetry/sdk/metrics/_internal/export/__init__.py", line 121, in export
     self.out.write(self.formatter(metrics_data))
   File "/usr/local/lib/python3.10/site-packages/opentelemetry/sdk/metrics/_internal/export/__init__.py", line 109, in <lambda>
     ] = lambda metric: metric.to_json()
 AttributeError: 'MetricsData' object has no attribute 'to_json'
 Exception while exporting metrics 'MetricsData' object has no attribute 'to_json'

Additional context
Add any other context about the problem here.

@ebarti ebarti added the bug Something isn't working label May 25, 2022
@ebarti
Copy link
Author

ebarti commented May 25, 2022

Fixed it by downgrading to 1.11 😅

@ebarti ebarti closed this as completed May 25, 2022
@srikanthccv
Copy link
Member

It's still a bug If it breaks on 1.12.0rc1.

@srikanthccv srikanthccv reopened this May 25, 2022
@ocelotl ocelotl self-assigned this May 26, 2022
ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue May 26, 2022
ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue May 26, 2022
ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue May 26, 2022
ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue Jun 3, 2022
ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue Jun 8, 2022
ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue Jun 8, 2022
ocelotl added a commit that referenced this issue Jun 8, 2022
* Add missing to_json methods

Fixes #2716

* Added resource to_json method

* Rename to metrics data

* Add to_json to Instrumentation Scope as well

Fixes #2716
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working metrics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants