English 中文(简体)
Emitting logs to Open Telemetry Collector
原标题:

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]
问题回答

You need to set the log level

opentelemetry::sdk::common::internal_log::GlobalLogHandler::SetLogLevel(opentelemetry::sdk::common::internal_log::LogLevel::Debug);




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签