open-telemetry / opentelemetry-cpp

The OpenTelemetry C++ Client
https://opentelemetry.io/
Apache License 2.0
860 stars 410 forks source link

Failed to set service name: 'rec' does not name a type, even the 'rec' is set #920

Closed r03942139 closed 3 years ago

r03942139 commented 3 years ago

Describe your environment Describe any aspect of your environment relevant to the problem, including your platform, build system, version numbers of installed dependencies, etc. If you're reporting a problem with a specific version of a library in this repo, please check whether the problem has been fixed on main branch.

Platform - alpine:3.12.7 opentelemetry-cpp - 1.0.0-rc2 Build - cmake 3.17.2 /usr/bin/c++: (Alpine 9.3.0) 9.3.0 /usr/bin/cc: (Alpine 9.3.0) 9.3.0

Steps to reproduce Describe exactly how to reproduce the error. Include a code sample if applicable.

bash-5.0$ c++ -I/opt/ats/include -I/usr/local/include -I/opentelemetry-cpp-1.0.0-rc3/exporters/jaeger/include -I/opentelemetry-cpp-1.0.0-rc3/exporters/jaeger/src -I/opentelemetry-cpp-1.0.0-rc3/exporters/jaeger/src -I/opentelemetry-cpp-1.0.0-rc3/exporters/jaeger/thrift-gen -std=c++17 -ggdb3 -pipe -Wall -Wextra -Wno-ignored-qualifiers -Wno-unused-parameter -Wno-format-truncation -Wno-cast-function-type -Wno-stringop-overflow -Wno-invalid-offsetof -Wno-noexcept-type -mcx16 -fpic -c main.cc -o main.lo -lopentelemetry_trace -lopentelemetry_version -lopentelemetry_resources -lopentelemetry_exporter_ostream_span -lopentelemetry_zpages -lopentelemetry_common -lhttp_client_curl -lthrift -lthriftnb -lthriftz main.cc:34:1: error: 'rec' does not name a type 34 | rec.SetResource(resource); | ^~~

What is the expected behavior? What did you expect to see?

The rec is previously assigned to class opentelemetry::exporter::jaeger::Recordable rec;

What is the actual behavior? What did you see instead? As above

Additional context Add any other context about the problem here.

----------- My main.cc -----------

include "opentelemetry/exporters/jaeger/recordable.h"

include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h"

include "opentelemetry/exporters/jaeger/jaeger_exporter.h"

include "opentelemetry/sdk/trace/simple_processor.h"

include "opentelemetry/sdk/trace/span_data.h"

include "opentelemetry/sdk/trace/tracer_provider.h"

include "opentelemetry/trace/provider.h"

include

include

define PLUGIN_NAME "hello_world"

namespace trace = opentelemetry::trace; namespace nostd = opentelemetry::nostd; namespace sdktrace = opentelemetry::sdk::trace; namespace jaeger = opentelemetry::exporter::jaeger;

using namespace jaegertracing; using namespace opentelemetry::exporter::jaeger; using namespace opentelemetry::sdk::instrumentationlibrary;

namespace { opentelemetry::exporter::jaeger::JaegerExporterOptions opts;

const std::string service_name_key = "service.name"; std::string service_name_value = "test-jaeger-service-name"; auto resource = opentelemetry::sdk::resource::Resource::Create( {{service_name_key, service_name_value}, {"key1", "value1"}, {"key2", "value2"}}); opentelemetry::exporter::jaeger::Recordable rec; rec.SetResource(resource);

nostd::shared_ptr get_tracer()
{
auto provider = trace::Provider::GetTracerProvider();
return provider->GetTracer("foo_library", OPENTELEMETRY_SDK_VERSION);
}

void InitTracer()
{
// Create Jaeger exporter instance
auto exporter = std::unique_ptr(new jaeger::JaegerExporter(opts)); auto processor = std::unique_ptr(
new sdktrace::SimpleSpanProcessor(std::move(exporter)));
auto provider =
nostd::shared_ptr(new sdktrace::TracerProvider(std::move(processor))); // Set the global trace provider
trace::Provider::SetTracerProvider(provider);
}

void foo_library()
{
auto scoped_span = trace::Scope(get_tracer()->StartSpan("library"));
}
} // namespace

int main() { ..... }

lalitb commented 3 years ago

@r03942139 - a quick look at the linker command shows that you are not linking the Jaeger exporter library. Please check one. Also, I would suggest you to initially use the discussion forum to post these compilations errors, and we would be happy to help you out there. Once proven a bug, we can create an issue from the discussion.

r03942139 commented 3 years ago

Also, I would suggest you to initially use the discussion forum to post these compilations errors, and we would be happy to help you out there. Once proven a bug, we can create an issue from the discussion.

Thank you and pardon. I would use discussions next time for this kind of case. Thanks again.