I am new to Open Telemetry and I am trying its C++ API with a toy example that emit logs. I am using the OtlpHttpLogExporter to emit to the Open Telemetry Collector via http. And I configured the Collector to use the "logging" exporter to print the collected data to the console. When I start up the collector and then run the code, it completes successfully but nothing is printed. Am I missing something? Can you suggest how I can go debugging this issue?
I tried switching to OStreamLogExporter to print directly to console instead of sending to Open Telemetry collector and the logs print fine. I also tried emitting traces and spans to the collector and that works as well. The issue seems to be specifically about sending logs to the collector.
#include "opentelemetry/sdk/logs/simple_log_processor.h"
#include "opentelemetry/sdk/logs/logger_provider.h"
#include "opentelemetry/logs/provider.h"
#include "opentelemetry/exporters/otlp/otlp_http_log_exporter.h"
#include "opentelemetry/sdk/version/version.h"
namespace logs_sdk = opentelemetry::sdk::logs;
namespace otlp = opentelemetry::exporter::otlp;
opentelemetry::exporter::otlp::OtlpHttpLogExporterOptions logger_opts;
int main()
{
auto exporter = std::unique_ptr<logs_sdk::LogExporter>(new otlp::OtlpHttpLogExporter(logger_opts));
auto processor = std::unique_ptr<logs_sdk::LogProcessor>(
new logs_sdk::SimpleLogProcessor(std::move(exporter)));
auto provider =
std::shared_ptr<logs_sdk::LoggerProvider>(new logs_sdk::LoggerProvider(std::move(processor)));
// Get Logger
auto logger = provider->GetLogger("firstlog", "", OPENTELEMETRY_SDK_VERSION);
logger->Debug("I am the first log message.");
}
And the configuration of the collector:
extensions:
health_check:
pprof:
endpoint: 0.0.0.0:1777
zpages:
endpoint: 0.0.0.0:55679
receivers:
otlp:
protocols:
grpc:
http:
opencensus:
# Collect own metrics
prometheus:
config:
scrape_configs:
- job_name: otel-collector
scrape_interval: 10s
static_configs:
- targets: [ 0.0.0.0:8888 ]
jaeger:
protocols:
grpc:
thrift_binary:
thrift_compact:
thrift_http:
zipkin:
processors:
batch:
exporters:
file:
path: ./myoutput.json
logging:
logLevel: debug
prometheus:
endpoint: "prometheus:8889"
namespace: "default"
jaeger:
endpoint: "localhost:14250"
tls:
insecure: true
service:
pipelines:
logs:
receivers: [otlp]
processors: [batch]
exporters: [logging]
traces:
receivers: [otlp]
processors: [batch]
exporters: [logging]
metrics:
receivers: [otlp]
processors: [batch]
exporters: [logging]
extensions: [health_check, pprof, zpages]