Skip to content

OTEL_CPP_GET_ATTR macro should fully qualify its usage of attr #1139

@lidavidm

Description

@lidavidm

Describe your environment

Platform: Linux
OpenTelemetry version: v1.1.0
Build system: CMake
Compiler:

> g++ --version
g++ (GCC) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Steps to reproduce

Compile this snippet:

#include <opentelemetry/sdk/resource/experimental_semantic_conventions.h>

#include <iostream>

int main(int, char**) {
  std::cout << OTEL_CPP_GET_ATTR(AttrServiceName) << std::endl;
  return 0;
}
$ g++ -I$CONDA_PREFIX/include test.cc -o test

What is the expected behavior?
The snippet should compile.

What is the actual behavior?
The snippet fails to compile:

> g++ -I$CONDA_PREFIX/include test.cc -o test 
In file included from test.cc:1:
test.cc: In function 'int main(int, char**)':
~/miniconda3/envs/astronaut-cpp/include/opentelemetry/sdk/resource/experimental_semantic_conventions.h:24:33: error: 'attr' was not declared in this scope
   24 | #define OTEL_CPP_GET_ATTR(name) attr(OTEL_CPP_CONST_HASHCODE(name))
      |                                 ^~~~
test.cc:6:16: note: in expansion of macro 'OTEL_CPP_GET_ATTR'
    6 |   std::cout << OTEL_CPP_GET_ATTR(AttrServiceName) << std::endl;
      |                ^~~~~~~~~~~~~~~~~

Additional context

The use of the attr helper should be fully qualified here, so it can be used even when not inside an OpenTelemetry namespace or without having to add using opentelemetry::sdk::resource::attr;.

#define OTEL_CPP_GET_ATTR(name) attr(OTEL_CPP_CONST_HASHCODE(name))

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions