Opentelemetry collector to grafanacloud (prometheus) - targetInfo metric

we are pushing metrics to grafana cloud using opentelemetry collector, and application are using javaagent (auto instrumentation) this is regarding deployement.environment resource attribute which ended up in the target_info metric and how to join http_server_duration_milliseconds_count metric with target_info metric for environment based dashboard

Hi! To avoid joining queries with target_info I would recommend using a transform processor in the collector to add the deployment.environment attribute to the Prometheus metrics as a label (deployment_environment):

transform/add_resource_attributes_as_metric_attributes:
  error_mode: ignore
  metric_statements:
    - context: datapoint
       statements:
         - set(attributes["deployment.environment"], resource.attributes["deployment.environment"])
...
service:
  pipelines:
    metrics:
      receivers: [otlp]
      processors: [transform/add_resource_attributes_as_metric_attributes]
      exporters: [prometheusremotewrite]

thanks for solution, but when i use as it is, collector not starting… can you please point me to full configuration file (/etc/otelcol-contrib/config.yaml)

never mind it is working with following configuration

transform:
  error_mode: ignore
  metric_statements:
    - context: datapoint
       statements:
         - set(attributes["deployment.environment"], resource.attributes["deployment.environment"])

...
service:
  pipelines:
    metrics:
      receivers: [otlp]
      processors: [transform]
      exporters: [prometheusremotewrite]
1 Like

Did you get an answer? I am facing the same problem on my project, if you find the solution please share here.