dynatrace-oss / opentelemetry-metric-python

Dynatrace OpenTelemetry Metrics Exporter for Python
https://www.dynatrace.com/integrations/opentelemetry/
Apache License 2.0
13 stars 6 forks source link

Convert attribute values to string automatically. #34

Closed RangelReale closed 8 months ago

RangelReale commented 1 year ago

Is your feature request related to a problem? Please describe. I'm getting this error message on each of my metrics: Skipping unsupported dimension with value type 'int'. This seems to be because only string dimension values are supported, but I'm using cloud resource detectors, like opentelemetry-resourcedetector-gcp, and it fetches some of its attributes from a metadata url, and python converts them to int automatically, so I have no way of pre-converting it before sending to the dynatrace exporter.

Describe the solution you'd like That attribute values are automatically converted to string using str.

Describe alternatives you've considered There's no place where I can put a callback so I could convert them to string myself.

Additional context

dyladan commented 1 year ago

You're correct that this is because only strings are supported. If you want to use non-string attributes you will need to convert them to string first. In the case of a resource detector you could for example create a wrapper around the resource detector which converts all attribute values to string. Something like the following:

class StringConversionResourceDetector(ResourceDetector):
    def __init__(self, detector, raise_on_error=False):
        super().__init__(raise_on_error)
        self.detector = detector

    def detect(self) -> "Resource":
        resource = self.detector.detect(self)
        # convert resources to string here
        for key in resource.attributes:
            resource.attributes[key] = str(resource.attributes[key])
        return resource
RangelReale commented 1 year ago

Looking at the AttributeLabel type, it openly states that other types besides str are allowed for attribute values, shouldn't this be the responsibility of the library that uses it to convert if it doesn't support the other types?

I can submit a PR if it is ok with you.

arminru commented 8 months ago

Hi @RangelReale!

In 2022, we introduced an OTLP Metrics ingest endpoint in Dynatrace, which makes this exporter here obsolete, as any OTel SDK and the collector can natively export to it out of the box.

You can find more details here:

The int->string attribute conversion you've requested here was implemented in the OTLP metrics ingest endpoint, so you could upgrade to that one instead.

This exporter is deprecated in favor of the OTLP metrics ingest and as such no new features will be implemented.