Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
@ebarti

Description

@ebarti

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingmetrics

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions