Skip to content

unexpected print statement from ConsoleMetricExporter #3198

@codeboten

Description

@codeboten

Describe your environment
I was writing an example application and forgot to set the meter provider. Running the code resulted in output bring printed, which led me in a rabbit hole of trying to figure out why my metrics weren't being produced, when in fact I'd missed the important step of using the MeterProvider.

Note this behaviour is different from the ConsoleSpanExporter which doesn't print any output if it's not used.

Steps to reproduce
Run the following code:

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

reader = PeriodicExportingMetricReader(ConsoleMetricExporter())
provider = MeterProvider(metric_readers=[reader])

What is the expected behavior?
Since I did not configure or use the provider in anyway, I was expecting not to see anything.

What is the actual behavior?

The following printed:

{"resource_metrics": [{"resource": {"attributes": {"telemetry.sdk.language": "python", "telemetry.sdk.name": "opentelemetry", "telemetry.sdk.version": "1.17.0.dev0", "service.name": "unknown_service"}, "schema_url": ""}, "scope_metrics": [], "schema_url": ""}]}

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions