├── .appveyor.yml ├── .clang-format ├── .clang-tidy ├── .github └── workflows │ ├── macos.yml │ ├── ubuntu.yml │ └── windows.yml ├── .gitignore ├── .gitmodules ├── .travis.yml ├── .ycm_extra_conf.py ├── CHANGELOG.md ├── CMakeLists.txt ├── CONTRIBUTING.md ├── Dockerfile.plugin ├── LICENSE ├── README.md ├── RELEASE.md ├── cmake ├── CodeCoverage.cmake ├── Config.cmake.in ├── Findthrift.cmake ├── Hunter │ └── config.cmake ├── HunterGate.cmake └── toolchain.cmake ├── codecov.yml ├── crossdock ├── Dockerfile ├── Server.cpp ├── Server.h └── docker-compose.yml ├── examples ├── App.cpp └── config.yml ├── scripts ├── build-plugin.sh ├── build.sh ├── clang-format.sh ├── clang-tidy.sh ├── thrift-gen.patch ├── update-license.py ├── update-licenses.sh └── upload-coverage.sh └── src └── jaegertracing ├── Compilers.h ├── Config.cpp ├── Config.h ├── ConfigTest.cpp ├── Constants.h.in ├── DynamicLoad.cpp ├── DynamicallyLoadTracerTest.cpp ├── LogRecord.cpp ├── LogRecord.h ├── Logging.cpp ├── Logging.h ├── Reference.cpp ├── Reference.h ├── ReferenceTest.cpp ├── Sender.cpp ├── Sender.h ├── Span.cpp ├── Span.h ├── SpanContext.cpp ├── SpanContext.h ├── SpanContextTest.cpp ├── SpanTest.cpp ├── Tag.cpp ├── Tag.h ├── TagTest.cpp ├── ThriftMethods.cpp ├── ThriftSender.cpp ├── ThriftSender.h ├── ThriftSenderTest.cpp ├── TraceID.cpp ├── TraceID.h ├── TraceIDTest.cpp ├── Tracer.cpp ├── Tracer.h ├── TracerFactory.cpp ├── TracerFactory.h ├── TracerFactoryTest.cpp ├── TracerTest.cpp ├── baggage ├── BaggageSetter.cpp ├── BaggageSetter.h ├── BaggageTest.cpp ├── RemoteRestrictionJSON.cpp ├── RemoteRestrictionJSON.h ├── RemoteRestrictionManager.cpp ├── RemoteRestrictionManager.h ├── Restriction.cpp ├── Restriction.h ├── RestrictionManager.cpp ├── RestrictionManager.h ├── RestrictionsConfig.cpp └── RestrictionsConfig.h ├── metrics ├── Counter.cpp ├── Counter.h ├── Gauge.cpp ├── Gauge.h ├── InMemoryStatsReporter.cpp ├── InMemoryStatsReporter.h ├── Metric.cpp ├── Metric.h ├── Metrics.cpp ├── Metrics.h ├── MetricsTest.cpp ├── NullCounter.cpp ├── NullCounter.h ├── NullGauge.cpp ├── NullGauge.h ├── NullStatsFactory.cpp ├── NullStatsFactory.h ├── NullStatsFactoryTest.cpp ├── NullStatsReporter.cpp ├── NullStatsReporter.h ├── NullTimer.cpp ├── NullTimer.h ├── StatsFactory.cpp ├── StatsFactory.h ├── StatsFactoryImpl.cpp ├── StatsFactoryImpl.h ├── StatsReporter.cpp ├── StatsReporter.h ├── Timer.cpp └── Timer.h ├── net ├── IPAddress.cpp ├── IPAddress.h ├── IPAddressTest.cpp ├── Socket.cpp ├── Socket.h ├── SocketTest.cpp ├── URI.cpp ├── URI.h ├── URITest.cpp └── http │ ├── Error.cpp │ ├── Error.h │ ├── Header.cpp │ ├── Header.h │ ├── HeaderTest.cpp │ ├── Method.cpp │ ├── Method.h │ ├── MethodTest.cpp │ ├── Request.cpp │ ├── Request.h │ ├── Response.cpp │ ├── Response.h │ ├── ResponseTest.cpp │ └── SocketReader.h ├── platform ├── Endian.cpp ├── Endian.h ├── Hostname.cpp └── Hostname.h ├── propagation ├── Extractor.cpp ├── Extractor.h ├── Format.cpp ├── Format.h ├── HeadersConfig.cpp ├── HeadersConfig.h ├── Injector.cpp ├── Injector.h ├── JaegerPropagator.cpp ├── JaegerPropagator.h ├── Propagator.cpp ├── Propagator.h ├── PropagatorTest.cpp ├── W3CPropagator.cpp ├── W3CPropagator.h └── W3CPropagatorTest.cpp ├── reporters ├── CompositeReporter.cpp ├── CompositeReporter.h ├── Config.cpp ├── Config.h ├── ConfigTest.cpp ├── InMemoryReporter.cpp ├── InMemoryReporter.h ├── LoggingReporter.cpp ├── LoggingReporter.h ├── NullReporter.cpp ├── NullReporter.h ├── RemoteReporter.cpp ├── RemoteReporter.h ├── Reporter.cpp ├── Reporter.h └── ReporterTest.cpp ├── samplers ├── AdaptiveSampler.cpp ├── AdaptiveSampler.h ├── Config.cpp ├── Config.h ├── ConstSampler.cpp ├── ConstSampler.h ├── GuaranteedThroughputProbabilisticSampler.cpp ├── GuaranteedThroughputProbabilisticSampler.h ├── ProbabilisticSampler.cpp ├── ProbabilisticSampler.h ├── RateLimitingSampler.cpp ├── RateLimitingSampler.h ├── RemoteSamplingJSON.cpp ├── RemoteSamplingJSON.h ├── RemotelyControlledSampler.cpp ├── RemotelyControlledSampler.h ├── Sampler.cpp ├── Sampler.h ├── SamplerTest.cpp ├── SamplingStatus.cpp └── SamplingStatus.h ├── testutils ├── EnvVariable.cpp ├── EnvVariable.h ├── MockAgent.cpp ├── MockAgent.h ├── MockAgentTest.cpp ├── SamplingManager.cpp ├── SamplingManager.h ├── TUDPTransport.cpp ├── TUDPTransport.h ├── TUDPTransportTest.cpp ├── TracerUtil.cpp └── TracerUtil.h ├── thrift-gen ├── Agent.cpp ├── Agent.h ├── AggregationValidator.cpp ├── AggregationValidator.h ├── BaggageRestrictionManager.cpp ├── BaggageRestrictionManager.h ├── Collector.cpp ├── Collector.h ├── Dependency.cpp ├── Dependency.h ├── SamplingManager.cpp ├── SamplingManager.h ├── TracedService.cpp ├── TracedService.h ├── ZipkinCollector.cpp ├── ZipkinCollector.h ├── agent_constants.cpp ├── agent_constants.h ├── agent_types.cpp ├── agent_types.h ├── aggregation_validator_constants.cpp ├── aggregation_validator_constants.h ├── aggregation_validator_types.cpp ├── aggregation_validator_types.h ├── baggage_constants.cpp ├── baggage_constants.h ├── baggage_types.cpp ├── baggage_types.h ├── dependency_constants.cpp ├── dependency_constants.h ├── dependency_types.cpp ├── dependency_types.h ├── jaeger_constants.cpp ├── jaeger_constants.h ├── jaeger_types.cpp ├── jaeger_types.h ├── sampling_constants.cpp ├── sampling_constants.h ├── sampling_types.cpp ├── sampling_types.h ├── tracetest_constants.cpp ├── tracetest_constants.h ├── tracetest_types.cpp ├── tracetest_types.h ├── zipkincore_constants.cpp ├── zipkincore_constants.h ├── zipkincore_types.cpp └── zipkincore_types.h └── utils ├── EnvVariable.cpp ├── EnvVariable.h ├── ErrorUtil.cpp ├── ErrorUtil.h ├── ErrorUtilTest.cpp ├── HTTPTransporter.cpp ├── HTTPTransporter.h ├── HTTPTransporterTest.cpp ├── HexParsing.cpp ├── HexParsing.h ├── RateLimiter.cpp ├── RateLimiter.h ├── RateLimiterTest.cpp ├── Transport.h ├── UDPSenderTest.cpp ├── UDPTransporter.cpp ├── UDPTransporter.h ├── YAML.cpp └── YAML.h /.appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '{build}' 2 | 3 | image: Visual Studio 2017 4 | 5 | init: 6 | - cmd: git config --global core.autocrlf true 7 | 8 | platform: 9 | - x64 10 | 11 | configuration: 12 | - Debug 13 | 14 | before_build: 15 | - cmake -H. -Bbuild -A%PLATFORM% -DBUILD_TESTING=ON 16 | 17 | build: 18 | project: build\jaegertracing.sln 19 | parallel: true 20 | verbosity: normal 21 | 22 | test_script: 23 | - ps: | 24 | cd build 25 | ctest -V -C $env:configuration --timeout 600 --output-on-failure -------------------------------------------------------------------------------- /.github/workflows/macos.yml: -------------------------------------------------------------------------------- 1 | name: MacOS 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | env: 12 | CTEST_OUTPUT_ON_FAILURE: 1 13 | 14 | jobs: 15 | build: 16 | 17 | runs-on: macos-latest 18 | 19 | steps: 20 | 21 | - name: Set up cache 22 | uses: actions/cache@v2 23 | with: 24 | path: ~\.hunter 25 | key: ${{ runner.os }}-hunter-${{ hashFiles('**/') }} 26 | restore-keys: | 27 | ${{ runner.os }}-hunter- 28 | 29 | - name: Checkout repository 30 | uses: actions/checkout@v2 31 | 32 | - name: Configure 33 | run: cmake -Bbuild 34 | 35 | - name: Build 36 | run: cmake --build build -j4 37 | 38 | - name: Test 39 | run: | 40 | cd build 41 | ctest -V --timeout 600 42 | -------------------------------------------------------------------------------- /.github/workflows/ubuntu.yml: -------------------------------------------------------------------------------- 1 | name: Ubuntu 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | env: 12 | CTEST_OUTPUT_ON_FAILURE: 1 13 | 14 | jobs: 15 | build: 16 | 17 | runs-on: ubuntu-latest 18 | 19 | steps: 20 | 21 | - name: Set up GCC 22 | uses: egor-tensin/setup-gcc@v1 23 | with: 24 | version: 7 25 | 26 | - name: Set up cache 27 | uses: actions/cache@v2 28 | with: 29 | path: ~\.hunter 30 | key: ${{ runner.os }}-hunter-${{ hashFiles('**/') }} 31 | restore-keys: | 32 | ${{ runner.os }}-hunter- 33 | 34 | - name: Checkout repository 35 | uses: actions/checkout@v2 36 | 37 | - name: Configure 38 | run: cmake -Bbuild 39 | 40 | - name: Build 41 | run: cmake --build build -j4 42 | 43 | - name: Test 44 | run: | 45 | cd build 46 | ctest -V --timeout 600 47 | -------------------------------------------------------------------------------- /.github/workflows/windows.yml: -------------------------------------------------------------------------------- 1 | name: Windows 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | env: 12 | CTEST_OUTPUT_ON_FAILURE: 1 13 | 14 | jobs: 15 | build: 16 | 17 | runs-on: windows-latest 18 | 19 | steps: 20 | 21 | - name: Set up cache 22 | uses: actions/cache@v2 23 | with: 24 | path: ~\AppData\Local\hunter 25 | key: ${{ runner.os }}-hunter-${{ hashFiles('**/') }} 26 | restore-keys: | 27 | ${{ runner.os }}-hunter- 28 | 29 | - name: Checkout repository 30 | uses: actions/checkout@v2 31 | 32 | - name: Configure 33 | run: cmake -Bbuild 34 | 35 | - name: Build 36 | run: cmake --build build -j4 37 | 38 | - name: Test 39 | run: | 40 | cd build 41 | ctest -V -C Debug --timeout 600 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build files 2 | /build 3 | /crossdock/crossdock 4 | /crossdock/jaeger-docker-compose.yml 5 | 6 | # vim swap files 7 | *.swo 8 | *.swp 9 | 10 | # Prerequisites 11 | *.d 12 | 13 | # Compiled Object files 14 | *.slo 15 | *.lo 16 | *.o 17 | *.obj 18 | 19 | # Precompiled Headers 20 | *.gch 21 | *.pch 22 | 23 | # Compiled Dynamic libraries 24 | *.so 25 | *.dylib 26 | *.dll 27 | 28 | # Fortran module files 29 | *.mod 30 | *.smod 31 | 32 | # Compiled Static libraries 33 | *.lai 34 | *.la 35 | *.a 36 | *.lib 37 | 38 | # Executables 39 | *.exe 40 | *.out 41 | *.app 42 | 43 | # Log files 44 | *.log 45 | 46 | # CLion folders 47 | cmake-build-debug 48 | .idea 49 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "idl"] 2 | path = idl 3 | url = https://github.com/uber/jaeger-idl.git 4 | -------------------------------------------------------------------------------- /Dockerfile.plugin: -------------------------------------------------------------------------------- 1 | FROM debian 2 | RUN apt-get update 3 | RUN apt-get install --yes build-essential curl git 4 | RUN curl -L -O "https://cmake.org/files/v3.11/cmake-3.11.0-Linux-x86_64.sh" && \ 5 | bash cmake-3.11.0-Linux-x86_64.sh --skip-license 6 | 7 | ADD . /src/jaeger-cpp-client 8 | WORKDIR /src/jaeger-cpp-client 9 | RUN ./scripts/build-plugin.sh 10 | -------------------------------------------------------------------------------- /RELEASE.md: -------------------------------------------------------------------------------- 1 | # Release Process 2 | 3 | 1. Create a PR "Preparing for release X.Y.Z" against master branch 4 | * Add section to `CHANGELOG.md` ` (YYYY-MM-DD)` with the list of changes 5 | * Change/verify vesion number in `CMakelists.txt` 6 | 2. Create a release "Release X.Y.Z" on Github 7 | * Create Tag `vX.Y.Z` 8 | * Copy `CHANGELOG.md` entry into the release notes 9 | 3. Create a PR "Back to development" against master branch 10 | * Update ` (unreleased)` section in the `CHANGELOG.md` 11 | * Update project version in CMakeLists.txt to the `` 12 | -------------------------------------------------------------------------------- /cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | set(package_deps @package_deps@) 4 | foreach(dep IN LISTS package_deps) 5 | if(dep STREQUAL "OpenSSL" OR dep STREQUAL "Threads") 6 | find_package(${dep} REQUIRED) 7 | elseif(dep STREQUAL "OpenTracing" OR 8 | dep STREQUAL "yaml-cpp") 9 | find_package(${dep} CONFIG REQUIRED) 10 | else() 11 | find_package(${dep} @hunter_config@ REQUIRED) 12 | endif() 13 | endforeach() 14 | 15 | set(boost_components @boost_components@) 16 | find_package(Boost CONFIG REQUIRED ${boost_components}) 17 | 18 | check_required_components("@PROJECT_NAME@") 19 | 20 | include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") 21 | -------------------------------------------------------------------------------- /cmake/Hunter/config.cmake: -------------------------------------------------------------------------------- 1 | hunter_config(GTest VERSION 1.8.0-hunter-p11) 2 | -------------------------------------------------------------------------------- /cmake/toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 2 | set(CMAKE_CXX_STANDARD 11) 3 | set(CMAKE_CXX_EXTENSIONS OFF) 4 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 5 | set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | notify: 3 | require_ci_to_pass: yes 4 | 5 | coverage: 6 | precision: 2 7 | round: down 8 | range: "70...100" 9 | 10 | status: 11 | project: yes 12 | patch: yes 13 | changes: no 14 | 15 | parsers: 16 | gcov: 17 | branch_detection: 18 | conditional: yes 19 | loop: yes 20 | method: no 21 | macro: no 22 | 23 | comment: 24 | layout: "reach, diff, flags, files, footer" 25 | behavior: default 26 | require_changes: no 27 | 28 | ignore: 29 | - "src/jaegertracing/thrift-gen" 30 | - "**/*Test.cpp" 31 | - "crossdock" 32 | -------------------------------------------------------------------------------- /crossdock/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gcc:7.2 2 | 3 | ADD ./build/crossdock / 4 | 5 | ENV AGENT_HOST_PORT=jaeger-agent:5775 6 | ENV SAMPLING_SERVER_URL=http://test_driver:5778/sampling 7 | 8 | EXPOSE 8080-8082 9 | 10 | CMD ["/crossdock"] 11 | -------------------------------------------------------------------------------- /crossdock/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | crossdock: 5 | image: crossdock/crossdock 6 | links: 7 | - test_driver 8 | - go 9 | - cpp-udp 10 | - cpp-http 11 | environment: 12 | - WAIT_FOR=test_driver,go,cpp-udp,cpp-http 13 | - WAIT_FOR_TIMEOUT=60s 14 | 15 | - CALL_TIMEOUT=60s 16 | 17 | - AXIS_CLIENT=go 18 | - AXIS_S1NAME=go,cpp-udp 19 | - AXIS_SAMPLED=true,false 20 | - AXIS_S2NAME=go,cpp-udp 21 | - AXIS_S2TRANSPORT=http 22 | - AXIS_S3NAME=go,cpp-udp 23 | - AXIS_S3TRANSPORT=http 24 | 25 | - BEHAVIOR_TRACE=client,s1name,sampled,s2name,s2transport,s3name,s3transport 26 | 27 | - AXIS_TESTDRIVER=test_driver 28 | - AXIS_SERVICES=cpp-udp,cpp-http 29 | 30 | - BEHAVIOR_ENDTOEND=testdriver,services 31 | 32 | - REPORT=compact 33 | 34 | go: 35 | image: jaegertracing/xdock-go 36 | ports: 37 | - "8080-8082" 38 | 39 | cpp-udp: 40 | depends_on: 41 | - test_driver 42 | build: 43 | context: $PWD 44 | dockerfile: crossdock/Dockerfile 45 | ports: 46 | - "8080-8082" 47 | environment: 48 | - SENDER=udp 49 | 50 | cpp-http: 51 | depends_on: 52 | - test_driver 53 | build: 54 | context: $PWD 55 | dockerfile: crossdock/Dockerfile 56 | ports: 57 | - "8080-8082" 58 | environment: 59 | - SENDER=http 60 | 61 | test_driver: 62 | image: jaegertracing/test-driver 63 | depends_on: 64 | - jaeger-query 65 | - jaeger-collector 66 | - jaeger-agent 67 | ports: 68 | - "8080" 69 | -------------------------------------------------------------------------------- /examples/App.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace { 8 | 9 | void setUpTracer(const char* configFilePath) 10 | { 11 | auto configYAML = YAML::LoadFile(configFilePath); 12 | auto config = jaegertracing::Config::parse(configYAML); 13 | auto tracer = jaegertracing::Tracer::make( 14 | "example-service", config, jaegertracing::logging::consoleLogger()); 15 | opentracing::Tracer::InitGlobal( 16 | std::static_pointer_cast(tracer)); 17 | } 18 | 19 | void tracedSubroutine(const std::unique_ptr& parentSpan) 20 | { 21 | auto span = opentracing::Tracer::Global()->StartSpan( 22 | "tracedSubroutine", { opentracing::ChildOf(&parentSpan->context()) }); 23 | } 24 | 25 | void tracedFunction() 26 | { 27 | auto span = opentracing::Tracer::Global()->StartSpan("tracedFunction"); 28 | tracedSubroutine(span); 29 | } 30 | 31 | } // anonymous namespace 32 | 33 | int main(int argc, char* argv[]) 34 | { 35 | if (argc < 2) { 36 | std::cerr << "usage: " << argv[0] << " \n"; 37 | return 1; 38 | } 39 | setUpTracer(argv[1]); 40 | tracedFunction(); 41 | // Not stricly necessary to close tracer, but might flush any buffered 42 | // spans. See more details in opentracing::Tracer::Close() documentation. 43 | opentracing::Tracer::Global()->Close(); 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /examples/config.yml: -------------------------------------------------------------------------------- 1 | disabled: false 2 | reporter: 3 | logSpans: true 4 | sampler: 5 | type: const 6 | param: 1 7 | -------------------------------------------------------------------------------- /scripts/build-plugin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | function main() { 6 | local project_dir 7 | project_dir="$(git rev-parse --show-toplevel)" 8 | 9 | mkdir -p build 10 | cd build 11 | export CFLAGS="$CFLAGS -march=x86-64" 12 | export CXXFLAGS="$CXXFLAGS -march=x86-64" 13 | 14 | cat < export.map 15 | { 16 | global: 17 | OpenTracingMakeTracerFactory; 18 | local: *; 19 | }; 20 | EOF 21 | 22 | cmake -DCMAKE_BUILD_TYPE=Release \ 23 | -DJAEGERTRACING_PLUGIN=ON \ 24 | -DBUILD_TESTING=ON \ 25 | -DHUNTER_CONFIGURATION_TYPES=Release \ 26 | .. 27 | make -j3 28 | mv libjaegertracing_plugin.so /libjaegertracing_plugin.so 29 | ./DynamicallyLoadTracerTest /libjaegertracing_plugin.so 30 | } 31 | 32 | main 33 | -------------------------------------------------------------------------------- /scripts/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Based on https://github.com/codecov/example-cpp11-cmake/blob/master/run_build.sh. 4 | 5 | set -e 6 | 7 | RED='\033[0;31m' 8 | BLUE='\033[0;34m' 9 | NO_COLOR='\033[0m' 10 | GREEN='\033[0;32m' 11 | 12 | function info() { 13 | echo -e "${GREEN}$1${NO_COLOR}" 14 | } 15 | 16 | function working() { 17 | echo -e "${BLUE}$1${NO_COLOR}" 18 | } 19 | 20 | function main() { 21 | local project_dir 22 | project_dir=$(git rev-parse --show-toplevel) 23 | cd "$project_dir" 24 | 25 | mkdir -p build 26 | cd build 27 | cmake ${CMAKE_OPTIONS} .. 28 | make -j3 UnitTest 29 | info "Running tests..." 30 | ./UnitTest 31 | working "All tests compiled and passed" 32 | 33 | set -x 34 | if ! [[ "${CMAKE_OPTIONS}" =~ "-DJAEGERTRACING_BUILD_CROSSDOCK=ON" ]]; then 35 | exit 0 36 | fi 37 | make crossdock-fresh 38 | } 39 | 40 | main 41 | -------------------------------------------------------------------------------- /scripts/clang-format.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function main() { 4 | local project_dir 5 | project_dir=$(git rev-parse --show-toplevel) 6 | cd "$project_dir" || exit 1 7 | 8 | local srcs 9 | srcs=$(git ls-files src crossdock | 10 | grep -E -v 'thrift-gen' | 11 | grep -E '\.(cpp|h)$') 12 | 13 | local cmd 14 | for src in $srcs; do 15 | cmd="clang-format -i $src" 16 | echo "$cmd" 17 | eval "$cmd" 18 | done 19 | } 20 | 21 | main 22 | -------------------------------------------------------------------------------- /scripts/clang-tidy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function main() { 4 | local project_dir 5 | project_dir=$(git rev-parse --show-toplevel) 6 | cd "$project_dir" || exit 1 7 | 8 | local srcs 9 | srcs=$(git ls-files src crossdock | 10 | grep -E -v 'thrift-gen|Test\.cpp' | 11 | grep -E '\.cpp$') 12 | 13 | local cmd 14 | for src in $srcs; do 15 | cmd="clang-tidy -p=build" 16 | cmd+=" -checks=\"-clang-diagnostic-unused-command-line-argument\" " 17 | cmd+=" $src" 18 | echo "$cmd" 19 | eval "$cmd" 20 | done 21 | } 22 | 23 | main 24 | -------------------------------------------------------------------------------- /scripts/update-licenses.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | python scripts/update-license.py $(git ls-files "*\.cpp" "*\.h" | 6 | grep -v thrift-gen | 7 | grep -v tracetest) \ 8 | src/jaegertracing/Constants.h.in 9 | -------------------------------------------------------------------------------- /scripts/upload-coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2018 Uber Technologies, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | 19 | function main() { 20 | set -x 21 | if ! [[ "${CMAKE_OPTIONS}" =~ "-DJAEGERTRACING_COVERAGE=ON" ]]; then 22 | exit 0 23 | fi 24 | unset -x 25 | 26 | local project_dir 27 | project_dir=$(git rev-parse --show-toplevel) 28 | cd "$project_dir" || exit 1 29 | 30 | local gcov_tool 31 | case "$CC" in 32 | gcc*) gcov_tool=${CC/gcc/gcov} 33 | ;; 34 | *) gcov_tool="$project_dir/scripts/llvm-gcov.sh" 35 | ;; 36 | esac 37 | find build -name '*.gcno' -exec "$gcov_tool" {} \; 38 | bash <(curl -s https://codecov.io/bash) || \ 39 | echo "Codecov did not collect coverage reports" 40 | } 41 | 42 | main 43 | -------------------------------------------------------------------------------- /src/jaegertracing/Compilers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_COMPILERS_H 18 | #define JAEGERTRACING_COMPILERS_H 19 | 20 | #ifdef _MSC_VER 21 | 22 | #pragma warning(push) 23 | #pragma warning(disable : 4251) 24 | #pragma warning(disable : 4275) 25 | 26 | // Define NOMINMAX to inhibit definition of Macros min(a,b) and max(a,b) in 27 | // windows.h 28 | #ifndef NOMINMAX 29 | #define NOMINMAX 30 | #endif 31 | 32 | #endif // _MSC_VER 33 | 34 | #endif // JAEGERTRACING_COMPILERS_H 35 | -------------------------------------------------------------------------------- /src/jaegertracing/Constants.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_CONSTANTS_H 18 | #define JAEGERTRACING_CONSTANTS_H 19 | 20 | #cmakedefine JAEGERTRACING_WITH_YAML_CPP 21 | 22 | namespace jaegertracing { 23 | 24 | static constexpr auto kJaegerClientVersion = "C++-@PROJECT_VERSION@"; 25 | static constexpr auto kJaegerClientVersionTagKey = "jaeger.version"; 26 | static constexpr auto kJaegerDebugHeader = "jaeger-debug-id"; 27 | static constexpr auto kJaegerBaggageHeader = "jaeger-baggage"; 28 | static constexpr auto kTracerHostnameTagKey = "hostname"; 29 | static constexpr auto kTracerIPTagKey = "ip"; 30 | static constexpr auto kSamplerTypeTagKey = "sampler.type"; 31 | static constexpr auto kSamplerParamTagKey = "sampler.param"; 32 | static constexpr auto kTraceContextHeaderName = "uber-trace-id"; 33 | static constexpr auto kTracerStateHeaderName = kTraceContextHeaderName; 34 | static constexpr auto kTraceBaggageHeaderPrefix = "uberctx-"; 35 | static constexpr auto kW3CTraceParentHeaderName = "traceparent"; 36 | static constexpr auto kW3CTraceStateHeaderName = "tracestate"; 37 | static constexpr auto kSamplerTypeConst = "const"; 38 | static constexpr auto kSamplerTypeRemote = "remote"; 39 | static constexpr auto kSamplerTypeProbabilistic = "probabilistic"; 40 | static constexpr auto kSamplerTypeRateLimiting = "ratelimiting"; 41 | static constexpr auto kSamplerTypeLowerBound = "lowerbound"; 42 | 43 | } // namespace jaegertracing 44 | 45 | #endif // JAEGERTRACING_CONSTANTS_H 46 | -------------------------------------------------------------------------------- /src/jaegertracing/DynamicLoad.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | #include "jaegertracing/Tracer.h" 23 | #include "jaegertracing/TracerFactory.h" 24 | 25 | static int makeTracerFactory(const char* opentracingVersion, 26 | const char* opentracingABIVersion, 27 | const void** errorCategory, 28 | void* errorMessage, 29 | void** tracerFactory) 30 | { 31 | assert(errorCategory != nullptr); 32 | assert(tracerFactory != nullptr); 33 | #ifndef JAEGERTRACING_WITH_YAML_CPP 34 | *errorCategory = 35 | static_cast(&opentracing::dynamic_load_error_category()); 36 | return opentracing::dynamic_load_not_supported_error.value(); 37 | #endif 38 | if (std::strcmp(opentracingABIVersion, OPENTRACING_ABI_VERSION) != 0) { 39 | *errorCategory = static_cast( 40 | &opentracing::dynamic_load_error_category()); 41 | return opentracing::incompatible_library_versions_error.value(); 42 | } 43 | 44 | const auto jaegerTracerFactory = new (std::nothrow) jaegertracing::TracerFactory(true); 45 | *tracerFactory = jaegerTracerFactory; 46 | if (*tracerFactory == nullptr) { 47 | *errorCategory = static_cast(&std::generic_category()); 48 | return static_cast(std::errc::not_enough_memory); 49 | } 50 | 51 | return 0; 52 | } 53 | 54 | OPENTRACING_DECLARE_IMPL_FACTORY(makeTracerFactory) 55 | -------------------------------------------------------------------------------- /src/jaegertracing/DynamicallyLoadTracerTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | #include "jaegertracing/Constants.h" 22 | 23 | // Verify that Jaeger's shared library can be dynamically loaded and used 24 | // as a plugin. 25 | int main(int argc, char* argv[]) 26 | { 27 | if (argc != 2) { 28 | std::cerr << "DynamicLoadTest \n"; 29 | return -1; 30 | } 31 | const char* library = argv[1]; 32 | std::string errorMessage; 33 | auto tracerFactoryMaybe = 34 | opentracing::DynamicallyLoadTracingLibrary(library, errorMessage); 35 | #ifdef JAEGERTRACING_WITH_YAML_CPP 36 | if (!errorMessage.empty()) { 37 | std::cerr << "Failed to load tracing tracer: " << errorMessage << "\n"; 38 | return -1; 39 | } 40 | if (!tracerFactoryMaybe) { 41 | std::cerr << "Failed to load tracing library: " 42 | << tracerFactoryMaybe.error().message() << "\n"; 43 | return -1; 44 | } 45 | #else 46 | if (tracerFactoryMaybe) { 47 | std::cerr << "Dynamically loading a tracing library should fail " 48 | "without YAML support\n"; 49 | return -1; 50 | } 51 | #endif // JAEGERTRACING_WITH_YAML_CPP 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /src/jaegertracing/LogRecord.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/LogRecord.h" 18 | #include "jaegertracing/thrift-gen/jaeger_types.h" 19 | 20 | namespace jaegertracing { 21 | void LogRecord::thrift(thrift::Log& log) const 22 | { 23 | log.__set_timestamp(std::chrono::duration_cast( 24 | _timestamp.time_since_epoch()) 25 | .count()); 26 | 27 | std::vector fields; 28 | fields.reserve(_fields.size()); 29 | std::transform(std::begin(_fields), 30 | std::end(_fields), 31 | std::back_inserter(fields), 32 | [](const Tag& tag) { 33 | thrift::Tag thriftTag; 34 | tag.thrift(thriftTag); 35 | return thriftTag; 36 | }); 37 | log.__set_fields(fields); 38 | } 39 | } // namespace jaegertracing 40 | -------------------------------------------------------------------------------- /src/jaegertracing/LogRecord.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_LOGRECORD_H 18 | #define JAEGERTRACING_LOGRECORD_H 19 | 20 | #include "jaegertracing/Compilers.h" 21 | #include "jaegertracing/Tag.h" 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | namespace jaegertracing { 31 | namespace thrift { 32 | class Log; 33 | } 34 | 35 | class LogRecord { 36 | public: 37 | using Clock = std::chrono::system_clock; 38 | 39 | LogRecord() 40 | : _timestamp(Clock::now()) 41 | { 42 | } 43 | 44 | template 45 | LogRecord(const Clock::time_point& timestamp, 46 | FieldIterator first, 47 | FieldIterator last) 48 | : _timestamp(timestamp) 49 | , _fields(first, last) 50 | { 51 | } 52 | 53 | LogRecord(const opentracing::LogRecord& other) 54 | : _timestamp(other.timestamp) 55 | , _fields(other.fields.begin(), other.fields.end()) 56 | { 57 | } 58 | 59 | const Clock::time_point& timestamp() const { return _timestamp; } 60 | 61 | const std::vector& fields() const { return _fields; } 62 | 63 | void thrift(thrift::Log& log) const; 64 | 65 | private: 66 | Clock::time_point _timestamp; 67 | std::vector _fields; 68 | }; 69 | 70 | } // namespace jaegertracing 71 | 72 | #endif // JAEGERTRACING_LOGRECORD_H 73 | -------------------------------------------------------------------------------- /src/jaegertracing/Logging.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/Logging.h" 18 | 19 | #include 20 | 21 | namespace jaegertracing { 22 | namespace logging { 23 | namespace { 24 | 25 | class NullLogger : public Logger { 26 | public: 27 | void error(const std::string& /* message */) override {} 28 | 29 | void info(const std::string& /* message */) override {} 30 | }; 31 | 32 | class ConsoleLogger : public Logger { 33 | public: 34 | void error(const std::string& message) override 35 | { 36 | std::cerr << "ERROR: " << message << '\n'; 37 | } 38 | 39 | void info(const std::string& message) override 40 | { 41 | std::cout << "INFO: " << message << '\n'; 42 | } 43 | }; 44 | 45 | } // anonymous namespace 46 | 47 | std::unique_ptr nullLogger() 48 | { 49 | return std::unique_ptr(new NullLogger()); 50 | } 51 | 52 | std::unique_ptr consoleLogger() 53 | { 54 | return std::unique_ptr(new ConsoleLogger()); 55 | } 56 | 57 | } // namespace logging 58 | } // namespace jaegertracing 59 | -------------------------------------------------------------------------------- /src/jaegertracing/Logging.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_LOGGING_H 18 | #define JAEGERTRACING_LOGGING_H 19 | 20 | #include 21 | #include 22 | 23 | #include "jaegertracing/Compilers.h" 24 | 25 | namespace jaegertracing { 26 | namespace logging { 27 | 28 | class Logger { 29 | public: 30 | virtual ~Logger() = default; 31 | 32 | virtual void error(const std::string& message) = 0; 33 | 34 | virtual void info(const std::string& message) = 0; 35 | }; 36 | 37 | std::unique_ptr nullLogger(); 38 | 39 | std::unique_ptr consoleLogger(); 40 | 41 | } // namespace logging 42 | } // namespace jaegertracing 43 | 44 | #endif // JAEGERTRACING_LOGGING_H 45 | -------------------------------------------------------------------------------- /src/jaegertracing/Reference.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/Reference.h" 18 | #include "jaegertracing/thrift-gen/jaeger_types.h" 19 | 20 | namespace jaegertracing { 21 | void Reference::thrift(thrift::SpanRef& spanRef) const 22 | { 23 | switch (_type) { 24 | case Type::ChildOfRef: { 25 | spanRef.__set_refType(thrift::SpanRefType::CHILD_OF); 26 | } break; 27 | case Type::FollowsFromRef: { 28 | spanRef.__set_refType(thrift::SpanRefType::FOLLOWS_FROM); 29 | } break; 30 | default: { 31 | std::ostringstream oss; 32 | oss << "Invalid span reference type " << static_cast(_type) 33 | << ", context " << _spanContext; 34 | throw std::invalid_argument(oss.str()); 35 | } break; 36 | } 37 | spanRef.__set_traceIdHigh(_spanContext.traceID().high()); 38 | spanRef.__set_traceIdLow(_spanContext.traceID().low()); 39 | spanRef.__set_spanId(_spanContext.spanID()); 40 | } 41 | } // namespace jaegertracing 42 | -------------------------------------------------------------------------------- /src/jaegertracing/Reference.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_REFERENCE_H 18 | #define JAEGERTRACING_REFERENCE_H 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include "jaegertracing/Compilers.h" 26 | #include "jaegertracing/SpanContext.h" 27 | 28 | namespace jaegertracing { 29 | namespace thrift { 30 | class SpanRef; 31 | } 32 | 33 | class Reference { 34 | public: 35 | using Type = opentracing::SpanReferenceType; 36 | 37 | Reference(const SpanContext& spanContext, Type type) 38 | : _spanContext(spanContext) 39 | , _type(type) 40 | { 41 | } 42 | 43 | const SpanContext& spanContext() const { return _spanContext; } 44 | 45 | Type type() const { return _type; } 46 | 47 | void thrift(thrift::SpanRef& spanRef) const; 48 | 49 | private: 50 | SpanContext _spanContext; 51 | Type _type; 52 | }; 53 | 54 | } // namespace jaegertracing 55 | 56 | #endif // JAEGERTRACING_REFERENCE_H 57 | -------------------------------------------------------------------------------- /src/jaegertracing/ReferenceTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/Reference.h" 18 | #include "jaegertracing/SpanContext.h" 19 | #include "jaegertracing/thrift-gen/jaeger_types.h" 20 | #include 21 | #include 22 | 23 | namespace jaegertracing { 24 | 25 | TEST(Reference, testThriftConversion) 26 | { 27 | const SpanContext context; 28 | const Reference childRef(context, Reference::Type::ChildOfRef); 29 | thrift::SpanRef thriftChildRef; 30 | ASSERT_NO_THROW(childRef.thrift(thriftChildRef)); 31 | const Reference followsFromRef(context, Reference::Type::FollowsFromRef); 32 | thrift::SpanRef thriftFollowsFromRef; 33 | ASSERT_NO_THROW(followsFromRef.thrift(thriftFollowsFromRef)); 34 | const Reference invalidRef(context, static_cast(-1)); 35 | thrift::SpanRef thriftInvalidRef; 36 | ASSERT_THROW(invalidRef.thrift(thriftInvalidRef), std::invalid_argument); 37 | } 38 | 39 | } // namespace jaegertracing 40 | -------------------------------------------------------------------------------- /src/jaegertracing/Sender.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/Sender.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/Sender.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_SENDER_H 18 | #define JAEGERTRACING_SENDER_H 19 | 20 | #include 21 | #include 22 | 23 | #include "jaegertracing/Compilers.h" 24 | 25 | namespace jaegertracing { 26 | 27 | class Span; 28 | 29 | class Sender { 30 | public: 31 | class Exception : public std::runtime_error { 32 | public: 33 | Exception(const std::string& what, int numFailed) 34 | : std::runtime_error(what) 35 | , _numFailed(numFailed) 36 | { 37 | } 38 | 39 | int numFailed() const { return _numFailed; } 40 | 41 | private: 42 | int _numFailed; 43 | }; 44 | 45 | virtual ~Sender() = default; 46 | 47 | virtual int append(const Span& span) = 0; 48 | 49 | virtual int flush() = 0; 50 | 51 | virtual void close() = 0; 52 | }; 53 | 54 | } // namespace jaegertracing 55 | 56 | #endif //JAEGERTRACING_SENDER_H 57 | -------------------------------------------------------------------------------- /src/jaegertracing/SpanContext.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/SpanContext.h" 18 | 19 | #include "jaegertracing/utils/HexParsing.h" 20 | 21 | namespace jaegertracing { 22 | 23 | SpanContext SpanContext::fromStream(std::istream& in) 24 | { 25 | SpanContext spanContext; 26 | spanContext._traceID = TraceID::fromStream(in); 27 | if (!spanContext._traceID.isValid()) { 28 | return SpanContext(); 29 | } 30 | 31 | char ch = '\0'; 32 | if (!in.get(ch) || ch != ':') { 33 | return SpanContext(); 34 | } 35 | 36 | constexpr auto kMaxUInt64Chars = static_cast(16); 37 | auto buffer = utils::HexParsing::readSegment(in, kMaxUInt64Chars, ':'); 38 | if (buffer.empty()) { 39 | return SpanContext(); 40 | } 41 | spanContext._spanID = utils::HexParsing::decodeHex(buffer); 42 | 43 | if (!in.get(ch) || ch != ':') { 44 | return SpanContext(); 45 | } 46 | 47 | buffer = utils::HexParsing::readSegment(in, kMaxUInt64Chars, ':'); 48 | if (buffer.empty()) { 49 | return SpanContext(); 50 | } 51 | spanContext._parentID = utils::HexParsing::decodeHex(buffer); 52 | 53 | if (!in.get(ch) || ch != ':') { 54 | return SpanContext(); 55 | } 56 | 57 | constexpr auto kMaxByteChars = static_cast(2); 58 | buffer = utils::HexParsing::readSegment(in, kMaxByteChars, ':'); 59 | if (buffer.empty()) { 60 | return SpanContext(); 61 | } 62 | spanContext._flags = utils::HexParsing::decodeHex(buffer); 63 | 64 | in.clear(); 65 | return spanContext; 66 | } 67 | 68 | } // namespace jaegertracing 69 | -------------------------------------------------------------------------------- /src/jaegertracing/SpanTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/Span.h" 18 | #include "jaegertracing/thrift-gen/jaeger_types.h" 19 | #include 20 | #include 21 | 22 | namespace jaegertracing { 23 | 24 | TEST(Span, testThriftConversion) 25 | { 26 | const Span span; 27 | ASSERT_TRUE(span.serviceName().empty()); 28 | ASSERT_TRUE(span.operationName().empty()); 29 | thrift::Span thriftSpan; 30 | ASSERT_NO_THROW(span.thrift(thriftSpan)); 31 | } 32 | 33 | } // namespace jaegertracing 34 | -------------------------------------------------------------------------------- /src/jaegertracing/Tag.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/Tag.h" 18 | #include "jaegertracing/thrift-gen/jaeger_types.h" 19 | 20 | namespace jaegertracing { 21 | class ThriftVisitor { 22 | public: 23 | using result_type = void; 24 | 25 | explicit ThriftVisitor(thrift::Tag& tag) 26 | : _tag(tag) 27 | { 28 | } 29 | 30 | void operator()(const std::string& value) const { setString(value); } 31 | 32 | void operator()(const char* value) const { setString(value); } 33 | 34 | void operator()(double value) const 35 | { 36 | _tag.__set_vType(thrift::TagType::DOUBLE); 37 | _tag.__set_vDouble(value); 38 | } 39 | 40 | void operator()(bool value) const 41 | { 42 | _tag.__set_vType(thrift::TagType::BOOL); 43 | _tag.__set_vBool(value); 44 | } 45 | 46 | void operator()(int64_t value) const { setLong(value); } 47 | 48 | void operator()(uint64_t value) const { setLong(value); } 49 | 50 | template 51 | void operator()(Arg&& value) const 52 | { 53 | // No-op 54 | } 55 | 56 | private: 57 | void setString(opentracing::string_view value) const 58 | { 59 | _tag.__set_vType(thrift::TagType::STRING); 60 | _tag.__set_vStr(value); 61 | } 62 | 63 | void setLong(int64_t value) const 64 | { 65 | _tag.__set_vType(thrift::TagType::LONG); 66 | _tag.__set_vLong(value); 67 | } 68 | 69 | thrift::Tag& _tag; 70 | }; 71 | 72 | void Tag::thrift(thrift::Tag& tag) const 73 | { 74 | tag.__set_key(_key); 75 | ThriftVisitor visitor(tag); 76 | opentracing::util::apply_visitor(visitor, _value); 77 | } 78 | 79 | } // namespace jaegertracing -------------------------------------------------------------------------------- /src/jaegertracing/Tag.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_TAG_H 18 | #define JAEGERTRACING_TAG_H 19 | 20 | #include "jaegertracing/Compilers.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace jaegertracing { 30 | namespace thrift { 31 | class Tag; 32 | } 33 | 34 | class Tag { 35 | public: 36 | using ValueType = opentracing::Value; 37 | 38 | template 39 | Tag(const std::string& key, ValueArg&& value) 40 | : _key(key) 41 | , _value(std::forward(value)) 42 | { 43 | } 44 | 45 | template 46 | Tag(const std::pair& tag_pair) 47 | : _key(tag_pair.first) 48 | , _value(tag_pair.second) 49 | { 50 | } 51 | 52 | bool operator==(const Tag& rhs) const 53 | { 54 | return _key == rhs._key && _value == rhs._value; 55 | } 56 | 57 | const std::string& key() const { return _key; } 58 | 59 | const ValueType& value() const { return _value; } 60 | 61 | void thrift(thrift::Tag& tag) const; 62 | 63 | private: 64 | std::string _key; 65 | ValueType _value; 66 | }; 67 | 68 | } // namespace jaegertracing 69 | 70 | #endif // JAEGERTRACING_TAG_H 71 | -------------------------------------------------------------------------------- /src/jaegertracing/TagTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/Tag.h" 18 | #include "jaegertracing/thrift-gen/jaeger_types.h" 19 | #include 20 | #include 21 | 22 | namespace jaegertracing { 23 | 24 | TEST(Tag, testThriftConversion) 25 | { 26 | const Tag tags[] = { { "testBool", true }, 27 | { "testDouble", 0.0 }, 28 | { "testInt64", 0LL }, 29 | { "testUint64", 0ULL }, 30 | { "testStr", std::string{ "test" } }, 31 | { "testNull", nullptr }, 32 | { "testCStr", "test" } }; 33 | 34 | for (auto&& tag : tags) { 35 | thrift::Tag thriftTag; 36 | ASSERT_NO_THROW(tag.thrift(thriftTag)); 37 | } 38 | } 39 | 40 | } // namespace jaegertracing 41 | -------------------------------------------------------------------------------- /src/jaegertracing/ThriftMethods.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/thrift-gen/BaggageRestrictionManager.h" 18 | #include "jaegertracing/thrift-gen/sampling_types.h" 19 | 20 | namespace jaegertracing { 21 | 22 | // trivial constructors of BaggageRestrictionManager thrift generated code are not generated by MSVC 23 | #ifdef _MSC_VER 24 | 25 | namespace thrift { 26 | 27 | BaggageRestrictionManager_getBaggageRestrictions_args:: 28 | BaggageRestrictionManager_getBaggageRestrictions_args( 29 | const BaggageRestrictionManager_getBaggageRestrictions_args& that) 30 | : serviceName(that.serviceName) 31 | { 32 | } 33 | 34 | BaggageRestrictionManager_getBaggageRestrictions_args& 35 | BaggageRestrictionManager_getBaggageRestrictions_args:: 36 | operator=(const BaggageRestrictionManager_getBaggageRestrictions_args& that) 37 | { 38 | this->serviceName = that.serviceName; 39 | return *this; 40 | } 41 | 42 | BaggageRestrictionManager_getBaggageRestrictions_result:: 43 | BaggageRestrictionManager_getBaggageRestrictions_result( 44 | const BaggageRestrictionManager_getBaggageRestrictions_result& that) 45 | : success(that.success) 46 | , __isset(that.__isset) 47 | { 48 | } 49 | BaggageRestrictionManager_getBaggageRestrictions_result& 50 | BaggageRestrictionManager_getBaggageRestrictions_result:: 51 | operator=(const BaggageRestrictionManager_getBaggageRestrictions_result& that) 52 | { 53 | this->success = that.success; 54 | return *this; 55 | } 56 | 57 | } // namespace thrift 58 | 59 | #endif // MSVC 60 | 61 | namespace sampling_manager { 62 | namespace thrift { 63 | 64 | const std::map& samplingStrategyType_VALUES_TO_NAMES() 65 | { 66 | return _SamplingStrategyType_VALUES_TO_NAMES; 67 | } 68 | 69 | } // namespace thrift 70 | } // namespace sampling_manager 71 | } // namespace jaegertracing 72 | -------------------------------------------------------------------------------- /src/jaegertracing/TraceID.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/TraceID.h" 18 | #include "jaegertracing/utils/HexParsing.h" 19 | #include 20 | #include 21 | #include 22 | 23 | namespace jaegertracing { 24 | 25 | TraceID TraceID::fromStream(std::istream& in) 26 | { 27 | TraceID traceID; 28 | constexpr auto kMaxChars = static_cast(32); 29 | auto buffer = utils::HexParsing::readSegment(in, kMaxChars, ':'); 30 | 31 | if (buffer.empty()) { 32 | return TraceID(); 33 | } 34 | 35 | if (buffer.size() < kMaxChars / 2) { 36 | traceID._low = utils::HexParsing::decodeHex(buffer); 37 | } 38 | else { 39 | auto beginLowStr = std::end(buffer) - kMaxChars / 2; 40 | const std::string highStr(std::begin(buffer), beginLowStr); 41 | traceID._high = utils::HexParsing::decodeHex(highStr); 42 | const std::string lowStr(beginLowStr, std::end(buffer)); 43 | traceID._low = utils::HexParsing::decodeHex(lowStr); 44 | } 45 | 46 | return traceID; 47 | } 48 | 49 | } // namespace jaegertracing 50 | -------------------------------------------------------------------------------- /src/jaegertracing/TraceID.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_TRACEID_H 18 | #define JAEGERTRACING_TRACEID_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace jaegertracing { 25 | 26 | class TraceID { 27 | public: 28 | static TraceID fromStream(std::istream& in); 29 | 30 | TraceID() 31 | : TraceID(0, 0) 32 | { 33 | } 34 | 35 | TraceID(uint64_t high, uint64_t low) 36 | : _high(high) 37 | , _low(low) 38 | { 39 | } 40 | 41 | bool isValid() const { return _high != 0 || _low != 0; } 42 | 43 | template 44 | void print(Stream& out) const 45 | { 46 | if (_high == 0) { 47 | out << std::setw(16) << std::setfill('0') << std::hex << _low; 48 | } 49 | else { 50 | out << std::setw(16) << std::setfill('0') << std::hex << _high 51 | << std::setw(16) << std::setfill('0') << std::hex << _low; 52 | } 53 | } 54 | 55 | uint64_t high() const { return _high; } 56 | 57 | uint64_t low() const { return _low; } 58 | 59 | bool operator==(const TraceID& rhs) const 60 | { 61 | return _high == rhs._high && _low == rhs._low; 62 | } 63 | 64 | private: 65 | uint64_t _high; 66 | uint64_t _low; 67 | }; 68 | 69 | } // namespace jaegertracing 70 | 71 | inline std::ostream& operator<<(std::ostream& out, 72 | const jaegertracing::TraceID& traceID) 73 | { 74 | traceID.print(out); 75 | return out; 76 | } 77 | 78 | inline std::istream& operator<<(std::istream& in, 79 | jaegertracing::TraceID& traceID) 80 | { 81 | traceID = jaegertracing::TraceID::fromStream(in); 82 | return in; 83 | } 84 | 85 | #endif // JAEGERTRACING_TRACEID_H 86 | -------------------------------------------------------------------------------- /src/jaegertracing/TraceIDTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/TraceID.h" 18 | #include 19 | #include 20 | 21 | namespace jaegertracing { 22 | 23 | TEST(TraceID, testPrintWithouthHigh) 24 | { 25 | std::ostringstream oss; 26 | oss << TraceID(0, 10); 27 | ASSERT_EQ("000000000000000a", oss.str()); 28 | } 29 | 30 | TEST(TraceID, testPrintWithHigh) 31 | { 32 | std::ostringstream oss; 33 | oss << TraceID(1, 10); 34 | ASSERT_EQ("0000000000000001000000000000000a", oss.str()); 35 | } 36 | 37 | } // namespace jaegertracing 38 | -------------------------------------------------------------------------------- /src/jaegertracing/TracerFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "TracerFactory.h" 18 | 19 | #include "jaegertracing/Tracer.h" 20 | 21 | namespace jaegertracing { 22 | 23 | opentracing::expected> 24 | TracerFactory::MakeTracer(const char* configuration, 25 | std::string& errorMessage) const noexcept try { 26 | #ifndef JAEGERTRACING_WITH_YAML_CPP 27 | errorMessage = 28 | "Failed to construct tracer: Jaeger was not build with yaml support."; 29 | return opentracing::make_unexpected( 30 | std::make_error_code(std::errc::not_supported)); 31 | #else 32 | YAML::Node yaml; 33 | try { 34 | yaml = YAML::Load(configuration); 35 | } catch (const YAML::ParserException& e) { 36 | errorMessage = e.what(); 37 | return opentracing::make_unexpected( 38 | opentracing::configuration_parse_error); 39 | } 40 | 41 | auto tracerConfig = jaegertracing::Config::parse(yaml); 42 | 43 | if (_readFromEnv) { 44 | tracerConfig.fromEnv(); 45 | } 46 | 47 | if (tracerConfig.serviceName().empty()) { 48 | errorMessage = "`service_name` not provided"; 49 | return opentracing::make_unexpected( 50 | opentracing::invalid_configuration_error); 51 | } 52 | 53 | return jaegertracing::Tracer::make(tracerConfig); 54 | #endif // JAEGERTRACING_WITH_YAML_CPP 55 | } catch (const std::bad_alloc&) { 56 | return opentracing::make_unexpected( 57 | std::make_error_code(std::errc::not_enough_memory)); 58 | } catch (const std::exception& e) { 59 | errorMessage = e.what(); 60 | return opentracing::make_unexpected( 61 | opentracing::invalid_configuration_error); 62 | } 63 | } // namespace jaegertracing 64 | -------------------------------------------------------------------------------- /src/jaegertracing/TracerFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_TRACER_FACTORY_H 18 | #define JAEGERTRACING_TRACER_FACTORY_H 19 | 20 | #include 21 | 22 | namespace jaegertracing { 23 | 24 | class TracerFactory : public opentracing::TracerFactory { 25 | public: 26 | opentracing::expected> 27 | MakeTracer(const char* configuration, std::string& errorMessage) const 28 | noexcept override; 29 | 30 | TracerFactory() 31 | : TracerFactory(false) 32 | { 33 | } 34 | 35 | TracerFactory(bool readFromEnv) 36 | : _readFromEnv(readFromEnv) 37 | { 38 | } 39 | private: 40 | bool _readFromEnv; 41 | }; 42 | 43 | } // namespace jaegertracing 44 | 45 | #endif // JAEGERTRACING_TRACER_FACTORY_H 46 | -------------------------------------------------------------------------------- /src/jaegertracing/baggage/BaggageSetter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/baggage/BaggageSetter.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/baggage/RemoteRestrictionJSON.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/baggage/RemoteRestrictionJSON.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/baggage/RemoteRestrictionJSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_BAGGAGE_REMOTERESTRICTIONJSON_H 18 | #define JAEGERTRACING_BAGGAGE_REMOTERESTRICTIONJSON_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "jaegertracing/Compilers.h" 26 | #include "jaegertracing/thrift-gen/BaggageRestrictionManager.h" 27 | #include "jaegertracing/thrift-gen/baggage_types.h" 28 | 29 | namespace jaegertracing { 30 | namespace thrift { 31 | 32 | inline void to_json(nlohmann::json& json, const BaggageRestriction& restriction) 33 | { 34 | json["baggageKey"] = restriction.baggageKey; 35 | json["maxValueLength"] = restriction.maxValueLength; 36 | } 37 | 38 | inline void from_json(const nlohmann::json& json, 39 | BaggageRestriction& restriction) 40 | { 41 | restriction.__set_baggageKey(json.at("baggageKey")); 42 | restriction.__set_maxValueLength(json.at("maxValueLength")); 43 | } 44 | 45 | using BaggageRestrictionList = 46 | BaggageRestrictionManager_getBaggageRestrictions_result; 47 | 48 | inline void to_json(nlohmann::json& json, const BaggageRestrictionList& list) 49 | { 50 | json = list.success; 51 | } 52 | 53 | inline void from_json(const nlohmann::json& json, BaggageRestrictionList& list) 54 | { 55 | list.success = json.get>(); 56 | list.__isset.success = true; 57 | } 58 | 59 | } // namespace thrift 60 | } // namespace jaegertracing 61 | 62 | #endif // JAEGERTRACING_BAGGAGE_REMOTERESTRICTIONJSON_H 63 | -------------------------------------------------------------------------------- /src/jaegertracing/baggage/Restriction.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/baggage/Restriction.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/baggage/Restriction.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_BAGGAGE_RESTRICTION_H 18 | #define JAEGERTRACING_BAGGAGE_RESTRICTION_H 19 | 20 | namespace jaegertracing { 21 | namespace baggage { 22 | 23 | class Restriction { 24 | public: 25 | Restriction(bool keyAllowed, int maxValueLength) 26 | : _keyAllowed(keyAllowed) 27 | , _maxValueLength(maxValueLength) 28 | { 29 | } 30 | 31 | friend bool operator==(const Restriction& lhs, const Restriction& rhs) 32 | { 33 | return lhs._keyAllowed == rhs._keyAllowed && 34 | lhs._maxValueLength == rhs._maxValueLength; 35 | } 36 | 37 | bool keyAllowed() const { return _keyAllowed; } 38 | 39 | int maxValueLength() const { return _maxValueLength; } 40 | 41 | private: 42 | bool _keyAllowed; 43 | int _maxValueLength; 44 | }; 45 | 46 | } // namespace baggage 47 | } // namespace jaegertracing 48 | 49 | #endif // JAEGERTRACING_BAGGAGE_RESTRICTION_H 50 | -------------------------------------------------------------------------------- /src/jaegertracing/baggage/RestrictionManager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/baggage/RestrictionManager.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/baggage/RestrictionManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_BAGGAGE_RESTRICTIONMANAGER_H 18 | #define JAEGERTRACING_BAGGAGE_RESTRICTIONMANAGER_H 19 | 20 | #include 21 | 22 | #include "jaegertracing/baggage/Restriction.h" 23 | 24 | namespace jaegertracing { 25 | namespace baggage { 26 | 27 | class RestrictionManager { 28 | public: 29 | virtual ~RestrictionManager() = default; 30 | 31 | virtual Restriction getRestriction(const std::string& service, 32 | const std::string& key) = 0; 33 | 34 | virtual void close() noexcept {} 35 | }; 36 | 37 | class DefaultRestrictionManager : public RestrictionManager { 38 | public: 39 | static constexpr auto kDefaultMaxValueLength = 2048; 40 | 41 | explicit DefaultRestrictionManager(int maxValueLength) 42 | : _defaultRestriction(true, 43 | maxValueLength == 0 ? kDefaultMaxValueLength 44 | : maxValueLength) 45 | { 46 | } 47 | 48 | Restriction getRestriction(const std::string& service, 49 | const std::string& key) override 50 | { 51 | return _defaultRestriction; 52 | } 53 | 54 | private: 55 | Restriction _defaultRestriction; 56 | }; 57 | 58 | } // namespace baggage 59 | } // namespace jaegertracing 60 | 61 | #endif // JAEGERTRACING_BAGGAGE_RESTRICTIONMANAGER_H 62 | -------------------------------------------------------------------------------- /src/jaegertracing/baggage/RestrictionsConfig.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/baggage/RestrictionsConfig.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/Counter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/metrics/Counter.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/Counter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_METRICS_COUNTER_H 18 | #define JAEGERTRACING_METRICS_COUNTER_H 19 | 20 | #include "jaegertracing/Compilers.h" 21 | 22 | #include 23 | 24 | namespace jaegertracing { 25 | namespace metrics { 26 | 27 | class Counter { 28 | public: 29 | virtual ~Counter() = default; 30 | 31 | virtual void inc(int64_t delta) = 0; 32 | }; 33 | 34 | } // namespace metrics 35 | } // namespace jaegertracing 36 | 37 | #endif // JAEGERTRACING_METRICS_COUNTER_H 38 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/Gauge.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/metrics/Gauge.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/Gauge.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_METRICS_GAUGE_H 18 | #define JAEGERTRACING_METRICS_GAUGE_H 19 | 20 | #include "jaegertracing/Compilers.h" 21 | 22 | #include 23 | 24 | namespace jaegertracing { 25 | namespace metrics { 26 | 27 | class Gauge { 28 | public: 29 | virtual ~Gauge() = default; 30 | 31 | virtual void update(int64_t amount) = 0; 32 | }; 33 | 34 | } // namespace metrics 35 | } // namespace jaegertracing 36 | 37 | #endif // JAEGERTRACING_METRICS_GAUGE_H 38 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/InMemoryStatsReporter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_METRICS_INMEMORYSTATSREPORTER_H 18 | #define JAEGERTRACING_METRICS_INMEMORYSTATSREPORTER_H 19 | 20 | #include "jaegertracing/metrics/StatsReporter.h" 21 | #include 22 | #include 23 | #include 24 | 25 | namespace jaegertracing { 26 | namespace metrics { 27 | 28 | class InMemoryStatsReporter : public StatsReporter { 29 | public: 30 | using ValueMap = std::unordered_map; 31 | 32 | using StatsReporter::incCounter; 33 | using StatsReporter::recordTimer; 34 | using StatsReporter::updateGauge; 35 | 36 | virtual ~InMemoryStatsReporter() = default; 37 | 38 | void incCounter(const std::string& name, 39 | int64_t delta, 40 | const TagMap& tags) override; 41 | 42 | void recordTimer(const std::string& name, 43 | int64_t time, 44 | const TagMap& tags) override; 45 | 46 | void updateGauge(const std::string& name, 47 | int64_t time, 48 | const TagMap& tags) override; 49 | 50 | void reset(); 51 | 52 | const ValueMap& counters() const { return _counters; } 53 | 54 | const ValueMap& gauges() const { return _gauges; } 55 | 56 | const ValueMap& timers() const { return _timers; } 57 | 58 | private: 59 | ValueMap _counters; 60 | ValueMap _gauges; 61 | ValueMap _timers; 62 | }; 63 | 64 | } // namespace metrics 65 | } // namespace jaegertracing 66 | 67 | #endif // JAEGERTRACING_METRICS_INMEMORYSTATSREPORTER_H 68 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/Metric.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/metrics/Metric.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/Metric.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_METRICS_METRIC_H 18 | #define JAEGERTRACING_METRICS_METRIC_H 19 | 20 | #include 21 | #include 22 | 23 | #include "jaegertracing/Compilers.h" 24 | 25 | namespace jaegertracing { 26 | namespace metrics { 27 | 28 | class Metric { 29 | public: 30 | using TagMap = std::unordered_map; 31 | 32 | Metric(const std::string& name, const TagMap& tags) 33 | : _name(name) 34 | , _tags(tags) 35 | { 36 | } 37 | 38 | virtual ~Metric() = default; 39 | 40 | const std::string& name() const { return _name; } 41 | 42 | const TagMap& tags() const { return _tags; } 43 | 44 | protected: 45 | std::string& name() { return _name; } 46 | 47 | TagMap& tags() { return _tags; } 48 | 49 | private: 50 | std::string _name; 51 | TagMap _tags; 52 | }; 53 | 54 | } // namespace metrics 55 | } // namespace jaegertracing 56 | 57 | #endif // JAEGERTRACING_METRICS_METRIC_H 58 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/Metrics.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/metrics/Metrics.h" 18 | #include "jaegertracing/metrics/Counter.h" 19 | #include "jaegertracing/metrics/Gauge.h" 20 | #include "jaegertracing/metrics/NullStatsFactory.h" 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace jaegertracing { 27 | namespace metrics { 28 | 29 | std::unique_ptr Metrics::makeNullMetrics() 30 | { 31 | metrics::NullStatsFactory factory; 32 | return std::unique_ptr(new Metrics(factory)); 33 | } 34 | 35 | std::string Metrics::addTagsToMetricName( 36 | const std::string& name, 37 | const std::unordered_map& tags) 38 | { 39 | std::ostringstream buffer; 40 | buffer << name; 41 | const std::map orderedMap(std::begin(tags), 42 | std::end(tags)); 43 | for (auto&& pair : orderedMap) { 44 | buffer << '.' << pair.first << '=' << pair.second; 45 | } 46 | return buffer.str(); 47 | } 48 | 49 | Metrics::~Metrics() = default; 50 | 51 | } // namespace metrics 52 | } // namespace jaegertracing 53 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/NullCounter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/metrics/NullCounter.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/NullCounter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_METRICS_NULLCOUNTER_H 18 | #define JAEGERTRACING_METRICS_NULLCOUNTER_H 19 | 20 | #include "jaegertracing/metrics/Counter.h" 21 | #include 22 | 23 | namespace jaegertracing { 24 | namespace metrics { 25 | 26 | class NullCounter : public Counter { 27 | public: 28 | void inc(int64_t) override {} 29 | }; 30 | 31 | } // namespace metrics 32 | } // namespace jaegertracing 33 | 34 | #endif // JAEGERTRACING_METRICS_NULLCOUNTER_H 35 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/NullGauge.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/metrics/NullGauge.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/NullGauge.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_METRICS_NULLGAUGE_H 18 | #define JAEGERTRACING_METRICS_NULLGAUGE_H 19 | 20 | #include "jaegertracing/metrics/Gauge.h" 21 | #include 22 | 23 | namespace jaegertracing { 24 | namespace metrics { 25 | 26 | class NullGauge : public Gauge { 27 | public: 28 | void update(int64_t) override {} 29 | }; 30 | 31 | } // namespace metrics 32 | } // namespace jaegertracing 33 | 34 | #endif // JAEGERTRACING_METRICS_NULLGAUGE_H 35 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/NullStatsFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/metrics/NullStatsFactory.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/NullStatsFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_METRICS_NULLSTATSFACTORY_H 18 | #define JAEGERTRACING_METRICS_NULLSTATSFACTORY_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "jaegertracing/metrics/NullCounter.h" 25 | #include "jaegertracing/metrics/NullGauge.h" 26 | #include "jaegertracing/metrics/NullTimer.h" 27 | #include "jaegertracing/metrics/StatsFactory.h" 28 | 29 | namespace jaegertracing { 30 | namespace metrics { 31 | 32 | class Counter; 33 | class Gauge; 34 | class Timer; 35 | 36 | class NullStatsFactory : public StatsFactory { 37 | public: 38 | using StatsFactory::createCounter; 39 | using StatsFactory::createGauge; 40 | using StatsFactory::createTimer; 41 | 42 | std::unique_ptr 43 | createCounter(const std::string&, 44 | const std::unordered_map&) override 45 | { 46 | return std::unique_ptr(new NullCounter()); 47 | } 48 | 49 | std::unique_ptr 50 | createTimer(const std::string&, 51 | const std::unordered_map&) override 52 | { 53 | return std::unique_ptr(new NullTimer()); 54 | } 55 | 56 | std::unique_ptr 57 | createGauge(const std::string&, 58 | const std::unordered_map&) override 59 | { 60 | return std::unique_ptr(new NullGauge()); 61 | } 62 | }; 63 | 64 | } // namespace metrics 65 | } // namespace jaegertracing 66 | 67 | #endif // JAEGERTRACING_METRICS_NULLSTATSFACTORY_H 68 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/NullStatsFactoryTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/metrics/Counter.h" 18 | #include "jaegertracing/metrics/Gauge.h" 19 | #include "jaegertracing/metrics/NullStatsFactory.h" 20 | #include "jaegertracing/metrics/Timer.h" 21 | #include 22 | #include 23 | 24 | namespace jaegertracing { 25 | namespace metrics { 26 | 27 | TEST(NullStatsFactory, test) 28 | { 29 | NullStatsFactory factory; 30 | factory.createGauge("")->update(1); 31 | factory.createTimer("")->record(1); 32 | factory.createCounter("")->inc(1); 33 | } 34 | 35 | } // namespace metrics 36 | } // namespace jaegertracing 37 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/NullStatsReporter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/metrics/NullStatsReporter.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/NullStatsReporter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_METRICS_NULLSTATSREPORTER_H 18 | #define JAEGERTRACING_METRICS_NULLSTATSREPORTER_H 19 | 20 | #include "jaegertracing/metrics/StatsReporter.h" 21 | #include 22 | #include 23 | #include 24 | 25 | namespace jaegertracing { 26 | namespace metrics { 27 | 28 | class NullStatsReporter : public StatsReporter { 29 | public: 30 | using StatsReporter::incCounter; 31 | using StatsReporter::recordTimer; 32 | using StatsReporter::updateGauge; 33 | 34 | ~NullStatsReporter() = default; 35 | 36 | void 37 | incCounter(const std::string&, 38 | int64_t, 39 | const std::unordered_map&) override 40 | { 41 | } 42 | 43 | void 44 | recordTimer(const std::string&, 45 | int64_t, 46 | const std::unordered_map&) override 47 | { 48 | } 49 | 50 | void 51 | updateGauge(const std::string&, 52 | int64_t, 53 | const std::unordered_map&) override 54 | { 55 | } 56 | }; 57 | 58 | } // namespace metrics 59 | } // namespace jaegertracing 60 | 61 | #endif // JAEGERTRACING_METRICS_NULLSTATSREPORTER_H 62 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/NullTimer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/metrics/NullTimer.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/NullTimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_METRICS_NULLTIMER_H 18 | #define JAEGERTRACING_METRICS_NULLTIMER_H 19 | 20 | #include "jaegertracing/metrics/Timer.h" 21 | #include 22 | 23 | namespace jaegertracing { 24 | namespace metrics { 25 | 26 | class NullTimer : public Timer { 27 | public: 28 | void record(int64_t) override {} 29 | }; 30 | 31 | } // namespace metrics 32 | } // namespace jaegertracing 33 | 34 | #endif // JAEGERTRACING_METRICS_NULLTIMER_H 35 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/StatsFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/metrics/StatsFactory.h" 18 | 19 | #include "jaegertracing/metrics/Counter.h" 20 | #include "jaegertracing/metrics/Gauge.h" 21 | #include "jaegertracing/metrics/Timer.h" 22 | 23 | namespace jaegertracing { 24 | namespace metrics { 25 | 26 | std::unique_ptr StatsFactory::createCounter(const std::string& name) 27 | { 28 | return createCounter(name, TagMap()); 29 | } 30 | 31 | std::unique_ptr StatsFactory::createTimer(const std::string& name) 32 | { 33 | return createTimer(name, TagMap()); 34 | } 35 | 36 | std::unique_ptr StatsFactory::createGauge(const std::string& name) 37 | { 38 | return createGauge(name, TagMap()); 39 | } 40 | 41 | } // namespace metrics 42 | } // namespace jaegertracing 43 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/StatsFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_METRICS_STATSFACTORY_H 18 | #define JAEGERTRACING_METRICS_STATSFACTORY_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "jaegertracing/Compilers.h" 25 | 26 | namespace jaegertracing { 27 | namespace metrics { 28 | 29 | class Counter; 30 | class Gauge; 31 | class Timer; 32 | 33 | class StatsFactory { 34 | public: 35 | using TagMap = std::unordered_map; 36 | 37 | virtual ~StatsFactory() = default; 38 | 39 | std::unique_ptr createCounter(const std::string& name); 40 | 41 | std::unique_ptr createTimer(const std::string& name); 42 | 43 | std::unique_ptr createGauge(const std::string& name); 44 | 45 | virtual std::unique_ptr createCounter(const std::string& name, 46 | const TagMap& tags) = 0; 47 | 48 | virtual std::unique_ptr createTimer(const std::string& name, 49 | const TagMap& tags) = 0; 50 | 51 | virtual std::unique_ptr createGauge(const std::string& name, 52 | const TagMap& tags) = 0; 53 | }; 54 | 55 | } // namespace metrics 56 | } // namespace jaegertracing 57 | 58 | #endif // JAEGERTRACING_METRICS_STATSFACTORY_H 59 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/StatsFactoryImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_METRICS_STATSFACTORYIMPL_H 18 | #define JAEGERTRACING_METRICS_STATSFACTORYIMPL_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "jaegertracing/metrics/StatsFactory.h" 25 | #include "jaegertracing/metrics/StatsReporter.h" 26 | 27 | namespace jaegertracing { 28 | namespace metrics { 29 | 30 | class Counter; 31 | class Gauge; 32 | class Timer; 33 | 34 | class StatsFactoryImpl : public StatsFactory { 35 | public: 36 | using StatsFactory::createCounter; 37 | using StatsFactory::createGauge; 38 | using StatsFactory::createTimer; 39 | 40 | explicit StatsFactoryImpl(StatsReporter& reporter); 41 | 42 | ~StatsFactoryImpl() = default; 43 | 44 | std::unique_ptr createCounter( 45 | const std::string& name, 46 | const std::unordered_map& tags) override; 47 | 48 | std::unique_ptr createTimer( 49 | const std::string& name, 50 | const std::unordered_map& tags) override; 51 | 52 | std::unique_ptr createGauge( 53 | const std::string& name, 54 | const std::unordered_map& tags) override; 55 | 56 | private: 57 | StatsReporter& _reporter; 58 | }; 59 | 60 | } // namespace metrics 61 | } // namespace jaegertracing 62 | 63 | #endif // JAEGERTRACING_METRICS_STATSFACTORYIMPL_H 64 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/StatsReporter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/metrics/StatsReporter.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/StatsReporter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_METRICS_STATSREPORTER_H 18 | #define JAEGERTRACING_METRICS_STATSREPORTER_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace jaegertracing { 25 | namespace metrics { 26 | 27 | class StatsReporter { 28 | public: 29 | using TagMap = std::unordered_map; 30 | 31 | virtual ~StatsReporter() = default; 32 | 33 | void incCounter(const std::string& name, int64_t delta) 34 | { 35 | incCounter(name, delta, TagMap()); 36 | } 37 | 38 | void recordTimer(const std::string& name, int64_t delta) 39 | { 40 | recordTimer(name, delta, TagMap()); 41 | } 42 | 43 | void updateGauge(const std::string& name, int64_t delta) 44 | { 45 | updateGauge(name, delta, TagMap()); 46 | } 47 | 48 | virtual void 49 | incCounter(const std::string& name, int64_t delta, const TagMap& tags) = 0; 50 | 51 | virtual void 52 | recordTimer(const std::string& name, int64_t time, const TagMap& tags) = 0; 53 | 54 | virtual void updateGauge(const std::string& name, 55 | int64_t amount, 56 | const TagMap& tags) = 0; 57 | }; 58 | 59 | } // namespace metrics 60 | } // namespace jaegertracing 61 | 62 | #endif // JAEGERTRACING_METRICS_STATSREPORTER_H 63 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/Timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/metrics/Timer.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/metrics/Timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_METRICS_TIMER_H 18 | #define JAEGERTRACING_METRICS_TIMER_H 19 | 20 | #include 21 | 22 | namespace jaegertracing { 23 | namespace metrics { 24 | 25 | class Timer { 26 | public: 27 | virtual ~Timer() = default; 28 | 29 | virtual void record(int64_t time) = 0; 30 | }; 31 | 32 | } // namespace metrics 33 | } // namespace jaegertracing 34 | 35 | #endif // JAEGERTRACING_METRICS_TIMER_H 36 | -------------------------------------------------------------------------------- /src/jaegertracing/net/IPAddressTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/net/IPAddress.h" 18 | #include 19 | #include 20 | 21 | namespace jaegertracing { 22 | namespace net { 23 | 24 | TEST(IPAddress, testParseFail) 25 | { 26 | ASSERT_THROW(IPAddress::v4("", 0), std::runtime_error); 27 | } 28 | 29 | TEST(IPAddress, testAuthority) 30 | { 31 | ASSERT_EQ("127.0.0.1", IPAddress::v4("127.0.0.1", 0).authority()); 32 | ASSERT_EQ("127.0.0.1:1234", IPAddress::v4("127.0.0.1", 1234).authority()); 33 | } 34 | 35 | TEST(IPAddress, testIPv6) 36 | { 37 | ASSERT_EQ("2001:db8:ac10:fe01::", 38 | IPAddress::v6("2001:db8:ac10:fe01::", 0).authority()); 39 | } 40 | 41 | TEST(IPAddress, testResolveAddress) 42 | { 43 | ASSERT_NO_THROW(resolveAddress("localhost", 80, AF_INET, SOCK_STREAM)); 44 | #ifdef WIN32 45 | ASSERT_THROW(resolveAddress("123456", 80, AF_INET, SOCK_STREAM), 46 | std::runtime_error); 47 | #else 48 | ASSERT_NO_THROW(resolveAddress("123456", 80, AF_INET, SOCK_STREAM)); 49 | #endif 50 | ASSERT_THROW(resolveAddress("localhost", 80, -1), std::runtime_error); 51 | } 52 | 53 | } // namespace net 54 | } // namespace jaegertracing 55 | -------------------------------------------------------------------------------- /src/jaegertracing/net/Socket.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/net/Socket.h" 18 | 19 | #ifdef WIN32 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #endif 27 | 28 | namespace jaegertracing { 29 | namespace net { 30 | 31 | namespace { 32 | 33 | 34 | void initSocket() 35 | { 36 | #ifdef WIN32 37 | /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */ 38 | WORD wVersionRequested = MAKEWORD(2, 2); 39 | 40 | WSADATA wsaData; 41 | int err = WSAStartup(wVersionRequested, &wsaData); 42 | if (err != 0) { 43 | std::ostringstream oss; 44 | oss << "Failed to find a usable Winsock DLL. WSAStartup failed with " 45 | "error " 46 | << err; 47 | throw std::system_error(errno, std::system_category(), oss.str()); 48 | } 49 | 50 | /* Confirm that the WinSock DLL supports 2.2.*/ 51 | /* Note that if the DLL supports versions greater */ 52 | /* than 2.2 in addition to 2.2, it will still return */ 53 | /* 2.2 in wVersion since that is the version we */ 54 | /* requested. */ 55 | 56 | if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) { 57 | WSACleanup(); 58 | 59 | std::ostringstream oss; 60 | oss << "Failed to find a usable Winsock DLL. WSAStartup failed with " 61 | "error " 62 | << err; 63 | throw std::system_error(errno, std::system_category(), oss.str()); 64 | } 65 | #endif 66 | } 67 | 68 | void cleanSocket() 69 | { 70 | #ifdef WIN32 71 | WSACleanup(); 72 | #endif 73 | } 74 | 75 | } 76 | 77 | 78 | Socket::OSResource::OSResource() { initSocket(); } 79 | 80 | Socket::OSResource::~OSResource() { cleanSocket(); } 81 | 82 | 83 | } // namespace net 84 | } // namespace jaegertracing 85 | -------------------------------------------------------------------------------- /src/jaegertracing/net/SocketTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/net/IPAddress.h" 18 | #include "jaegertracing/net/Socket.h" 19 | #include "jaegertracing/net/URI.h" 20 | #include 21 | #include 22 | #include 23 | 24 | namespace jaegertracing { 25 | namespace net { 26 | 27 | TEST(Socket, testFailOpen) 28 | { 29 | Socket socket; 30 | ASSERT_THROW(socket.open(-5, -10), std::system_error); 31 | } 32 | 33 | // On Windows, the bind does not throw 34 | #ifndef WIN32 35 | TEST(Socket, testFailBind) 36 | { 37 | Socket socket; 38 | socket.open(AF_INET, SOCK_STREAM); 39 | ASSERT_THROW(socket.bind(IPAddress::v4("127.0.0.1", 1)), std::system_error); 40 | } 41 | #endif 42 | 43 | TEST(Socket, testFailConnect) 44 | { 45 | Socket socket; 46 | socket.open(AF_INET, SOCK_STREAM); 47 | ASSERT_THROW(socket.connect(IPAddress::v4("127.0.0.1", 12345)), 48 | std::runtime_error); 49 | } 50 | 51 | TEST(Socket, testFailConnectURI) 52 | { 53 | Socket socket; 54 | socket.open(AF_INET, SOCK_STREAM); 55 | const auto uri = URI::parse("http://127.0.0.1:12345"); 56 | ASSERT_THROW(socket.connect(uri), std::runtime_error); 57 | } 58 | 59 | TEST(Socket, testFailListen) 60 | { 61 | Socket socket; 62 | socket.open(AF_INET, SOCK_DGRAM); 63 | ASSERT_THROW(socket.listen(), std::system_error); 64 | } 65 | 66 | TEST(Socket, testFailAccept) 67 | { 68 | Socket socket; 69 | socket.open(AF_INET, SOCK_DGRAM); 70 | ASSERT_THROW(socket.accept(), std::system_error); 71 | } 72 | 73 | } // namespace net 74 | } // namespace jaegertracing 75 | -------------------------------------------------------------------------------- /src/jaegertracing/net/http/Error.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/net/http/Error.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/net/http/Error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_NET_HTTP_ERROR_H 18 | #define JAEGERTRACING_NET_HTTP_ERROR_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace jaegertracing { 25 | namespace net { 26 | namespace http { 27 | 28 | class ParseError : public std::invalid_argument { 29 | public: 30 | using invalid_argument::invalid_argument; 31 | 32 | static ParseError make(const std::string& expected, 33 | const std::string& actual) 34 | { 35 | std::ostringstream oss; 36 | oss << "Parse error, expected " << expected << ", encountered \"" 37 | << actual << '"'; 38 | return ParseError(oss.str()); 39 | } 40 | }; 41 | 42 | } // namespace http 43 | } // namespace net 44 | } // namespace jaegertracing 45 | 46 | #endif // JAEGERTRACING_NET_HTTP_ERROR_H 47 | -------------------------------------------------------------------------------- /src/jaegertracing/net/http/Header.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/net/http/Header.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/net/http/HeaderTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/net/http/Header.h" 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace jaegertracing { 24 | namespace net { 25 | namespace http { 26 | 27 | class ParseError; 28 | 29 | TEST(Header, readLine) 30 | { 31 | std::stringstream ss; 32 | ss << "test\r123\r\n"; 33 | std::string line; 34 | while (readLineCRLF(ss, line)) { 35 | ASSERT_EQ("test\r123", line); 36 | } 37 | } 38 | 39 | TEST(Header, readHeaders) 40 | { 41 | std::stringstream ss; 42 | ss << "Bad Header\r\n"; 43 | std::vector
headers; 44 | ASSERT_THROW(readHeaders(ss, headers), ParseError); 45 | } 46 | 47 | } // namespace http 48 | } // namespace net 49 | } // namespace jaegertracing 50 | -------------------------------------------------------------------------------- /src/jaegertracing/net/http/Method.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/net/http/Method.h" 18 | #include 19 | #include 20 | #include 21 | 22 | namespace jaegertracing { 23 | namespace net { 24 | namespace http { 25 | 26 | Method parseMethod(const std::string& methodName) 27 | { 28 | #ifdef WIN32 29 | static constexpr char* kMethodNames[] = { "OPTIONS", "GET", "HEAD", 30 | "POST", "PUT", "DELETE", 31 | "TRACE", "CONNECT" }; 32 | #else 33 | static auto kMethodNames = { "OPTIONS", "GET", "HEAD", "POST", 34 | "PUT", "DELETE", "TRACE", "CONNECT" }; 35 | #endif 36 | 37 | 38 | auto itr = 39 | std::find(std::begin(kMethodNames), std::end(kMethodNames), methodName); 40 | if (itr == std::end(kMethodNames)) { 41 | return Method::EXTENSION; 42 | } 43 | return static_cast(std::distance(std::begin(kMethodNames), itr)); 44 | } 45 | 46 | } // namespace http 47 | } // namespace net 48 | } // namespace jaegertracing 49 | -------------------------------------------------------------------------------- /src/jaegertracing/net/http/Method.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_NET_HTTP_METHOD_H 18 | #define JAEGERTRACING_NET_HTTP_METHOD_H 19 | 20 | #include 21 | 22 | #undef DELETE 23 | 24 | namespace jaegertracing { 25 | namespace net { 26 | namespace http { 27 | 28 | enum class Method { 29 | OPTIONS, 30 | GET, 31 | HEAD, 32 | POST, 33 | PUT, 34 | DELETE, 35 | TRACE, 36 | CONNECT, 37 | EXTENSION 38 | }; 39 | 40 | Method parseMethod(const std::string& methodName); 41 | 42 | } // namespace http 43 | } // namespace net 44 | } // namespace jaegertracing 45 | 46 | #endif // JAEGERTRACING_NET_HTTP_METHOD_H 47 | -------------------------------------------------------------------------------- /src/jaegertracing/net/http/MethodTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/net/http/Method.h" 18 | #include 19 | 20 | namespace jaegertracing { 21 | namespace net { 22 | namespace http { 23 | 24 | TEST(Method, testParse) 25 | { 26 | ASSERT_EQ(Method::OPTIONS, parseMethod("OPTIONS")); 27 | ASSERT_EQ(Method::GET, parseMethod("GET")); 28 | ASSERT_EQ(Method::HEAD, parseMethod("HEAD")); 29 | ASSERT_EQ(Method::POST, parseMethod("POST")); 30 | ASSERT_EQ(Method::PUT, parseMethod("PUT")); 31 | ASSERT_EQ(Method::DELETE, parseMethod("DELETE")); 32 | ASSERT_EQ(Method::TRACE, parseMethod("TRACE")); 33 | ASSERT_EQ(Method::CONNECT, parseMethod("CONNECT")); 34 | ASSERT_EQ(Method::EXTENSION, parseMethod("post")); 35 | } 36 | 37 | } // namespace http 38 | } // namespace net 39 | } // namespace jaegertracing 40 | -------------------------------------------------------------------------------- /src/jaegertracing/net/http/Request.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/net/http/Request.h" 18 | #include "jaegertracing/net/http/SocketReader.h" 19 | 20 | #include 21 | 22 | namespace jaegertracing { 23 | namespace net { 24 | namespace http { 25 | 26 | Request Request::read(Socket & socket) 27 | { 28 | std::string response = SocketReader::read(socket); 29 | std::istringstream responseStream(response); 30 | return Request::parse(responseStream); 31 | } 32 | 33 | Request Request::parse(std::istream& in) 34 | { 35 | const std::regex requestLinePattern( 36 | "([A-Z]+) ([^ ]+) HTTP/([0-9]\\.[0-9])$"); 37 | std::string line; 38 | std::smatch match; 39 | if (!readLineCRLF(in, line) || 40 | !std::regex_match(line, match, requestLinePattern) || 41 | match.size() < 4) { 42 | throw ParseError::make("request line", line); 43 | } 44 | Request request; 45 | 46 | request._method = parseMethod(match[1]); 47 | request._target = match[2]; 48 | request._version = match[3]; 49 | 50 | readHeaders(in, request._headers); 51 | request._body = std::string(std::istreambuf_iterator(in), 52 | std::istreambuf_iterator{}); 53 | 54 | return request; 55 | } 56 | 57 | } // namespace http 58 | } // namespace net 59 | } // namespace jaegertracing 60 | -------------------------------------------------------------------------------- /src/jaegertracing/net/http/Request.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_NET_HTTP_REQUEST_H 18 | #define JAEGERTRACING_NET_HTTP_REQUEST_H 19 | 20 | #include "jaegertracing/net/URI.h" 21 | #include "jaegertracing/net/Socket.h" 22 | #include "jaegertracing/net/http/Error.h" 23 | #include "jaegertracing/net/http/Header.h" 24 | #include "jaegertracing/net/http/Method.h" 25 | 26 | namespace jaegertracing { 27 | namespace net { 28 | namespace http { 29 | 30 | class Request { 31 | public: 32 | static Request parse(std::istream& in); 33 | 34 | static Request read(Socket& in); 35 | 36 | Request() 37 | : _method() 38 | , _target() 39 | , _version() 40 | , _headers() 41 | { 42 | } 43 | 44 | Method method() const { return _method; } 45 | 46 | const std::string& target() const { return _target; } 47 | 48 | const std::string& version() const { return _version; } 49 | 50 | const std::vector
& headers() const { return _headers; } 51 | 52 | const std::string& body() const { return _body; } 53 | 54 | private: 55 | Method _method; 56 | std::string _target; 57 | std::string _version; 58 | std::vector
_headers; 59 | std::string _body; 60 | }; 61 | 62 | } // namespace http 63 | } // namespace net 64 | } // namespace jaegertracing 65 | 66 | #endif // JAEGERTRACING_NET_HTTP_REQUEST_H 67 | -------------------------------------------------------------------------------- /src/jaegertracing/net/http/Response.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_NET_HTTP_RESPONSE_H 18 | #define JAEGERTRACING_NET_HTTP_RESPONSE_H 19 | 20 | #include "jaegertracing/net/URI.h" 21 | #include "jaegertracing/net/Socket.h" 22 | #include "jaegertracing/net/http/Error.h" 23 | #include "jaegertracing/net/http/Header.h" 24 | #include "jaegertracing/net/http/Method.h" 25 | 26 | namespace jaegertracing { 27 | namespace net { 28 | namespace http { 29 | 30 | class Response { 31 | public: 32 | static Response parse(std::istream& in); 33 | 34 | Response() 35 | : _version() 36 | , _statusCode(0) 37 | , _reason() 38 | , _headers() 39 | , _body() 40 | { 41 | } 42 | 43 | int statusCode() const { return _statusCode; } 44 | 45 | const std::string& reason() const { return _reason; } 46 | 47 | const std::vector
& headers() const { return _headers; } 48 | 49 | const std::string& body() const { return _body; } 50 | 51 | private: 52 | std::string _version; 53 | int _statusCode; 54 | std::string _reason; 55 | std::vector
_headers; 56 | std::string _body; 57 | }; 58 | 59 | Response get(const URI& uri); 60 | 61 | /** 62 | * Reads http response from a socket 63 | */ 64 | Response read(Socket& socket); 65 | 66 | } // namespace http 67 | } // namespace net 68 | } // namespace jaegertracing 69 | 70 | #endif // JAEGERTRACING_NET_HTTP_RESPONSE_H 71 | -------------------------------------------------------------------------------- /src/jaegertracing/net/http/SocketReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, The Jaeger Authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_NET_HTTP_SOCKET_READER_H 18 | #define JAEGERTRACING_NET_HTTP_SOCKET_READER_H 19 | 20 | #include "jaegertracing/net/Socket.h" 21 | 22 | namespace jaegertracing { 23 | namespace net { 24 | namespace http { 25 | 26 | class SocketReader { 27 | public: 28 | static std::string read(Socket& socket) { 29 | constexpr auto kBufferSize = 1024; 30 | std::array buffer{}; 31 | auto numRead = ::recv(socket.handle(), &buffer[0], buffer.size(), 0); 32 | std::string response; 33 | while (numRead > 0) { 34 | response.append(&buffer[0], numRead); 35 | if (numRead < static_cast(buffer.size())) { 36 | break; 37 | } 38 | numRead = ::recv(socket.handle(), &buffer[0], buffer.size(), 0); 39 | } 40 | return response; 41 | } 42 | }; 43 | 44 | } // namespace http 45 | } // namespace net 46 | } // namespace jaegertracing 47 | 48 | #endif // JAEGERTRACING_NET_HTTP_SOCKET_READER_H 49 | -------------------------------------------------------------------------------- /src/jaegertracing/platform/Endian.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/platform/Endian.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/platform/Endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_PLATFORM_ENDIAN_H 18 | #define JAEGERTRACING_PLATFORM_ENDIAN_H 19 | 20 | #include 21 | 22 | #if defined(__APPLE__) 23 | 24 | #include 25 | #define htobe16(x) OSSwapHostToBigInt16(x) 26 | #define htobe32(x) OSSwapHostToBigInt32(x) 27 | #define htobe64(x) OSSwapHostToBigInt64(x) 28 | #define be16toh(x) OSSwapBigToHostInt16(x) 29 | #define be32toh(x) OSSwapBigToHostInt32(x) 30 | #define be64toh(x) OSSwapBigToHostInt64(x) 31 | 32 | #elif defined(__linux__) 33 | #include 34 | #elif defined WIN32 35 | #include 36 | 37 | #if BYTE_ORDER == LITTLE_ENDIAN 38 | 39 | #define htobe16(x) htons(x) 40 | #define be16toh(x) ntohs(x) 41 | 42 | #define htobe32(x) htonl(x) 43 | #define be32toh(x) ntohl(x) 44 | 45 | #define htobe64(x) htonll(x) 46 | #define be64toh(x) ntohll(x) 47 | #elif BYTE_ORDER == BIG_ENDIAN 48 | #define htobe16(x) (x) 49 | #define be16toh(x) (x) 50 | 51 | #define htobe32(x) (x) 52 | #define be32toh(x) (x) 53 | 54 | #define htobe64(x) (x) 55 | #define be64toh(x) (x) 56 | #else 57 | #error byte order not supported 58 | #endif 59 | #else 60 | #error "unsupported platform" 61 | #endif 62 | 63 | namespace jaegertracing { 64 | namespace platform { 65 | namespace endian { 66 | 67 | inline uint16_t toBigEndian(uint16_t value) { return htobe16(value); } 68 | 69 | inline uint32_t toBigEndian(uint32_t value) { return htobe32(value); } 70 | 71 | inline uint64_t toBigEndian(uint64_t value) { return htobe64(value); } 72 | 73 | inline uint16_t fromBigEndian(uint16_t value) { return be16toh(value); } 74 | 75 | inline uint32_t fromBigEndian(uint32_t value) { return be32toh(value); } 76 | 77 | inline uint64_t fromBigEndian(uint64_t value) { return be64toh(value); } 78 | 79 | } // namespace endian 80 | } // namespace platform 81 | } // namespace jaegertracing 82 | 83 | #endif // JAEGERTRACING_PLATFORM_ENDIAN_H 84 | -------------------------------------------------------------------------------- /src/jaegertracing/platform/Hostname.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/platform/Hostname.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/platform/Hostname.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_PLATFORM_HOSTNAME_H 18 | #define JAEGERTRACING_PLATFORM_HOSTNAME_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #ifdef WIN32 25 | #include 26 | #else 27 | #include 28 | #endif 29 | 30 | #ifdef _MSC_VER 31 | #pragma warning(push) 32 | #pragma warning(disable : 4267) 33 | #endif 34 | 35 | namespace jaegertracing { 36 | namespace platform { 37 | 38 | inline std::string hostname() 39 | { 40 | constexpr auto kBufferSize = 256; 41 | std::string buffer(kBufferSize, '\0'); 42 | const auto returnCode = ::gethostname(&buffer[0], buffer.size()); 43 | if (returnCode != 0) { 44 | throw std::system_error( 45 | errno, std::system_category(), "Failed to get hostname"); 46 | } 47 | const auto nullPos = buffer.find('\0'); 48 | return buffer.substr(0, nullPos); 49 | } 50 | 51 | } // namespace platform 52 | } // namespace jaegertracing 53 | 54 | #ifdef _MSC_VER 55 | #pragma warning(pop) 56 | #endif 57 | 58 | #endif // JAEGERTRACING_PLATFORM_HOSTNAME_H 59 | -------------------------------------------------------------------------------- /src/jaegertracing/propagation/Extractor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/propagation/Extractor.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/propagation/Extractor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_PROPAGATION_EXTRACTOR_H 18 | #define JAEGERTRACING_PROPAGATION_EXTRACTOR_H 19 | 20 | #include 21 | 22 | #include "jaegertracing/SpanContext.h" 23 | 24 | namespace jaegertracing { 25 | namespace propagation { 26 | 27 | template 28 | class Extractor { 29 | public: 30 | virtual ~Extractor() = default; 31 | 32 | virtual SpanContext extract(Reader reader) const = 0; 33 | }; 34 | 35 | } // namespace propagation 36 | } // namespace jaegertracing 37 | 38 | #endif // JAEGERTRACING_PROPAGATION_EXTRACTOR_H 39 | -------------------------------------------------------------------------------- /src/jaegertracing/propagation/Format.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2020 The Jaeger Authors 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "jaegertracing/propagation/Format.h" 19 | -------------------------------------------------------------------------------- /src/jaegertracing/propagation/Format.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 The Jaeger Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_PROPAGATION_FORMAT_H 18 | #define JAEGERTRACING_PROPAGATION_FORMAT_H 19 | 20 | namespace jaegertracing { 21 | namespace propagation { 22 | 23 | enum Format { JAEGER, W3C }; 24 | 25 | } // namespace propagation 26 | } // namespace jaegertracing 27 | 28 | #endif // JAEGERTRACING_PROPAGATION_FORMAT_H -------------------------------------------------------------------------------- /src/jaegertracing/propagation/HeadersConfig.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/propagation/HeadersConfig.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/propagation/Injector.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/propagation/Injector.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/propagation/Injector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_PROPAGATION_INJECTOR_H 18 | #define JAEGERTRACING_PROPAGATION_INJECTOR_H 19 | 20 | #include 21 | 22 | namespace jaegertracing { 23 | 24 | class SpanContext; 25 | 26 | namespace propagation { 27 | 28 | template 29 | class Injector { 30 | public: 31 | virtual ~Injector() = default; 32 | 33 | virtual void inject(const SpanContext& ctx, Writer writer) const = 0; 34 | }; 35 | 36 | } // namespace propagation 37 | } // namespace jaegertracing 38 | 39 | #endif // JAEGERTRACING_PROPAGATION_INJECTOR_H 40 | -------------------------------------------------------------------------------- /src/jaegertracing/propagation/JaegerPropagator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 The Jaeger Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/propagation/JaegerPropagator.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/propagation/Propagator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/propagation/Propagator.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/propagation/W3CPropagator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 The Jaeger Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/propagation/W3CPropagator.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/reporters/CompositeReporter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/reporters/CompositeReporter.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/reporters/CompositeReporter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_REPORTERS_COMPOSITEREPORTER_H 18 | #define JAEGERTRACING_REPORTERS_COMPOSITEREPORTER_H 19 | 20 | #include "jaegertracing/reporters/Reporter.h" 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace jaegertracing { 27 | class Span; 28 | } // namespace jaegertracing 29 | 30 | namespace jaegertracing { 31 | namespace reporters { 32 | 33 | class CompositeReporter : public Reporter { 34 | public: 35 | using ReporterPtr = std::shared_ptr; 36 | 37 | explicit CompositeReporter(const std::vector& reporters) 38 | : _reporters(reporters) 39 | { 40 | } 41 | 42 | ~CompositeReporter() { close(); } 43 | 44 | void report(const Span& span) noexcept override 45 | { 46 | std::for_each( 47 | std::begin(_reporters), 48 | std::end(_reporters), 49 | [&span](const ReporterPtr& reporter) { reporter->report(span); }); 50 | } 51 | 52 | void close() noexcept override 53 | { 54 | std::for_each(std::begin(_reporters), 55 | std::end(_reporters), 56 | [](const ReporterPtr& reporter) { reporter->close(); }); 57 | } 58 | 59 | private: 60 | std::vector _reporters; 61 | }; 62 | 63 | } // namespace reporters 64 | } // namespace jaegertracing 65 | 66 | #endif // JAEGERTRACING_REPORTERS_COMPOSITEREPORTER_H 67 | -------------------------------------------------------------------------------- /src/jaegertracing/reporters/ConfigTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, The Jaeger Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "jaegertracing/reporters/Config.h" 24 | 25 | namespace jaegertracing { 26 | namespace reporters { 27 | 28 | TEST(Config, testLoadConfig) 29 | { 30 | std::string yamlConfig = 31 | "disabled: false\n" 32 | "reporter:\n" 33 | " logSpans: true\n" 34 | " bufferFlushInterval: 88\n" 35 | " localAgentHostPort: ahost:22\n" 36 | " endpoint: http://somehost:33/api/traces\n" 37 | "sampler:\n" 38 | " type: const\n" 39 | " param: 1"; 40 | 41 | auto configYAML = YAML::Load(yamlConfig); 42 | auto reporterYAML = configYAML["reporter"]; 43 | auto config = jaegertracing::reporters::Config::parse(reporterYAML); 44 | 45 | ASSERT_EQ(true, config.logSpans()); 46 | ASSERT_EQ(std::chrono::seconds(88), config.bufferFlushInterval()); 47 | ASSERT_EQ(std::string("ahost:22"), config.localAgentHostPort()); 48 | ASSERT_EQ(std::string("http://somehost:33/api/traces"), config.endpoint()); 49 | } 50 | 51 | } // namespace reporters 52 | } // namespace jaegertracing 53 | -------------------------------------------------------------------------------- /src/jaegertracing/reporters/InMemoryReporter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/reporters/InMemoryReporter.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/reporters/InMemoryReporter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_REPORTERS_INMEMORYREPORTER_H 18 | #define JAEGERTRACING_REPORTERS_INMEMORYREPORTER_H 19 | 20 | #include 21 | #include 22 | 23 | #include "jaegertracing/Span.h" 24 | #include "jaegertracing/reporters/Reporter.h" 25 | 26 | namespace jaegertracing { 27 | namespace reporters { 28 | 29 | class InMemoryReporter : public Reporter { 30 | public: 31 | InMemoryReporter() 32 | : _spans() 33 | , _mutex() 34 | { 35 | constexpr auto kInitialCapacity = 10; 36 | _spans.reserve(kInitialCapacity); 37 | } 38 | 39 | void report(const Span& span) noexcept override 40 | { 41 | std::lock_guard lock(_mutex); 42 | _spans.push_back(span); 43 | } 44 | 45 | void close() noexcept override {} 46 | 47 | int spansSubmitted() const noexcept 48 | { 49 | std::lock_guard lock(_mutex); 50 | return _spans.size(); 51 | } 52 | 53 | std::vector spans() const noexcept 54 | { 55 | std::lock_guard lock(_mutex); 56 | return _spans; 57 | } 58 | 59 | void reset() noexcept 60 | { 61 | std::lock_guard lock(_mutex); 62 | _spans.clear(); 63 | } 64 | 65 | private: 66 | std::vector _spans; 67 | mutable std::mutex _mutex; 68 | }; 69 | 70 | } // namespace reporters 71 | } // namespace jaegertracing 72 | 73 | #endif // JAEGERTRACING_REPORTERS_INMEMORYREPORTER_H 74 | -------------------------------------------------------------------------------- /src/jaegertracing/reporters/LoggingReporter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/reporters/LoggingReporter.h" 18 | #include "jaegertracing/Logging.h" 19 | #include "jaegertracing/Span.h" 20 | #include 21 | 22 | namespace jaegertracing { 23 | namespace reporters { 24 | 25 | void LoggingReporter::report(const Span& span) noexcept 26 | { 27 | std::ostringstream oss; 28 | oss << "Reporting span " << span; 29 | _logger.info(oss.str()); 30 | } 31 | 32 | } // namespace reporters 33 | } // namespace jaegertracing 34 | -------------------------------------------------------------------------------- /src/jaegertracing/reporters/LoggingReporter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_REPORTERS_LOGGINGREPORTER_H 18 | #define JAEGERTRACING_REPORTERS_LOGGINGREPORTER_H 19 | 20 | #include "jaegertracing/Logging.h" 21 | #include "jaegertracing/reporters/Reporter.h" 22 | 23 | namespace jaegertracing { 24 | namespace reporters { 25 | 26 | class LoggingReporter : public Reporter { 27 | public: 28 | explicit LoggingReporter(logging::Logger& logger) 29 | : _logger(logger) 30 | { 31 | } 32 | 33 | void report(const Span& span) noexcept override; 34 | 35 | void close() noexcept override {} 36 | 37 | private: 38 | logging::Logger& _logger; 39 | }; 40 | 41 | } // namespace reporters 42 | } // namespace jaegertracing 43 | 44 | #endif // JAEGERTRACING_REPORTERS_LOGGINGREPORTER_H 45 | -------------------------------------------------------------------------------- /src/jaegertracing/reporters/NullReporter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/reporters/NullReporter.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/reporters/NullReporter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_REPORTERS_NULLREPORTER_H 18 | #define JAEGERTRACING_REPORTERS_NULLREPORTER_H 19 | 20 | #include "jaegertracing/reporters/Reporter.h" 21 | 22 | namespace jaegertracing { 23 | class Span; 24 | } // namespace jaegertracing 25 | 26 | namespace jaegertracing { 27 | namespace reporters { 28 | 29 | class NullReporter : public Reporter { 30 | public: 31 | void report(const Span&) noexcept override {} 32 | 33 | void close() noexcept override {} 34 | }; 35 | 36 | } // namespace reporters 37 | } // namespace jaegertracing 38 | 39 | #endif // JAEGERTRACING_REPORTERS_NULLREPORTER_H 40 | -------------------------------------------------------------------------------- /src/jaegertracing/reporters/Reporter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/reporters/Reporter.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/reporters/Reporter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_REPORTERS_REPORTER_H 18 | #define JAEGERTRACING_REPORTERS_REPORTER_H 19 | 20 | #include "jaegertracing/Compilers.h" 21 | 22 | namespace jaegertracing { 23 | 24 | class Span; 25 | 26 | namespace reporters { 27 | 28 | class Reporter { 29 | public: 30 | virtual ~Reporter() = default; 31 | 32 | virtual void report(const Span& span) noexcept = 0; 33 | 34 | virtual void close() noexcept = 0; 35 | }; 36 | 37 | } // namespace reporters 38 | } // namespace jaegertracing 39 | 40 | #endif // JAEGERTRACING_REPORTERS_REPORTER_H 41 | -------------------------------------------------------------------------------- /src/jaegertracing/samplers/AdaptiveSampler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_SAMPLERS_ADAPTIVESAMPLER_H 18 | #define JAEGERTRACING_SAMPLERS_ADAPTIVESAMPLER_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "jaegertracing/Compilers.h" 25 | 26 | #include "jaegertracing/Constants.h" 27 | #include "jaegertracing/samplers/GuaranteedThroughputProbabilisticSampler.h" 28 | #include "jaegertracing/samplers/ProbabilisticSampler.h" 29 | #include "jaegertracing/samplers/Sampler.h" 30 | 31 | namespace jaegertracing { 32 | namespace sampling_manager { 33 | namespace thrift { 34 | class PerOperationSamplingStrategies; 35 | } 36 | } // namespace sampling_manager 37 | 38 | namespace samplers { 39 | 40 | class AdaptiveSampler : public Sampler { 41 | public: 42 | using PerOperationSamplingStrategies = 43 | sampling_manager::thrift::PerOperationSamplingStrategies; 44 | using SamplerMap = std::unordered_map< 45 | std::string, 46 | std::shared_ptr>; 47 | 48 | AdaptiveSampler(const PerOperationSamplingStrategies& strategies, 49 | size_t maxOperations); 50 | 51 | ~AdaptiveSampler() { close(); } 52 | 53 | SamplingStatus isSampled(const TraceID& id, 54 | const std::string& operation) override; 55 | 56 | void close() override; 57 | 58 | void update(const PerOperationSamplingStrategies& strategies); 59 | 60 | Type type() const override { return Type::kAdaptiveSampler; } 61 | 62 | private: 63 | SamplerMap _samplers; 64 | ProbabilisticSampler _defaultSampler; 65 | double _lowerBound; 66 | size_t _maxOperations; 67 | std::mutex _mutex; 68 | }; 69 | 70 | } // namespace samplers 71 | } // namespace jaegertracing 72 | 73 | #endif // JAEGERTRACING_SAMPLERS_ADAPTIVESAMPLER_H 74 | -------------------------------------------------------------------------------- /src/jaegertracing/samplers/Config.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/samplers/Config.h" 18 | #include "jaegertracing/utils/EnvVariable.h" 19 | 20 | namespace jaegertracing { 21 | namespace samplers { 22 | 23 | constexpr double Config::kDefaultSamplingProbability; 24 | constexpr const char* Config::kDefaultSamplingServerURL; 25 | 26 | constexpr const char* Config::kJAEGER_SAMPLER_TYPE_ENV_PROP; 27 | constexpr const char* Config::kJAEGER_SAMPLER_PARAM_ENV_PROP; 28 | 29 | void Config::fromEnv() 30 | { 31 | const auto samplerType = utils::EnvVariable::getStringVariable(kJAEGER_SAMPLER_TYPE_ENV_PROP); 32 | if (!samplerType.empty()) { 33 | _type = samplerType; 34 | } 35 | 36 | const auto param = utils::EnvVariable::getStringVariable(kJAEGER_SAMPLER_PARAM_ENV_PROP); 37 | if (!param.empty()) { 38 | std::istringstream iss(param); 39 | double paramVal = 0; 40 | if (iss >> paramVal) { 41 | _param = paramVal; 42 | } 43 | } 44 | const auto samplingServerURL = utils::EnvVariable::getStringVariable(kJAEGER_SAMPLING_ENDPOINT_ENV_PROP); 45 | if (!samplingServerURL.empty()) { 46 | _samplingServerURL = samplingServerURL; 47 | } 48 | } 49 | 50 | } // namespace samplers 51 | } // namespace jaegertracing 52 | -------------------------------------------------------------------------------- /src/jaegertracing/samplers/ConstSampler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/samplers/ConstSampler.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/samplers/ConstSampler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_SAMPLERS_CONSTSAMPLER_H 18 | #define JAEGERTRACING_SAMPLERS_CONSTSAMPLER_H 19 | 20 | #include "jaegertracing/Constants.h" 21 | #include "jaegertracing/Tag.h" 22 | #include "jaegertracing/samplers/Sampler.h" 23 | #include "jaegertracing/samplers/SamplingStatus.h" 24 | #include 25 | #include 26 | 27 | namespace jaegertracing { 28 | class TraceID; 29 | } // namespace jaegertracing 30 | 31 | namespace jaegertracing { 32 | namespace samplers { 33 | 34 | class ConstSampler : public Sampler { 35 | public: 36 | explicit ConstSampler(bool sample) 37 | : _decision(sample) 38 | , _tags({ { kSamplerTypeTagKey, kSamplerTypeConst }, 39 | { kSamplerParamTagKey, _decision } }) 40 | { 41 | } 42 | 43 | SamplingStatus isSampled(const TraceID& id, 44 | const std::string& operation) override 45 | { 46 | return SamplingStatus(_decision, _tags); 47 | } 48 | 49 | void close() override {} 50 | 51 | Type type() const override { return Type::kConstSampler; } 52 | 53 | private: 54 | bool _decision; 55 | std::vector _tags; 56 | }; 57 | 58 | } // namespace samplers 59 | } // namespace jaegertracing 60 | 61 | #endif // JAEGERTRACING_SAMPLERS_CONSTSAMPLER_H 62 | -------------------------------------------------------------------------------- /src/jaegertracing/samplers/GuaranteedThroughputProbabilisticSampler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/samplers/GuaranteedThroughputProbabilisticSampler.h" 18 | 19 | namespace jaegertracing { 20 | namespace samplers { 21 | 22 | void GuaranteedThroughputProbabilisticSampler::update(double lowerBound, 23 | double samplingRate) 24 | { 25 | if (_samplingRate != samplingRate) { 26 | _probabilisticSampler = ProbabilisticSampler(samplingRate); 27 | _samplingRate = _probabilisticSampler.samplingRate(); 28 | _tags = { { kSamplerTypeTagKey, kSamplerTypeLowerBound }, 29 | { kSamplerParamTagKey, _samplingRate } }; 30 | } 31 | 32 | if (_lowerBound != lowerBound) { 33 | _lowerBoundSampler.reset(new RateLimitingSampler(lowerBound)); 34 | _lowerBound = lowerBound; 35 | } 36 | } 37 | 38 | } // namespace samplers 39 | } // namespace jaegertracing 40 | -------------------------------------------------------------------------------- /src/jaegertracing/samplers/ProbabilisticSampler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/samplers/ProbabilisticSampler.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/samplers/RateLimitingSampler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/samplers/RateLimitingSampler.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/samplers/RateLimitingSampler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_SAMPLERS_RATELIMITINGSAMPLER_H 18 | #define JAEGERTRACING_SAMPLERS_RATELIMITINGSAMPLER_H 19 | 20 | #include "jaegertracing/Compilers.h" 21 | 22 | #include "jaegertracing/Constants.h" 23 | #include "jaegertracing/Tag.h" 24 | #include "jaegertracing/samplers/Sampler.h" 25 | #include "jaegertracing/samplers/SamplingStatus.h" 26 | #include "jaegertracing/utils/RateLimiter.h" 27 | #include 28 | #include 29 | #include 30 | 31 | namespace jaegertracing { 32 | class TraceID; 33 | } // namespace jaegertracing 34 | 35 | namespace jaegertracing { 36 | namespace samplers { 37 | 38 | class RateLimitingSampler : public Sampler { 39 | public: 40 | explicit RateLimitingSampler(double maxTracesPerSecond) 41 | : _maxTracesPerSecond(maxTracesPerSecond) 42 | , _rateLimiter(_maxTracesPerSecond, std::max(_maxTracesPerSecond, 1.0)) 43 | , _tags({ { kSamplerTypeTagKey, kSamplerTypeRateLimiting }, 44 | { kSamplerParamTagKey, maxTracesPerSecond } }) 45 | { 46 | } 47 | 48 | SamplingStatus isSampled(const TraceID& id, 49 | const std::string& operation) override 50 | { 51 | return SamplingStatus(_rateLimiter.checkCredit(1), _tags); 52 | } 53 | 54 | void close() override {} 55 | 56 | Type type() const override { return Type::kRateLimitingSampler; } 57 | 58 | private: 59 | double _maxTracesPerSecond; 60 | utils::RateLimiter<> _rateLimiter; 61 | std::vector _tags; 62 | }; 63 | 64 | } // namespace samplers 65 | } // namespace jaegertracing 66 | 67 | #endif // JAEGERTRACING_SAMPLERS_RATELIMITINGSAMPLER_H 68 | -------------------------------------------------------------------------------- /src/jaegertracing/samplers/RemoteSamplingJSON.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/samplers/RemoteSamplingJSON.h" -------------------------------------------------------------------------------- /src/jaegertracing/samplers/Sampler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/samplers/Sampler.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/samplers/Sampler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_SAMPLERS_SAMPLER_H 18 | #define JAEGERTRACING_SAMPLERS_SAMPLER_H 19 | 20 | #include "jaegertracing/Compilers.h" 21 | 22 | #include "jaegertracing/TraceID.h" 23 | #include "jaegertracing/samplers/SamplingStatus.h" 24 | 25 | namespace jaegertracing { 26 | namespace samplers { 27 | 28 | class Sampler { 29 | public: 30 | enum class Type { 31 | kAdaptiveSampler, 32 | kConstSampler, 33 | kGuaranteedThroughputProbabilisticSampler, 34 | kProbabilisticSampler, 35 | kRateLimitingSampler, 36 | kRemotelyControlledSampler 37 | }; 38 | 39 | virtual ~Sampler() = default; 40 | 41 | virtual SamplingStatus isSampled(const TraceID& id, 42 | const std::string& operation) = 0; 43 | 44 | virtual void close() = 0; 45 | 46 | virtual Type type() const = 0; 47 | }; 48 | 49 | } // namespace samplers 50 | } // namespace jaegertracing 51 | 52 | #endif // JAEGERTRACING_SAMPLERS_SAMPLER_H 53 | -------------------------------------------------------------------------------- /src/jaegertracing/samplers/SamplingStatus.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/samplers/SamplingStatus.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/samplers/SamplingStatus.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_SAMPLERS_SAMPLINGSTATUS_H 18 | #define JAEGERTRACING_SAMPLERS_SAMPLINGSTATUS_H 19 | 20 | #include 21 | 22 | #include "jaegertracing/Compilers.h" 23 | 24 | #include "jaegertracing/Tag.h" 25 | 26 | namespace jaegertracing { 27 | namespace samplers { 28 | 29 | class SamplingStatus { 30 | public: 31 | SamplingStatus(bool isSampled, const std::vector& tags) 32 | : _isSampled(isSampled) 33 | , _tags(tags) 34 | { 35 | } 36 | 37 | bool isSampled() const { return _isSampled; } 38 | 39 | const std::vector& tags() const { return _tags; } 40 | 41 | private: 42 | bool _isSampled; 43 | std::vector _tags; 44 | }; 45 | 46 | } // namespace samplers 47 | } // namespace jaegertracing 48 | 49 | #endif // JAEGERTRACING_SAMPLERS_SAMPLINGSTATUS_H 50 | -------------------------------------------------------------------------------- /src/jaegertracing/testutils/EnvVariable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 The Jaeger Authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/testutils/EnvVariable.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/testutils/EnvVariable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 The Jaeger Authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_TESTUTILS_ENVVARIABLE_H 18 | #define JAEGERTRACING_TESTUTILS_ENVVARIABLE_H 19 | 20 | #include 21 | 22 | namespace jaegertracing { 23 | namespace testutils { 24 | namespace EnvVariable { 25 | 26 | inline void setEnv(const char *variable, const char *value) { 27 | #ifdef WIN32 28 | _putenv_s(variable, value); 29 | #else 30 | setenv(variable, value, true); 31 | #endif 32 | } 33 | 34 | } // namespace EnvVariable 35 | } // namespace testutils 36 | } // namespace jaegertracing 37 | 38 | #endif // JAEGERTRACING_TESTUTILS_ENVVARIABLE_H 39 | -------------------------------------------------------------------------------- /src/jaegertracing/testutils/SamplingManager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/testutils/SamplingManager.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/testutils/TUDPTransport.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/testutils/TUDPTransport.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/testutils/TracerUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_TESTUTILS_TRACERUTIL_H 18 | #define JAEGERTRACING_TESTUTILS_TRACERUTIL_H 19 | 20 | #include 21 | 22 | #include "jaegertracing/Tracer.h" 23 | #include "jaegertracing/propagation/Format.h" 24 | #include "jaegertracing/testutils/MockAgent.h" 25 | 26 | namespace jaegertracing { 27 | namespace testutils { 28 | namespace TracerUtil { 29 | 30 | struct ResourceHandle { 31 | ResourceHandle() 32 | : _mockAgent(testutils::MockAgent::make()) 33 | { 34 | } 35 | 36 | ~ResourceHandle() 37 | { 38 | opentracing::Tracer::InitGlobal(opentracing::MakeNoopTracer()); 39 | } 40 | 41 | std::shared_ptr _mockAgent; 42 | }; 43 | 44 | std::shared_ptr installGlobalTracer(); 45 | std::shared_ptr installGlobalTracer128Bit(); 46 | std::shared_ptr installGlobalTracerW3CPropagation(); 47 | std::shared_ptr buildTracer(const std::string& endpoint); 48 | 49 | } // namespace TracerUtil 50 | } // namespace testutils 51 | } // namespace jaegertracing 52 | 53 | #endif // JAEGERTRACING_TESTUTILS_TRACERUTIL_H 54 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/agent_constants.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #include "agent_constants.h" 8 | 9 | namespace jaegertracing { namespace agent { namespace thrift { 10 | 11 | const agentConstants g_agent_constants; 12 | 13 | agentConstants::agentConstants() { 14 | } 15 | 16 | }}} // namespace 17 | 18 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/agent_constants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #ifndef agent_CONSTANTS_H 8 | #define agent_CONSTANTS_H 9 | 10 | #include "agent_types.h" 11 | 12 | namespace jaegertracing { namespace agent { namespace thrift { 13 | 14 | class agentConstants { 15 | public: 16 | agentConstants(); 17 | 18 | }; 19 | 20 | extern const agentConstants g_agent_constants; 21 | 22 | }}} // namespace 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/agent_types.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #include "agent_types.h" 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | namespace jaegertracing { namespace agent { namespace thrift { 15 | 16 | }}} // namespace 17 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/agent_types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #ifndef agent_TYPES_H 8 | #define agent_TYPES_H 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "jaeger_types.h" 19 | #include "zipkincore_types.h" 20 | 21 | 22 | namespace jaegertracing { namespace agent { namespace thrift { 23 | 24 | }}} // namespace 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/aggregation_validator_constants.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #include "aggregation_validator_constants.h" 8 | 9 | namespace jaegertracing { namespace thrift { 10 | 11 | const aggregation_validatorConstants g_aggregation_validator_constants; 12 | 13 | aggregation_validatorConstants::aggregation_validatorConstants() { 14 | } 15 | 16 | }} // namespace 17 | 18 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/aggregation_validator_constants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #ifndef aggregation_validator_CONSTANTS_H 8 | #define aggregation_validator_CONSTANTS_H 9 | 10 | #include "aggregation_validator_types.h" 11 | 12 | namespace jaegertracing { namespace thrift { 13 | 14 | class aggregation_validatorConstants { 15 | public: 16 | aggregation_validatorConstants(); 17 | 18 | }; 19 | 20 | extern const aggregation_validatorConstants g_aggregation_validator_constants; 21 | 22 | }} // namespace 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/aggregation_validator_types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #ifndef aggregation_validator_TYPES_H 8 | #define aggregation_validator_TYPES_H 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | 20 | 21 | namespace jaegertracing { namespace thrift { 22 | 23 | class ValidateTraceResponse; 24 | 25 | 26 | class ValidateTraceResponse : public virtual ::apache::thrift::TBase { 27 | public: 28 | 29 | ValidateTraceResponse(const ValidateTraceResponse&); 30 | ValidateTraceResponse& operator=(const ValidateTraceResponse&); 31 | ValidateTraceResponse() : ok(0), traceCount(0) { 32 | } 33 | 34 | virtual ~ValidateTraceResponse() throw(); 35 | bool ok; 36 | int64_t traceCount; 37 | 38 | void __set_ok(const bool val); 39 | 40 | void __set_traceCount(const int64_t val); 41 | 42 | bool operator == (const ValidateTraceResponse & rhs) const 43 | { 44 | if (!(ok == rhs.ok)) 45 | return false; 46 | if (!(traceCount == rhs.traceCount)) 47 | return false; 48 | return true; 49 | } 50 | bool operator != (const ValidateTraceResponse &rhs) const { 51 | return !(*this == rhs); 52 | } 53 | 54 | bool operator < (const ValidateTraceResponse & ) const; 55 | 56 | uint32_t read(::apache::thrift::protocol::TProtocol* iprot); 57 | uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; 58 | 59 | virtual void printTo(std::ostream& out) const; 60 | }; 61 | 62 | void swap(ValidateTraceResponse &a, ValidateTraceResponse &b); 63 | 64 | std::ostream& operator<<(std::ostream& out, const ValidateTraceResponse& obj); 65 | 66 | }} // namespace 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/baggage_constants.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #include "baggage_constants.h" 8 | 9 | namespace jaegertracing { namespace thrift { 10 | 11 | const baggageConstants g_baggage_constants; 12 | 13 | baggageConstants::baggageConstants() { 14 | } 15 | 16 | }} // namespace 17 | 18 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/baggage_constants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #ifndef baggage_CONSTANTS_H 8 | #define baggage_CONSTANTS_H 9 | 10 | #include "baggage_types.h" 11 | 12 | namespace jaegertracing { namespace thrift { 13 | 14 | class baggageConstants { 15 | public: 16 | baggageConstants(); 17 | 18 | }; 19 | 20 | extern const baggageConstants g_baggage_constants; 21 | 22 | }} // namespace 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/baggage_types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #ifndef baggage_TYPES_H 8 | #define baggage_TYPES_H 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | 20 | 21 | namespace jaegertracing { namespace thrift { 22 | 23 | class BaggageRestriction; 24 | 25 | 26 | class BaggageRestriction : public virtual ::apache::thrift::TBase { 27 | public: 28 | 29 | BaggageRestriction(const BaggageRestriction&); 30 | BaggageRestriction& operator=(const BaggageRestriction&); 31 | BaggageRestriction() : baggageKey(), maxValueLength(0) { 32 | } 33 | 34 | virtual ~BaggageRestriction() throw(); 35 | std::string baggageKey; 36 | int32_t maxValueLength; 37 | 38 | void __set_baggageKey(const std::string& val); 39 | 40 | void __set_maxValueLength(const int32_t val); 41 | 42 | bool operator == (const BaggageRestriction & rhs) const 43 | { 44 | if (!(baggageKey == rhs.baggageKey)) 45 | return false; 46 | if (!(maxValueLength == rhs.maxValueLength)) 47 | return false; 48 | return true; 49 | } 50 | bool operator != (const BaggageRestriction &rhs) const { 51 | return !(*this == rhs); 52 | } 53 | 54 | bool operator < (const BaggageRestriction & ) const; 55 | 56 | uint32_t read(::apache::thrift::protocol::TProtocol* iprot); 57 | uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; 58 | 59 | virtual void printTo(std::ostream& out) const; 60 | }; 61 | 62 | void swap(BaggageRestriction &a, BaggageRestriction &b); 63 | 64 | std::ostream& operator<<(std::ostream& out, const BaggageRestriction& obj); 65 | 66 | }} // namespace 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/dependency_constants.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #include "dependency_constants.h" 8 | 9 | namespace jaegertracing { namespace thrift { 10 | 11 | const dependencyConstants g_dependency_constants; 12 | 13 | dependencyConstants::dependencyConstants() { 14 | } 15 | 16 | }} // namespace 17 | 18 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/dependency_constants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #ifndef dependency_CONSTANTS_H 8 | #define dependency_CONSTANTS_H 9 | 10 | #include "dependency_types.h" 11 | 12 | namespace jaegertracing { namespace thrift { 13 | 14 | class dependencyConstants { 15 | public: 16 | dependencyConstants(); 17 | 18 | }; 19 | 20 | extern const dependencyConstants g_dependency_constants; 21 | 22 | }} // namespace 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/jaeger_constants.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #include "jaeger_constants.h" 8 | 9 | namespace jaegertracing { namespace thrift { 10 | 11 | const jaegerConstants g_jaeger_constants; 12 | 13 | jaegerConstants::jaegerConstants() { 14 | } 15 | 16 | }} // namespace 17 | 18 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/jaeger_constants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #ifndef jaeger_CONSTANTS_H 8 | #define jaeger_CONSTANTS_H 9 | 10 | #include "jaeger_types.h" 11 | 12 | namespace jaegertracing { namespace thrift { 13 | 14 | class jaegerConstants { 15 | public: 16 | jaegerConstants(); 17 | 18 | }; 19 | 20 | extern const jaegerConstants g_jaeger_constants; 21 | 22 | }} // namespace 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/sampling_constants.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #include "sampling_constants.h" 8 | 9 | namespace jaegertracing { namespace sampling_manager { namespace thrift { 10 | 11 | const samplingConstants g_sampling_constants; 12 | 13 | samplingConstants::samplingConstants() { 14 | } 15 | 16 | }}} // namespace 17 | 18 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/sampling_constants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #ifndef sampling_CONSTANTS_H 8 | #define sampling_CONSTANTS_H 9 | 10 | #include "sampling_types.h" 11 | 12 | namespace jaegertracing { namespace sampling_manager { namespace thrift { 13 | 14 | class samplingConstants { 15 | public: 16 | samplingConstants(); 17 | 18 | }; 19 | 20 | extern const samplingConstants g_sampling_constants; 21 | 22 | }}} // namespace 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/tracetest_constants.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #include "tracetest_constants.h" 8 | 9 | namespace jaegertracing { namespace crossdock { namespace thrift { 10 | 11 | const tracetestConstants g_tracetest_constants; 12 | 13 | tracetestConstants::tracetestConstants() { 14 | } 15 | 16 | }}} // namespace 17 | 18 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/tracetest_constants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #ifndef tracetest_CONSTANTS_H 8 | #define tracetest_CONSTANTS_H 9 | 10 | #include "tracetest_types.h" 11 | 12 | namespace jaegertracing { namespace crossdock { namespace thrift { 13 | 14 | class tracetestConstants { 15 | public: 16 | tracetestConstants(); 17 | 18 | }; 19 | 20 | extern const tracetestConstants g_tracetest_constants; 21 | 22 | }}} // namespace 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/zipkincore_constants.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #include "zipkincore_constants.h" 8 | 9 | namespace twitter { namespace zipkin { namespace thrift { 10 | 11 | const zipkincoreConstants g_zipkincore_constants; 12 | 13 | zipkincoreConstants::zipkincoreConstants() { 14 | CLIENT_SEND = "cs"; 15 | 16 | CLIENT_RECV = "cr"; 17 | 18 | SERVER_SEND = "ss"; 19 | 20 | SERVER_RECV = "sr"; 21 | 22 | MESSAGE_SEND = "ms"; 23 | 24 | MESSAGE_RECV = "mr"; 25 | 26 | WIRE_SEND = "ws"; 27 | 28 | WIRE_RECV = "wr"; 29 | 30 | CLIENT_SEND_FRAGMENT = "csf"; 31 | 32 | CLIENT_RECV_FRAGMENT = "crf"; 33 | 34 | SERVER_SEND_FRAGMENT = "ssf"; 35 | 36 | SERVER_RECV_FRAGMENT = "srf"; 37 | 38 | LOCAL_COMPONENT = "lc"; 39 | 40 | CLIENT_ADDR = "ca"; 41 | 42 | SERVER_ADDR = "sa"; 43 | 44 | MESSAGE_ADDR = "ma"; 45 | 46 | } 47 | 48 | }}} // namespace 49 | 50 | -------------------------------------------------------------------------------- /src/jaegertracing/thrift-gen/zipkincore_constants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.11.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #ifndef zipkincore_CONSTANTS_H 8 | #define zipkincore_CONSTANTS_H 9 | 10 | #include "zipkincore_types.h" 11 | 12 | namespace twitter { namespace zipkin { namespace thrift { 13 | 14 | class zipkincoreConstants { 15 | public: 16 | zipkincoreConstants(); 17 | 18 | std::string CLIENT_SEND; 19 | std::string CLIENT_RECV; 20 | std::string SERVER_SEND; 21 | std::string SERVER_RECV; 22 | std::string MESSAGE_SEND; 23 | std::string MESSAGE_RECV; 24 | std::string WIRE_SEND; 25 | std::string WIRE_RECV; 26 | std::string CLIENT_SEND_FRAGMENT; 27 | std::string CLIENT_RECV_FRAGMENT; 28 | std::string SERVER_SEND_FRAGMENT; 29 | std::string SERVER_RECV_FRAGMENT; 30 | std::string LOCAL_COMPONENT; 31 | std::string CLIENT_ADDR; 32 | std::string SERVER_ADDR; 33 | std::string MESSAGE_ADDR; 34 | }; 35 | 36 | extern const zipkincoreConstants g_zipkincore_constants; 37 | 38 | }}} // namespace 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/jaegertracing/utils/EnvVariable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/utils/EnvVariable.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/utils/EnvVariable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 The Jaeger Authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_UTILS_ENV_VARIABLE_H 18 | #define JAEGERTRACING_UTILS_ENV_VARIABLE_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace jaegertracing { 25 | namespace utils { 26 | namespace EnvVariable { 27 | 28 | inline std::string getStringVariable(const char* envVar) 29 | { 30 | const auto rawVariable = std::getenv(envVar); 31 | return std::string(rawVariable ? rawVariable : ""); 32 | } 33 | 34 | inline std::pair getIntVariable(const char* envVar) 35 | { 36 | const auto rawVariable = std::getenv(envVar); 37 | const std::string variable(rawVariable ? rawVariable : ""); 38 | if (!variable.empty()) { 39 | std::istringstream iss(variable); 40 | int intVal = 0; 41 | if (iss >> intVal) { 42 | return std::make_pair(false, intVal); 43 | } 44 | } 45 | return std::make_pair(false, 0); 46 | } 47 | 48 | inline std::pair getBoolVariable(const char* envVar) 49 | { 50 | const auto rawVariable = std::getenv(envVar); 51 | std::string variable(rawVariable ? rawVariable : ""); 52 | 53 | if (!variable.empty()) { 54 | std::transform( 55 | variable.begin(), variable.end(), variable.begin(), ::tolower); 56 | return std::make_pair(true, (variable == "true")); 57 | } 58 | return std::make_pair(false, false); 59 | } 60 | 61 | } // namespace EnvVariable 62 | } // namespace utils 63 | } // namespace jaegertracing 64 | 65 | #endif // JAEGERTRACING_UTILS_ENV_VARIABLE_H 66 | -------------------------------------------------------------------------------- /src/jaegertracing/utils/ErrorUtil.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/utils/ErrorUtil.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/utils/ErrorUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_UTILS_ERRORUTIL_H 18 | #define JAEGERTRACING_UTILS_ERRORUTIL_H 19 | 20 | #include "jaegertracing/Logging.h" 21 | #include "jaegertracing/Sender.h" 22 | #include 23 | #include 24 | #include 25 | 26 | namespace jaegertracing { 27 | namespace utils { 28 | namespace ErrorUtil { 29 | 30 | inline void logError(logging::Logger& logger, const std::string& message) 31 | { 32 | try { 33 | throw; 34 | } catch (const Sender::Exception& ex) { 35 | std::ostringstream oss; 36 | oss << message << ": " << ex.what() << ", numFailed=" << ex.numFailed(); 37 | logger.error(oss.str()); 38 | } catch (const std::system_error& ex) { 39 | std::ostringstream oss; 40 | oss << message << ": " << ex.what() << ", code=" << ex.code().value(); 41 | logger.error(oss.str()); 42 | } catch (const std::exception& ex) { 43 | std::ostringstream oss; 44 | oss << message << ": " << ex.what(); 45 | logger.error(oss.str()); 46 | } catch (...) { 47 | logger.error(message); 48 | } 49 | } 50 | 51 | } // namespace ErrorUtil 52 | } // namespace utils 53 | } // namespace jaegertracing 54 | 55 | #endif // JAEGERTRACING_UTILS_ERRORUTIL_H 56 | -------------------------------------------------------------------------------- /src/jaegertracing/utils/HTTPTransporter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, The Jaeger Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/utils/HTTPTransporter.h" 18 | #include 19 | #include 20 | 21 | namespace jaegertracing { 22 | namespace utils { 23 | 24 | HTTPTransporter::HTTPTransporter(const net::URI& endpoint, int maxPacketSize) 25 | : Transport(maxPacketSize == 0 ? kHttpPacketMaxLength : maxPacketSize) 26 | , _buffer(new apache::thrift::transport::TMemoryBuffer(_maxPacketSize)) 27 | , _serverAddr(net::IPAddress::v4(endpoint._host, endpoint._port)) 28 | , _httpClient(new ::apache::thrift::transport::THttpClient( 29 | _buffer, endpoint._host, endpoint._path + "?format=jaeger.thrift")) 30 | { 31 | using TProtocolFactory = apache::thrift::protocol::TProtocolFactory; 32 | using TBinaryProtocolFactory = 33 | apache::thrift::protocol::TBinaryProtocolFactory; 34 | 35 | _socket.open(AF_INET, SOCK_STREAM); 36 | _socket.connect(_serverAddr); 37 | std::shared_ptr protocolFactory( 38 | new TBinaryProtocolFactory()); 39 | _protocol = protocolFactory->getProtocol(_httpClient); 40 | } 41 | 42 | } // namespace utils 43 | } // namespace jaegertracing 44 | -------------------------------------------------------------------------------- /src/jaegertracing/utils/HexParsing.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/utils/HexParsing.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/utils/HexParsing.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_UTILS_HEXPARSING_H 18 | #define JAEGERTRACING_UTILS_HEXPARSING_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace jaegertracing { 26 | namespace utils { 27 | namespace HexParsing { 28 | 29 | inline bool isHex(char ch) 30 | { 31 | return (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || 32 | (ch >= 'a' && ch <= 'f'); 33 | } 34 | 35 | inline std::string readSegment(std::istream& in, size_t maxChars, char delim) 36 | { 37 | std::string buffer; 38 | auto ch = '\0'; 39 | for (auto i = static_cast(0); i < maxChars && in.get(ch); ++i) { 40 | if (!isHex(ch)) { 41 | if (ch == delim) { 42 | in.putback(ch); 43 | break; 44 | } 45 | else { 46 | return ""; 47 | } 48 | } 49 | 50 | buffer.push_back(ch); 51 | } 52 | return buffer; 53 | } 54 | 55 | template 56 | ResultType decodeHex(const std::string& str) 57 | { 58 | auto first = std::begin(str); 59 | auto last = std::end(str); 60 | ResultType result = 0; 61 | for (; first != last; ++first) { 62 | const auto ch = *first; 63 | 64 | // This condition is guaranteed by `readSegment`. 65 | assert(isHex(ch)); 66 | 67 | auto hexDigit = 0; 68 | if (std::isdigit(ch)) { 69 | hexDigit = (ch - '0'); 70 | } 71 | else if (std::isupper(ch)) { 72 | hexDigit = (ch - 'A') + 10; 73 | } 74 | else { 75 | hexDigit = (ch - 'a') + 10; 76 | } 77 | 78 | result = (result << 4) | hexDigit; 79 | } 80 | 81 | return result; 82 | } 83 | 84 | } // namespace HexParsing 85 | } // namespace utils 86 | } // namespace jaegertracing 87 | 88 | #endif // JAEGERTRACING_UTILS_HEXPARSING_H 89 | -------------------------------------------------------------------------------- /src/jaegertracing/utils/RateLimiter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/utils/RateLimiter.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/utils/RateLimiter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_UTILS_RATELIMITER_H 18 | #define JAEGERTRACING_UTILS_RATELIMITER_H 19 | 20 | #include 21 | #include 22 | 23 | namespace jaegertracing { 24 | namespace utils { 25 | 26 | template 27 | class RateLimiter { 28 | public: 29 | using Clock = ClockType; 30 | 31 | RateLimiter(double creditsPerSecond, double maxBalance) 32 | : _creditsPerSecond(creditsPerSecond) 33 | , _maxBalance(maxBalance) 34 | , _balance(_maxBalance) 35 | , _lastTick(Clock::now()) 36 | { 37 | } 38 | 39 | bool checkCredit(double itemCost) 40 | { 41 | std::lock_guard lock(_mutex); 42 | const auto currentTime = Clock::now(); 43 | const auto elapsedTime = 44 | std::chrono::duration(currentTime - _lastTick); 45 | _lastTick = currentTime; 46 | 47 | _balance += elapsedTime.count() * _creditsPerSecond; 48 | if (_balance > _maxBalance) { 49 | _balance = _maxBalance; 50 | } 51 | 52 | if (_balance >= itemCost) { 53 | _balance -= itemCost; 54 | return true; 55 | } 56 | 57 | return false; 58 | } 59 | 60 | private: 61 | double _creditsPerSecond; 62 | double _maxBalance; 63 | double _balance; 64 | typename Clock::time_point _lastTick; 65 | std::mutex _mutex; 66 | }; 67 | 68 | } // namespace utils 69 | } // namespace jaegertracing 70 | 71 | #endif // JAEGERTRACING_UTILS_RATELIMITER_H 72 | -------------------------------------------------------------------------------- /src/jaegertracing/utils/Transport.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, The Jaeger Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_UTILS_SENDER_H 18 | #define JAEGERTRACING_UTILS_SENDER_H 19 | 20 | #include "jaegertracing/net/Socket.h" 21 | #include "jaegertracing/thrift-gen/jaeger_types.h" 22 | 23 | namespace jaegertracing { 24 | namespace utils { 25 | 26 | class Transport { 27 | public: 28 | Transport(int maxPacketSize) 29 | : _maxPacketSize(maxPacketSize) 30 | { 31 | } 32 | 33 | virtual ~Transport() { close(); } 34 | 35 | virtual void emitBatch(const thrift::Batch& batch) = 0; 36 | 37 | int maxPacketSize() const { return _maxPacketSize; } 38 | 39 | void close() { _socket.close(); } 40 | 41 | virtual std::unique_ptr 42 | protocolFactory() const = 0; 43 | 44 | protected: 45 | int _maxPacketSize; 46 | net::Socket _socket; 47 | }; 48 | 49 | } // namespace utils 50 | } // namespace jaegertracing 51 | 52 | #endif // JAEGERTRACING_UTILS_SENDER_H 53 | -------------------------------------------------------------------------------- /src/jaegertracing/utils/UDPTransporter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/utils/UDPTransporter.h" 18 | #include 19 | #include 20 | 21 | namespace jaegertracing { 22 | namespace utils { 23 | 24 | UDPTransporter::UDPTransporter(const net::IPAddress& serverAddr, int maxPacketSize) 25 | : Transport(maxPacketSize == 0 ? kUDPPacketMaxLength 26 | : maxPacketSize) 27 | , _buffer(new apache::thrift::transport::TMemoryBuffer(_maxPacketSize)) 28 | , _serverAddr(serverAddr) 29 | , _client() 30 | { 31 | using TProtocolFactory = apache::thrift::protocol::TProtocolFactory; 32 | using TCompactProtocolFactory = 33 | apache::thrift::protocol::TCompactProtocolFactory; 34 | 35 | _socket.open(AF_INET, SOCK_DGRAM); 36 | _socket.connect(_serverAddr); 37 | std::shared_ptr protocolFactory( 38 | new TCompactProtocolFactory()); 39 | auto protocol = protocolFactory->getProtocol(_buffer); 40 | _client.reset(new agent::thrift::AgentClient(protocol)); 41 | } 42 | 43 | } // namespace utils 44 | } // namespace jaegertracing 45 | -------------------------------------------------------------------------------- /src/jaegertracing/utils/YAML.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jaegertracing/utils/YAML.h" 18 | -------------------------------------------------------------------------------- /src/jaegertracing/utils/YAML.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Uber Technologies, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef JAEGERTRACING_UTILS_YAML_H 18 | #define JAEGERTRACING_UTILS_YAML_H 19 | 20 | #include "jaegertracing/Constants.h" 21 | 22 | #ifdef JAEGERTRACING_WITH_YAML_CPP 23 | 24 | #include 25 | 26 | namespace jaegertracing { 27 | namespace utils { 28 | namespace yaml { 29 | 30 | template 31 | ValueType findOrDefault(const YAML::Node& node, 32 | const KeyType& key, 33 | const DefaultValueType& defaultValue) 34 | { 35 | const auto valueNode = node[key]; 36 | if (!valueNode.IsDefined()) { 37 | return defaultValue; 38 | } 39 | return valueNode.template as(); 40 | } 41 | 42 | } // namespace yaml 43 | } // namespace utils 44 | } // namespace jaegertracing 45 | 46 | #endif // JAEGERTRACING_WITH_YAML_CPP 47 | 48 | #endif // JAEGERTRACING_UTILS_YAML_H 49 | --------------------------------------------------------------------------------