-
Notifications
You must be signed in to change notification settings - Fork 423
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
OTLP GRPC CPP Exporter Does Not Compile #880
Comments
@techxpert99 - please try the following options:
or
|
@maxgolov Thank you. Any of the two options resolve the bug, and the export works as intended. I will be closing this issue now. |
@lalitb @techxpert99 - I also wrote this example that works: // Make sure to include GRPC headers first because otherwise Abseil may create
// ambiguity with `nostd::variant` if compiled with Visual Studio 2015. Other
// modern compilers are unaffected.
#include <grpcpp/grpcpp.h>
#include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h"
#include "opentelemetry/trace/provider.h"
#include "opentelemetry/sdk/trace/simple_processor.h"
#include "opentelemetry/sdk/trace/tracer_provider.h"
#include <iostream>
using namespace opentelemetry;
nostd::shared_ptr<trace::Tracer> tracer;
void setup()
{
exporter::otlp::OtlpGrpcExporterOptions options;
auto exporter =
std::unique_ptr<sdk::trace::SpanExporter>(new exporter::otlp::OtlpGrpcExporter(options));
auto processor = std::unique_ptr<sdk::trace::SpanProcessor>(
new sdk::trace::SimpleSpanProcessor(std::move(exporter)));
auto provider = nostd::shared_ptr<trace::TracerProvider>(
new sdk::trace::TracerProvider(std::move(processor)));
tracer = provider->GetTracer("otel-demo-cpp-oge2c2zb-tracer", "0.1");
}
int fib(int n)
{
int ans = -1;
auto span = tracer->StartSpan("fib-function");
auto scope = tracer->WithActiveSpan(span);
if (n < 0)
span->AddEvent("Negative Input");
else if (n == 0)
ans = 0;
else if (n == 1)
ans = 1;
else
ans = fib(n - 2) + fib(n - 1);
span->SetAttribute("answer", ans);
span->End();
return ans;
}
int main(int arc, char **argv)
{
setup();
int n;
std::cout << "Input number: ";
std::cin >> n;
std::cout << "Output: " << fib(n) << std::endl;
return 0;
} I will think about how to fix it better. The issue is that we use internally a different version of Abseil library than gRPC uses. We shield this by adding our own Abseil into our own private namespace. Somehow it clashes with certain compilers, when gRPC's Abseil gets included after ours. However, if gRPC header is included BEFORE the rest of OpenTelemetry headers - everything works! I think it's some sort of a bug, where the two types are in different namespaces clearly. But compiler collapses them all into the same. Maybe it's due to one of the My CMakeLists.txt : project(otlp_grpc_simple)
include_directories(
${CMAKE_BINARY_DIR}/generated/third_party/opentelemetry-proto)
include_directories(${CMAKE_SOURCE_DIR}/exporters/otlp/include)
if(WITH_OTLP_GRPC)
add_executable(otlp_grpc_simple main.cc)
target_link_libraries(
otlp_grpc_simple
${CMAKE_THREAD_LIBS_INIT}
opentelemetry_api
opentelemetry_common
opentelemetry_trace
opentelemetry_exporter_otlp_grpc
opentelemetry_otlp_recordable
opentelemetry_proto
opentelemetry_resources
protobuf
gRPC::grpc++)
endif() I can add this example in our repo, because I believe a similar issue may pop up again. I will also consider a better fix. But I am not yet sure, maybe it's something we need to document... For now I consider you are unblocked! As there are at least two workarounds available to properly make it work. |
@maxgolov Yes fortunately! There is a similar issue with ZipkinExporter, because of a constant named kDefaultZipkinOptions. |
@techxpert99 Both are valid issues, thanks for reporting. Please raise a bug for the same. |
Thanks @maxgolov for looking into this. I agree, we can document this in README.md for OTLP exporter, and gRPC example. |
Ok please ignore, has created an issue for the same : #881 |
Describe your environment
Running Manjaro Linux 21.0.7 Ornara (x86-64, Kernel: Linux 5.10.42-1-MANJARO), in a VirtualBox VM
Compiler(s) Used to build:
g++ (GCC) 11.1.0
gcc (GCC) 11.1.0
clang 12.0.0
Steps to reproduce
(1) Clone the Repo:
git clone --recursive https://www.github.com/open-telemetry/opentelemetery-cpp.git
(2) Build and Install the API, SDK with CMake & Make along with third-party the relevant third-party libs ( opentelemetry-proto, nlohmann-json, ...) and ext libs (http, ...)
(3) The compilation should succeed and produce a superset of the following libs (that I have in /usr/local/lib):
libhttp_client_curl.a,libopentelemetry_common.a; libopentelemetry_exporter_otlp_grpc.a; libopentelemetry_otlp_recordable.a; libopentelemetry_proto.a; libopentelemetry_resources.a; libopentelemetry_trace.a; libopentelemetry_version.a
(4) Along with that install external dependencies- protobuf, grpc, absl
(5) Have a Demo.cpp file with the following code:
(6) Have a CMakeLists.txt file with the following Code:
(7) Have a OtelConCol.yaml file to configure the collector to export to Zipkin:
(8) A docker image: openzipkin/zipkin
(9) Compile in a build directory using
cmake .. && make
(8) If successfully compiled, execute using
./demo
after runningotelconcol --config OtelConCol.yaml
anddocker run -dp 9411:9411 openzipkin/zipkin
[Here otelconcol is the binary of the opentelemetry contrib collector for amd64 architecture]What is the expected behavior?
Expected it to compile. After compilation, expect it to run and export data to collector, and from there to zipkin
What is the actual behavior?
Does not compile using any compiler gcc/g++/clang
Additional context
After analyzing the output of "make", it seems that the bug is because of the redefinition of some of the code of absl lib in the namespace nostd::absl. For instance, the struct identity is redefined. The macro #ifndef OTABSL_BASE_INTERNAL_IDENTITY_H_ , and #idnef ABSL_BASE_INTERNAL_IDENTITY_H_ do not match, and the struct is redefined because of that.
Here is a filtered output of make:
The complete output is as follows:
The text was updated successfully, but these errors were encountered: