open-telemetry / opentelemetry-python

OpenTelemetry Python API and SDK
https://opentelemetry.io
Apache License 2.0
1.74k stars 610 forks source link

The preferred_temporality.py and preferred_aggregation.py sample code doesn't work #3125

Closed R-M-F-at-C-A closed 1 year ago

R-M-F-at-C-A commented 1 year ago

Describe your environment

Ubuntu, Python 3.9.10
opentelemetry-api 1.12.0
opentelemetry-sdk 1.12.0
opentelemetry-semantic-conventions-0.33b0

success case:

opentelemetry-api-1.15.0
opentelemetry-sdk-1.15.0
opentelemetry-semantic-conventions-0.36b0

Steps to reproduce

mkdir otel-reader-examples
cd otel-reader-examples
cp ../opentelemetry-python/docs/examples/metrics/reader/* .
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python preferred_aggregation.py

What is the expected behavior?

{"resource_metrics": [{"resource": {"attributes": {"telemetry.sdk.language": "python", "telemetry.sdk.name": "opentelemetry", "telemetry.sdk.version": "1.15.0", "service.name": "unknown_service"}, "schema_url": ""}, "scope_metrics": [{"scope": {"name": "preferred-aggregation", "version": "0.1.2", "schema_url": ""}, "metrics": [{"name": "my-counter", "description": "", "unit": "", "data": {"data_points": [{"attributes": {}, "start_time_unix_nano": 0, "time_unix_nano": 1673457057728324588, "value": 2}]}}], "schema_url": ""}], "schema_url": ""}]}
{"resource_metrics": [{"resource": {"attributes": {"telemetry.sdk.language": "python", "telemetry.sdk.name": "opentelemetry", "telemetry.sdk.version": "1.15.0", "service.name": "unknown_service"}, "schema_url": ""}, "scope_metrics": [{"scope": {"name": "preferred-aggregation", "version": "0.1.2", "schema_url": ""}, "metrics": [{"name": "my-counter", "description": "", "unit": "", "data": {"data_points": [{"attributes": {}, "start_time_unix_nano": 0, "time_unix_nano": 1673457062780390227, "value": 5}]}}], "schema_url": ""}], "schema_url": ""}]}
{"resource_metrics": [{"resource": {"attributes": {"telemetry.sdk.language": "python", "telemetry.sdk.name": "opentelemetry", "telemetry.sdk.version": "1.15.0", "service.name": "unknown_service"}, "schema_url": ""}, "scope_metrics": [{"scope": {"name": "preferred-aggregation", "version": "0.1.2", "schema_url": ""}, "metrics": [{"name": "my-counter", "description": "", "unit": "", "data": {"data_points": [{"attributes": {}, "start_time_unix_nano": 0, "time_unix_nano": 1673457067784526426, "value": 7}]}}], "schema_url": ""}], "schema_url": ""}]}
{"resource_metrics": [{"resource": {"attributes": {"telemetry.sdk.language": "python", "telemetry.sdk.name": "opentelemetry", "telemetry.sdk.version": "1.15.0", "service.name": "unknown_service"}, "schema_url": ""}, "scope_metrics": [{"scope": {"name": "preferred-aggregation", "version": "0.1.2", "schema_url": ""}, "metrics": [{"name": "my-counter", "description": "", "unit": "", "data": {"data_points": [{"attributes": {}, "start_time_unix_nano": 0, "time_unix_nano": 1673457072748357770, "value": 9}]}}], "schema_url": ""}], "schema_url": ""}]}

What is the actual behavior? Traceback (most recent call last): File "/home/richardf/prog/otel-reader-examples/preferred_aggregation.py", line 28, in exporter = ConsoleMetricExporter( TypeError: init() got an unexpected keyword argument 'preferred_aggregation'

Additional context This is the behaviour reported in #2910 and putatively fixed in #2911

The issue seems to be that the requirements.txt installs the versions of the software before the fix. Changing requirements.txt to:

Deprecated==1.2.13
opentelemetry-api==1.15.0
opentelemetry-sdk==1.15.0
typing_extensions==4.3.0
wrapt==1.14.1

resolved the issue for me, there's probably a smarter way to do this. Ideally there would be pipeline tests to ensure the examples run.

R-M-F-at-C-A commented 1 year ago

Thank you Leighton!