企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ### Jaeger-client(客户端库) ***** client是客户端lib,便于不同语言的项目来介入到Jaeger中,当我们的应用程序装载上之后,client会负责收集并发送数据到Agent。当前Jaeger的SDK支持有如下: ``` --官方 1.Go 2.Java 3.Node 4.Python 5.C++ --非官方 1.PHP 3.Others ``` client是支持OpenTracing标准的,如上文提到,Zipkin也是支持OpenTracing标准的,这也就意味着,我们的应用程序在嵌入Jaeger-client的地方,可以随时替换成Zipkin,对业务是完全透明的。 ### Jaeger 客户端库的使用 ***** #### C++Jaeger客户端的使用 github:[https://github.com/jaegertracing/jaeger-client-cpp](https://github.com/jaegertracing/jaeger-client-cpp) ##### Windows下编译 使用Cmake编译 ![UTOOLS1586855741629.png](https://user-gold-cdn.xitu.io/2020/4/14/17177f909eb05854?w=1091&h=578&f=png&s=23291) ##### Linux/MacOS下编译 使用Cmake编译 ##### 参考例子 [examples/App.cpp](https://github.com/jaegertracing/jaeger-client-cpp/blob/master/examples/App.cpp) ``` #include <iostream> #include <yaml-cpp/yaml.h> #include <jaegertracing/Tracer.h> namespace { void setUpTracer(const char* configFilePath) { auto configYAML = YAML::LoadFile(configFilePath); auto config = jaegertracing::Config::parse(configYAML); auto tracer = jaegertracing::Tracer::make( "test_service", config, jaegertracing::logging::consoleLogger()); opentracing::Tracer::InitGlobal( std::static_pointer_cast<opentracing::Tracer>(tracer)); } void tracedSubroutine(const std::unique_ptr<opentracing::Span>& parentSpan) { auto span = opentracing::Tracer::Global()->StartSpan( "tracedSubroutine", { opentracing::ChildOf(&parentSpan->context()) }); } void tracedFunction() { auto span = opentracing::Tracer::Global()->StartSpan("tracedFunction"); tracedSubroutine(span); } } // anonymous namespace int main(int argc, char* argv[]) { if (argc < 2) { std::cerr << "usage: " << argv[0] << " <config-yaml-path>\n"; return 1; } setUpTracer(argv[1]); tracedFunction(); // Not stricly necessary to close tracer, but might flush any buffered // spans. See more details in opentracing::Tracer::Close() documentation. opentracing::Tracer::Global()->Close(); return 0; } ``` 配置文件 config.yml: ``` disabled: false reporter: logSpans: true localAgentHostPort: 192.168.0.172:6831 endPoint: 192.168.0.172:16686/api/traces sampler: type: const param: 1 samplingServerURL: 192.168.0.172:5778/sampling ``` 执行命令: ``` app.exe config.yml ``` 生成: ``` INFO: Initializing logging reporter INFO: Reporting span a86faeec10eb5206:54619d0c57878022:a86faeec10eb5206:1 INFO: Reporting span a86faeec10eb5206:a86faeec10eb5206:0:1 ```