Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include resource attributes as target_info for Prometheus exporters #5407

Merged

Conversation

robertcoltheart
Copy link
Contributor

@robertcoltheart robertcoltheart commented Mar 2, 2024

Fixes #3087

Changes

Adds a target_info section to the Prometheus output.

target_info is only displayed for clients using the Accept: application/openmetrics-text header, since Prometheus will break on reading info types with servers that don't send the Content-Type: application/openmetrics-text header.

Example output that shows target_info with resource attributes:

# TYPE target info
# HELP target Target metadata
target_info{deployment_environment="Production",service_name="otel-test",service_version="1.0.0.0",service_instance_id="GLIP",telemetry_sdk_name="opentelemetry",telemetry_sdk_language="dotnet",telemetry_sdk_version="0.0.0-alpha.0.2851"} 1
# TYPE otel_scope_info info
# HELP otel_scope_info Scope metadata
otel_scope_info{otel_scope_name="Microsoft.AspNetCore.Server.Kestrel"} 1
# TYPE kestrel_active_connections gauge
# HELP kestrel_active_connections Number of connections that are currently active on the server.
kestrel_active_connections{otel_scope_name="Microsoft.AspNetCore.Server.Kestrel",network_transport="tcp",network_type="ipv6",server_address="::1",server_port="5000"} 1 1709377047.805
kestrel_active_connections{otel_scope_name="Microsoft.AspNetCore.Server.Kestrel",network_transport="tcp",network_type="ipv4",server_address="127.0.0.1",server_port="5000"} 1 1709377047.805
# EOF

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

Copy link

codecov bot commented Mar 2, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 85.57%. Comparing base (6250307) to head (317ce4c).
Report is 138 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5407      +/-   ##
==========================================
+ Coverage   83.38%   85.57%   +2.19%     
==========================================
  Files         297      289       -8     
  Lines       12531    12640     +109     
==========================================
+ Hits        10449    10817     +368     
+ Misses       2082     1823     -259     
Flag Coverage Δ
unittests ?
unittests-Solution-Stable 84.96% <83.33%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...etheus.HttpListener/Internal/PrometheusExporter.cs 100.00% <100.00%> (ø)
...heus.HttpListener/Internal/PrometheusSerializer.cs 85.79% <94.11%> (+0.93%) ⬆️
...tpListener/Internal/PrometheusCollectionManager.cs 76.37% <66.66%> (-1.40%) ⬇️

... and 64 files with indirect coverage changes

@robertcoltheart robertcoltheart marked this pull request as ready for review March 2, 2024 11:05
@robertcoltheart robertcoltheart requested a review from a team as a code owner March 2, 2024 11:05
@vishweshbankwar
Copy link
Member

@robertcoltheart Could you split the PR in to two parts?

  1. Add target_info metric.
  2. Ability to add resource attribute to individual metrics.

It will help in reviewing the PR and separating public API addition from an internal change. Thanks!

@robertcoltheart robertcoltheart changed the title Include resource attributes as metrics tags Include resource attributes as target_info for Prometheus exporters Mar 6, 2024
@robertcoltheart
Copy link
Contributor Author

Thanks @vishweshbankwar, updated per recommendations. Will raise the 2nd PR once this is merged.

@robertcoltheart
Copy link
Contributor Author

I've added caching for target_info, this should be good to go now

@cijothomas
Copy link
Member

telemetry_sdk_version="0.0.0-alpha.0.2851

how come! 🤣 we didn't have prometheus exporter that far !

@robertcoltheart
Copy link
Contributor Author

telemetry_sdk_version="0.0.0-alpha.0.2851

how come! 🤣 we didn't have prometheus exporter that far !

Lol yeah I'm guessing this was because I was running it locally? Not sure where the version number is coming from.

@utpilla utpilla merged commit 0969437 into open-telemetry:main Mar 21, 2024
31 checks passed
@robertcoltheart robertcoltheart deleted the feature/resource-attribute-tags branch March 22, 2024 08:37
@CodeBlanch CodeBlanch added the pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package label Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Metrics Exporters: Include Resource Data in Labels
5 participants