opentelemetry-collector icon indicating copy to clipboard operation
opentelemetry-collector copied to clipboard

[cmd/mdatagen] Add support for optional attribute

Open sincejune opened this issue 6 months ago • 5 comments

Description

Add support for optional attribute, ref: Conditional Required Attribute

Notes:

  • Add helper.tmpl for helper templates
  • Add With<AttributeName>EventAttribute and With<AttributeName>MetricAttribute for optional attributes
  • Add some helper functions in go files.

Link to tracking issue

Relevant to #12571

Testing

Updated

Documentation

Added

sincejune avatar May 09 '25 14:05 sincejune

Codecov Report

Attention: Patch coverage is 98.18182% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.31%. Comparing base (c9aaed8) to head (055c400). Report is 52 commits behind head on main.

Files with missing lines Patch % Lines
cmd/mdatagen/internal/command.go 92.30% 0 Missing and 2 partials :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13007      +/-   ##
==========================================
+ Coverage   91.29%   91.31%   +0.02%     
==========================================
  Files         509      509              
  Lines       28735    28807      +72     
==========================================
+ Hits        26233    26305      +72     
+ Misses       1988     1986       -2     
- Partials      514      516       +2     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar May 09 '25 14:05 codecov[bot]

I added some helper functions in the Go files to simplify the templates. I'd like to remove the helper functions if possible, but it doesn't seem to be easy.

sincejune avatar May 09 '25 17:05 sincejune

Can you please provide a specific use case? The whole point of the attributes defined in the metadata.yaml is to provide end-users visibility on the exact set of attribute being emitted. It's already possible to add any attributes to the generated metrics/event even without this extra API, but this should be strongly discouraged

dmitryax avatar May 12 '25 18:05 dmitryax

Can you please provide a specific use case? The whole point of the attributes defined in the metadata.yaml is to provide end-users visibility on the exact set of attribute being emitted. It's already possible to add any attributes to the generated metrics/event even without this extra API, but this should be strongly discouraged

I was working on the PR mentioned below, and I noticed that certain attributes in the events are only pushed when there is an increment in their values. Therefore, I created this PR to introduce optional attributes to address this behavior.

https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/40041/files#diff-e3b3d58b3d3a0c9d1db62068e7c47e72edcaa6409091343ce5ed0e9e48947eebR10

sincejune avatar May 13 '25 13:05 sincejune

@sincejune, thanks for clarifying, this makes sense to me. Can you please address the comment from @jinja2

dmitryax avatar May 29 '25 00:05 dmitryax

This PR was marked stale due to lack of activity. It will be closed in 14 days.

github-actions[bot] avatar Jun 25 '25 03:06 github-actions[bot]