GoogleCloudPlatform / opentelemetry-operations-python

OpenTelemetry Python exporters for Google Cloud Monitoring and Trace
https://google-cloud-opentelemetry.readthedocs.io/en/stable/
Apache License 2.0
64 stars 45 forks source link

Support explicit monitored resource for Metrics #299

Open daniel-sanche opened 1 year ago

daniel-sanche commented 1 year ago

This PR adds the option to pass in a MonitoredResource object when creating an exporter instance, which is then used for all export calls. If not passed, it will fallback to the current behavior of parsing a resource out of the Otel Resource object

The main intention is to allow users to pass in additional monitored_resource types, but it also has performance benefits, using a cached object instead of re-constructing it from scratch for each metric.

It may also make sense to make changes to gcp_resource_detector.get_monitored_resource to parse arbitrary monitored resource types out of the Otel Resource, but I left that off for now for simplicity.

If this change seems reasonable, I can add tests

Fixes https://github.com/GoogleCloudPlatform/opentelemetry-operations-python/issues/298