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

Make macros.h available for all source files via version.h #1918

Merged
merged 4 commits into from
Jan 17, 2023

Conversation

ThomsonTan
Copy link
Contributor

Changes

As the macros defined in macros.h is general for all sources, including it in version.h to make it available for all sources (no need for separate #include "opentelemetry/common/macros.h" statement.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@ThomsonTan ThomsonTan requested a review from a team January 11, 2023 22:28
@codecov
Copy link

codecov bot commented Jan 11, 2023

Codecov Report

Merging #1918 (58f3bfc) into main (0305ad8) will not change coverage.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1918   +/-   ##
=======================================
  Coverage   86.92%   86.92%           
=======================================
  Files         165      165           
  Lines        4594     4594           
=======================================
  Hits         3993     3993           
  Misses        601      601           
Impacted Files Coverage Δ
api/include/opentelemetry/trace/trace_state.h 97.60% <ø> (ø)
...include/opentelemetry/sdk/metrics/view/predicate.h 72.73% <ø> (ø)
sdk/src/metrics/instrument_metadata_validator.cc 100.00% <ø> (ø)

Copy link
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this change will expose:

  • the cstdint header file
  • the regex headerfile
  • the HAVE_WORKING_REGEX symbol, which is not using an OPENTELEMETRY_ prefix and therefore pollutes the build

for any user of any api header file.

I would prefer to apply the include-what-you-use principles, and only include macro.h in the few places where it is needed.

The API header files are stable by now, so there is no real maintenance burden and breaks caused by missing includes on macro.h

What is the motivation or rationale for this change ?

@ThomsonTan
Copy link
Contributor Author

Making this change will expose:

  • the cstdint header file
  • the regex headerfile
  • the HAVE_WORKING_REGEX symbol, which is not using an OPENTELEMETRY_ prefix and therefore pollutes the build

for any user of any api header file.

I would prefer to apply the include-what-you-use principles, and only include macro.h in the few places where it is needed.

The API header files are stable by now, so there is no real maintenance burden and breaks caused by missing includes on macro.h

What is the motivation or rationale for this change ?

Perhaps we should remove cstdint from macro here? HAVE_WORKING_REGEX is like any definition in config.h which is fine and convenient to be included for every source file under the repo?

The intention was the make the all the generic macros in a common header file for all source files. I am adding some declspec macro for building DLL, so I'd like to avoid including it for every header (there could be many of them).

@ThomsonTan
Copy link
Contributor Author

Perhaps move #include <regex> to the source file which need it instead of putting into this generic header file?

Copy link
Member

@owent owent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with the following changes, please consider to:

  • rename HAVE_WORKING_REGEX to OPENTELEMETRY_HAVE_WORKING_REGEX, everywhere (including in the SDK)
  • only set OPENTELEMETRY_HAVE_WORKING_REGEX based on the GCC version, but do not include regex.h when setting the flag
  • include (conditionally) regex.h when using the flag
  • remove the code duplication from trace_state.h

With this, all uses should look like:

#if OPENTELEMETRY_HAVE_WORKING_REGEX
#  include <regex>
#endif

I know this is an existing issue, but cleaning it up before exposing macro.h is needed, to avoid causing side effects on user code.

No strong opinion on whether to put the code to set OPENTELEMETRY_HAVE_WORKING_REGEX in macro.h or config.h

Thanks for the fix.

@marcalff
Copy link
Member

Perhaps move #include <regex> to the source file which need it instead of putting into this generic header file?

Good idea, see my latest review comments.

@ThomsonTan ThomsonTan merged commit 59d0bc2 into open-telemetry:main Jan 17, 2023
@ThomsonTan ThomsonTan deleted the include_macro_in_version branch January 17, 2023 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants