Fix #3695: add attributes to get_meter fn and InstrumentationScope
Description
Fixes #3695 (issue)
Type of change
Please delete options that are not relevant.
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
How Has This Been Tested?
Added unit tests for the get_meter fn call, also included the attributes where instrumentationScope is being called
Does This PR Require a Contrib Repo Change?
- [ ] Yes. - Link to PR:
- [x] No.
Checklist:
- [x] Followed the style guidelines of this project
- [x] Changelogs have been updated
- [x] Unit tests have been added
- [ ] Documentation has been updated
The committers listed above are authorized under a signed CLA.
- :white_check_mark: login: vivek378521 / name: Vivek Khatri (5bc3820a36eea29567e6e68b26b704c6ed170e14, ea15e796db268e66dd9a468ebfae312f13a24eca, 34da3d5bedbe75bcb2ca0d1523be304e36c71049, f8fcaea0c51627d47785e0a9d1328e2ba61c866c, 815e7f31dd255da0cd9fab722fe81b724b5455fc, db349c88a57cf598d0e4c11b35269ca948a50c68, c3e33d7dded79922b2a95e6123c4d45383c48c34, 93811f718239caea9679375e1c5b32a36c3d9ffa, af158f9475bce7332d70f3460592d684a7520a6f, 74451fe894bbc5da4e3864ca36088c74108d19fc, dbe9b73d232707c0136569fe6b916b2acb1452bd, 722be3c55b3e7d0c9611b5ca43e8f6bb8dcffc1a, ef7ad085baecda0ce9f21c1d55db2e47d2e3d254, e320a9eb42905be7abf65734d5f8a9941ca28bbb, 6a4595e50a13b47f3d38c7dee76779a1f0ebc3fe)
- :white_check_mark: login: lzchen / name: Leighton Chen (402448a18277402339f31baf460f15d44adb285e, 9f9987554cc7f6eae040cb3854a7e87486f25062, e44bffe533cbe74659416dc1282e7dd20a35d15e)
@vivek378521 thanks for the PR and the quick turnaround!
Are we missing a change to the actual api ?
@lzchen I have added the field to the api (the place you pointed to in the code)
@vivek378521 could you please fix lint errors?
There was an import statement linting issue, I fixed that, ran tox -e lint 10/10. :')
@vivek378521
To fix mypy, you must add attributes field to every get_meter function of all subclasses of MeterProvider. This includes NoOpMeterProvider and ProxyMeterProvider.
@lzchen
You mean here: https://github.com/open-telemetry/opentelemetry-python/blob/e44bffe533cbe74659416dc1282e7dd20a35d15e/opentelemetry-api/src/opentelemetry/metrics/_internal/init.py#L144C9-L144C42
and here: https://github.com/open-telemetry/opentelemetry-python/blob/e44bffe533cbe74659416dc1282e7dd20a35d15e/opentelemetry-api/src/opentelemetry/metrics/_internal/init.py#L160 ?
@lzchen
You mean here: https://github.com/open-telemetry/opentelemetry-python/blob/e44bffe533cbe74659416dc1282e7dd20a35d15e/opentelemetry-api/src/opentelemetry/metrics/_internal/init.py#L144C9-L144C42
and here:
https://github.com/open-telemetry/opentelemetry-python/blob/e44bffe533cbe74659416dc1282e7dd20a35d15e/opentelemetry-api/src/opentelemetry/metrics/_internal/init.py#L160 ?
yes
So just these changes, right?
def get_meter(
self,
name: str,
version: Optional[str] = None,
schema_url: Optional[str] = None,
attributes: Optional[Attributes] = None, # here?
) -> "Meter":
"""Returns a NoOpMeter."""
return NoOpMeter(name, version=version, schema_url=schema_url)
def get_meter(
self,
name: str,
version: Optional[str] = None,
schema_url: Optional[str] = None,
attributes: Optional[Attributes] = None, # here?
) -> "Meter":
with self._lock:
if self._real_meter_provider is not None:
return self._real_meter_provider.get_meter(
name, version, schema_url
)
meter = _ProxyMeter(name, version=version, schema_url=schema_url)
self._meters.append(meter)
return meter
yay, all checks passed! 🥳