I am having little trouble with getting service.name exported with prometheus. These are my JVM opts
:jvm-opts ["-javaagent:grafana-opentelemetry-java.jar"
"-Dotel.resource.attributes=service.name=dev-webserver"
"-Dotel.metrics.exporter=prometheus"
"-Dotel.metric.export.interval=5000"
"-Dotel.logs.exporter=none"
"-Dotel.traces.exporter=none"
]
agent is started and i do have metrics: http://localhost:9464/metrics
problem is that they are missing important label like service name
jvm_class_count{otel_scope_name="io.opentelemetry.runtime-telemetry-java8",otel_scope_version="2.4.0-alpha"} 37413.0
If i do collector setup - autoconfigure + default exporter (basically removed everything except service.name from jvm opts) i get this exported
jvm_class_count{exported_instance="adbb4085-ef54-4823-be3c-3747ba027012", exported_job="cube-app", instance="otel-collector:9464", job="otel-collector"}
Having exported_jobs is a must
edit
this seems to be prometheus config and related to relabeling.
resource_to_telemetry_conversion might also be helpfulThe OpenTelemetry Prometheus exporters map telemetry data to Prometheus format. This (among other changes) means that service.name (an OpenTelemetry semantic attribute) is mapped to job or exported_job label depending on which exporter is used.
Right at this moment I am designing Grafana dashboards for the clj-otel microservice examples. The PromQL queries I'm using include selecting by job label:
histogram_quantile(0.9, sum(rate(http_server_request_duration_seconds_bucket{job="sentence-summary-service"}[$__rate_interval])) by (le))Is job label visible when you do do GET on localhost:9464/metrics?
I haven't found any need to remap attributes or map resource attributes to additional labels on the exported telemetry.
I'm using the prometheusremotewrite (push) exporter, and job label is present on the exported telemetry.
Alright thanks for clarifications.
I was looking at this wrong then expecting that /metrics should have that label or all of the agent's metrics should have the service-name if i add it.
My local prometheus isn't including the job to the agent metrics
For the prometheus (pull) exporter, you may need to add a label containing resource information, as you say.
resource_to_telemetry_conversion adds all the resource attributes as labels to the exported telemetry. For more fine-tuned control, you could consider using the contrib OpenTelemetry instrumentation agent collector (this is a super-charged version of the agent collector with extra knobs) to add only the labels you need : https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/exporter/prometheusexporter/README.md
(the transform processor is in contrib, but not the core distribution of the agent).
I haven't tried this myself, so do let us know if you go down this route!