Skip to content

Commit b89ca2c

Browse files
authored
Merge branch 'main' into FixJaegerIds
2 parents 2965d0b + 01837f5 commit b89ca2c

25 files changed

+1354
-186
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Increment the:
1515

1616
## [Unreleased]
1717

18+
* [EXPORTER] Add OTLP/HTTP+JSON Protocol exporter ([#810](https://github.com/open-telemetry/opentelemetry-cpp/pull/810))
19+
* [EXPORTER] Rename `OtlpExporter` to `OtlpGrpcExporter`, rename `otlp_exporter.h` to `otlp_grpc_exporter.h` ([#810](https://github.com/open-telemetry/opentelemetry-cpp/pull/810))
20+
1821
## [1.0.0-rc1] 2021-06-04
1922

2023
* [BUILD] Enable Jaeger exporter build in Windows ([#815](https://github.com/open-telemetry/opentelemetry-cpp/pull/815))

CMakeLists.txt

+11-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ if(WITH_OTLP)
203203
find_package(Protobuf REQUIRED)
204204
endif()
205205
if(NOT gRPC_FOUND)
206-
find_package(gRPC REQUIRED)
206+
find_package(gRPC)
207207
endif()
208208
if(WIN32)
209209
# Always use x64 protoc.exe
@@ -221,6 +221,15 @@ if(WITH_OTLP)
221221
message("PROTOBUF_PROTOC_EXECUTABLE=${PROTOBUF_PROTOC_EXECUTABLE}")
222222

223223
include(cmake/opentelemetry-proto.cmake)
224+
include(CMakeDependentOption)
225+
find_package(CURL)
226+
find_package(nlohmann_json)
227+
cmake_dependent_option(
228+
WITH_OTLP_GRPC "Whether to include the OTLP gRPC exporter in the SDK" ON
229+
"gRPC_FOUND" OFF)
230+
cmake_dependent_option(
231+
WITH_OTLP_HTTP "Whether to include the OTLP http exporter in the SDK" ON
232+
"CURL_FOUND;nlohmann_json_FOUND" OFF)
224233
endif()
225234

226235
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}")
@@ -268,11 +277,11 @@ if(NOT WITH_API_ONLY)
268277
include_directories(ext/include)
269278

270279
add_subdirectory(sdk)
280+
add_subdirectory(ext)
271281
add_subdirectory(exporters)
272282
if(WITH_EXAMPLES)
273283
add_subdirectory(examples)
274284
endif()
275-
add_subdirectory(ext)
276285
endif()
277286

278287
# Add nlohmann/json submodule to include directories

WORKSPACE

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
2929

3030
grpc_extra_deps()
3131

32-
load("@upb//bazel:repository_defs.bzl", "bazel_version_repository")
32+
load("@upb//bazel:workspace_deps.bzl", "upb_deps")
3333

34-
bazel_version_repository(name = "upb_bazel_version")
34+
upb_deps()
3535

3636
# Load prometheus C++ dependencies.
3737
load("@com_github_jupp0r_prometheus_cpp//bazel:repositories.bzl", "prometheus_cpp_repositories")

bazel/repository.bzl

+13-3
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,23 @@ def opentelemetry_cpp_deps():
2929
)
3030

3131
# Load gRPC dependency
32+
maybe(
33+
http_archive,
34+
name = "com_github_grpc_grpc_legacy",
35+
sha256 = "2060769f2d4b0d3535ba594b2ab614d7f68a492f786ab94b4318788d45e3278a",
36+
strip_prefix = "grpc-1.33.2",
37+
urls = [
38+
"https://github.com/grpc/grpc/archive/v1.33.2.tar.gz",
39+
],
40+
)
41+
3242
maybe(
3343
http_archive,
3444
name = "com_github_grpc_grpc",
35-
sha256 = "d6277f77e0bb922d3f6f56c0f93292bb4cfabfc3c92b31ee5ccea0e100303612",
36-
strip_prefix = "grpc-1.28.0",
45+
sha256 = "2060769f2d4b0d3535ba594b2ab614d7f68a492f786ab94b4318788d45e3278a",
46+
strip_prefix = "grpc-1.33.2",
3747
urls = [
38-
"https://github.com/grpc/grpc/archive/v1.28.0.tar.gz",
48+
"https://github.com/grpc/grpc/archive/v1.33.2.tar.gz",
3949
],
4050
)
4151

cmake/opentelemetry-proto.cmake

+1-82
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,4 @@
1-
macro(check_append_cxx_compiler_flag OUTPUT_VAR)
2-
foreach(CHECK_FLAG ${ARGN})
3-
check_cxx_compiler_flag(${CHECK_FLAG}
4-
"check_cxx_compiler_flag_${CHECK_FLAG}")
5-
if(check_cxx_compiler_flag_${CHECK_FLAG})
6-
list(APPEND ${OUTPUT_VAR} ${CHECK_FLAG})
7-
endif()
8-
endforeach()
9-
endmacro()
10-
11-
if(NOT PATCH_PROTOBUF_SOURCES_OPTIONS_SET)
12-
if(MSVC)
13-
unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE)
14-
set(PATCH_PROTOBUF_SOURCES_OPTIONS /wd4244 /wd4251 /wd4267 /wd4309)
15-
16-
if(MSVC_VERSION GREATER_EQUAL 1922)
17-
# see
18-
# https://docs.microsoft.com/en-us/cpp/overview/cpp-conformance-improvements?view=vs-2019#improvements_162
19-
# for detail
20-
list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd5054)
21-
endif()
22-
23-
if(MSVC_VERSION GREATER_EQUAL 1925)
24-
list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd4996)
25-
endif()
26-
27-
if(MSVC_VERSION LESS 1910)
28-
list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd4800)
29-
endif()
30-
else()
31-
unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE)
32-
include(CheckCXXCompilerFlag)
33-
check_append_cxx_compiler_flag(
34-
PATCH_PROTOBUF_SOURCES_OPTIONS -Wno-type-limits
35-
-Wno-deprecated-declarations -Wno-unused-parameter)
36-
endif()
37-
set(PATCH_PROTOBUF_SOURCES_OPTIONS_SET TRUE)
38-
if(PATCH_PROTOBUF_SOURCES_OPTIONS)
39-
set(PATCH_PROTOBUF_SOURCES_OPTIONS
40-
${PATCH_PROTOBUF_SOURCES_OPTIONS}
41-
CACHE INTERNAL
42-
"Options to disable warning of generated protobuf sources" FORCE)
43-
endif()
44-
endif()
45-
46-
function(patch_protobuf_sources)
47-
if(PATCH_PROTOBUF_SOURCES_OPTIONS)
48-
foreach(PROTO_SRC ${ARGN})
49-
unset(PROTO_SRC_OPTIONS)
50-
get_source_file_property(PROTO_SRC_OPTIONS ${PROTO_SRC} COMPILE_OPTIONS)
51-
if(PROTO_SRC_OPTIONS)
52-
list(APPEND PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS})
53-
else()
54-
set(PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS})
55-
endif()
56-
57-
set_source_files_properties(
58-
${PROTO_SRC} PROPERTIES COMPILE_OPTIONS "${PROTO_SRC_OPTIONS}")
59-
endforeach()
60-
unset(PROTO_SRC)
61-
unset(PROTO_SRC_OPTIONS)
62-
endif()
63-
endfunction()
64-
65-
function(patch_protobuf_targets)
66-
if(PATCH_PROTOBUF_SOURCES_OPTIONS)
67-
foreach(PROTO_TARGET ${ARGN})
68-
unset(PROTO_TARGET_OPTIONS)
69-
get_target_property(PROTO_TARGET_OPTIONS ${PROTO_TARGET} COMPILE_OPTIONS)
70-
if(PROTO_TARGET_OPTIONS)
71-
list(APPEND PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS})
72-
else()
73-
set(PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS})
74-
endif()
75-
76-
set_target_properties(
77-
${PROTO_TARGET} PROPERTIES COMPILE_OPTIONS "${PROTO_TARGET_OPTIONS}")
78-
endforeach()
79-
unset(PROTO_TARGET)
80-
unset(PROTO_TARGET_OPTIONS)
81-
endif()
82-
endfunction()
1+
include(${PROJECT_SOURCE_DIR}/cmake/proto-options-patch.cmake)
832

843
set(PROTO_PATH "${CMAKE_CURRENT_SOURCE_DIR}/third_party/opentelemetry-proto")
854

cmake/proto-options-patch.cmake

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
macro(check_append_cxx_compiler_flag OUTPUT_VAR)
2+
foreach(CHECK_FLAG ${ARGN})
3+
check_cxx_compiler_flag(${CHECK_FLAG}
4+
"check_cxx_compiler_flag_${CHECK_FLAG}")
5+
if(check_cxx_compiler_flag_${CHECK_FLAG})
6+
list(APPEND ${OUTPUT_VAR} ${CHECK_FLAG})
7+
endif()
8+
endforeach()
9+
endmacro()
10+
11+
if(NOT PATCH_PROTOBUF_SOURCES_OPTIONS_SET)
12+
if(MSVC)
13+
unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE)
14+
set(PATCH_PROTOBUF_SOURCES_OPTIONS /wd4244 /wd4251 /wd4267 /wd4309)
15+
16+
if(MSVC_VERSION GREATER_EQUAL 1922)
17+
# see
18+
# https://docs.microsoft.com/en-us/cpp/overview/cpp-conformance-improvements?view=vs-2019#improvements_162
19+
# for detail
20+
list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd5054)
21+
endif()
22+
23+
if(MSVC_VERSION GREATER_EQUAL 1925)
24+
list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd4996)
25+
endif()
26+
27+
if(MSVC_VERSION LESS 1910)
28+
list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd4800)
29+
endif()
30+
else()
31+
unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE)
32+
include(CheckCXXCompilerFlag)
33+
check_append_cxx_compiler_flag(
34+
PATCH_PROTOBUF_SOURCES_OPTIONS -Wno-type-limits
35+
-Wno-deprecated-declarations -Wno-unused-parameter)
36+
endif()
37+
set(PATCH_PROTOBUF_SOURCES_OPTIONS_SET TRUE)
38+
if(PATCH_PROTOBUF_SOURCES_OPTIONS)
39+
set(PATCH_PROTOBUF_SOURCES_OPTIONS
40+
${PATCH_PROTOBUF_SOURCES_OPTIONS}
41+
CACHE INTERNAL
42+
"Options to disable warning of generated protobuf sources" FORCE)
43+
endif()
44+
endif()
45+
46+
function(patch_protobuf_sources)
47+
if(PATCH_PROTOBUF_SOURCES_OPTIONS)
48+
foreach(PROTO_SRC ${ARGN})
49+
unset(PROTO_SRC_OPTIONS)
50+
get_source_file_property(PROTO_SRC_OPTIONS ${PROTO_SRC} COMPILE_OPTIONS)
51+
if(PROTO_SRC_OPTIONS)
52+
list(APPEND PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS})
53+
else()
54+
set(PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS})
55+
endif()
56+
57+
set_source_files_properties(
58+
${PROTO_SRC} PROPERTIES COMPILE_OPTIONS "${PROTO_SRC_OPTIONS}")
59+
endforeach()
60+
unset(PROTO_SRC)
61+
unset(PROTO_SRC_OPTIONS)
62+
endif()
63+
endfunction()
64+
65+
function(patch_protobuf_targets)
66+
if(PATCH_PROTOBUF_SOURCES_OPTIONS)
67+
foreach(PROTO_TARGET ${ARGN})
68+
unset(PROTO_TARGET_OPTIONS)
69+
get_target_property(PROTO_TARGET_OPTIONS ${PROTO_TARGET} COMPILE_OPTIONS)
70+
if(PROTO_TARGET_OPTIONS)
71+
list(APPEND PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS})
72+
else()
73+
set(PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS})
74+
endif()
75+
76+
set_target_properties(
77+
${PROTO_TARGET} PROPERTIES COMPILE_OPTIONS "${PROTO_TARGET_OPTIONS}")
78+
endforeach()
79+
unset(PROTO_TARGET)
80+
unset(PROTO_TARGET_OPTIONS)
81+
endif()
82+
endfunction()

examples/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if(WITH_OTLP)
1+
if(WITH_OTLP_GRPC OR WITH_OTLP_HTTP)
22
add_subdirectory(otlp)
33
add_subdirectory(grpc)
44
endif()

examples/grpc/CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ add_custom_command(
1616
${PROTOBUF_PROTOC_EXECUTABLE} ARGS "--grpc_out=${CMAKE_CURRENT_BINARY_DIR}"
1717
"--cpp_out=${CMAKE_CURRENT_BINARY_DIR}" "--proto_path=${proto_file_path}"
1818
--plugin=protoc-gen-grpc="${gRPC_CPP_PLUGIN_EXECUTABLE}" "${proto_file}")
19-
# DEPENDS "${proto_file}")
2019

21-
# hw_grpc_proto
2220
add_library(example_grpc_proto ${example_grpc_srcs} ${example_grpc_hdrs}
2321
${example_proto_srcs} ${example_proto_hdrs})
2422

23+
include(${PROJECT_SOURCE_DIR}/cmake/proto-options-patch.cmake)
24+
patch_protobuf_targets(example_grpc_proto)
25+
2526
include_directories(
2627
${CMAKE_SOURCE_DIR}/exporters/ostream/include ${CMAKE_SOURCE_DIR}/ext/include
2728
${CMAKE_SOURCE_DIR}/api/include/ ${CMAKE_SOURCE_DIR/})
@@ -45,4 +46,5 @@ foreach(_target client server)
4546
gRPC::grpc++_reflection
4647
opentelemetry_trace
4748
opentelemetry_exporter_ostream_span)
49+
patch_protobuf_targets(${_target})
4850
endforeach()

examples/otlp/BUILD

+16-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,27 @@ cc_library(
1212
)
1313

1414
cc_binary(
15-
name = "example_otlp",
15+
name = "example_otlp_grpc",
1616
srcs = [
17-
"main.cc",
17+
"grpc_main.cc",
1818
],
1919
deps = [
2020
":foo_library",
2121
"//api",
22-
"//exporters/otlp:otlp_exporter",
22+
"//exporters/otlp:otlp_grpc_exporter",
23+
"//sdk/src/trace",
24+
],
25+
)
26+
27+
cc_binary(
28+
name = "example_otlp_http",
29+
srcs = [
30+
"http_main.cc",
31+
],
32+
deps = [
33+
":foo_library",
34+
"//api",
35+
"//exporters/otlp:otlp_http_exporter",
2336
"//sdk/src/trace",
2437
],
2538
)

examples/otlp/CMakeLists.txt

+18-9
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@ add_library(otlp_foo_library foo_library/foo_library.cc)
66
target_link_libraries(otlp_foo_library ${CMAKE_THREAD_LIBS_INIT}
77
${CORE_RUNTIME_LIBS} opentelemetry_api)
88

9-
add_executable(example_otlp main.cc)
10-
target_link_libraries(
11-
example_otlp
12-
${CMAKE_THREAD_LIBS_INIT}
13-
otlp_foo_library
14-
opentelemetry_trace
15-
${CORE_RUNTIME_LIBS}
16-
opentelemetry_exporter_otprotocol
17-
gRPC::grpc++)
9+
if(WITH_OTLP_GRPC)
10+
add_executable(example_otlp_grpc grpc_main.cc)
11+
target_link_libraries(
12+
example_otlp_grpc
13+
${CMAKE_THREAD_LIBS_INIT}
14+
otlp_foo_library
15+
opentelemetry_trace
16+
${CORE_RUNTIME_LIBS}
17+
opentelemetry_exporter_otlp_grpc
18+
gRPC::grpc++)
19+
endif()
20+
21+
if(WITH_OTLP_HTTP)
22+
add_executable(example_otlp_http http_main.cc)
23+
target_link_libraries(
24+
example_otlp_http ${CMAKE_THREAD_LIBS_INIT} otlp_foo_library
25+
opentelemetry_trace ${CORE_RUNTIME_LIBS} opentelemetry_exporter_otlp_http)
26+
endif()

examples/otlp/README.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ This is an example of how to use the [OpenTelemetry
44
Protocol](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/README.md)
55
(OTLP) exporter.
66

7-
The application in `main.cc` initializes an `OtlpExporter` instance and uses it
8-
to register a tracer provider from the [OpenTelemetry
7+
The application in `grpc_main.cc` initializes an `OtlpGrpcExporter` instance and
8+
the application in `http_main.cc` initializes an `OtlpHttpExporter` instance
9+
and they register a tracer provider from the [OpenTelemetry
910
SDK](https://github.com/open-telemetry/opentelemetry-cpp). The application then
1011
calls a `foo_library` which has been instrumented using the [OpenTelemetry
1112
API](https://github.com/open-telemetry/opentelemetry-cpp/tree/main/api).
1213

1314
To enable TLS authentication for OTLP grpc exporter, SslCredentials can be used
1415
by specifying the path to client certificate pem file, or the string containing
15-
this certificate via OtlpExporterOptions. The path to such a .pem file can be
16+
this certificate via OtlpGrpcExporterOptions. The path to such a .pem file can be
1617
provided as a command-line argument alongwith the collector endpoint to the main
1718
binary invocation above.
1819

@@ -31,18 +32,19 @@ OpenTelemetry Collector with an OTLP receiver by running:
3132
- On Unix based systems use:
3233

3334
```console
34-
docker run --rm -it -p 4317:4317 -v $(pwd)/examples/otlp:/cfg otel/opentelemetry-collector:0.19.0 --config=/cfg/opentelemetry-collector-config/config.dev.yaml
35+
docker run --rm -it -p 4317:4317 -p 55681:55681 -v $(pwd)/examples/otlp:/cfg otel/opentelemetry-collector:0.19.0 --config=/cfg/opentelemetry-collector-config/config.dev.yaml
3536
```
3637

3738
- On Windows use:
3839

3940
```console
40-
docker run --rm -it -p 4317:4317 -v "%cd%/examples/otlp":/cfg otel/opentelemetry-collector:0.19.0 --config=/cfg/opentelemetry-collector-config/config.dev.yaml
41+
docker run --rm -it -p 4317:4317 -p 55681:55681 -v "%cd%/examples/otlp":/cfg otel/opentelemetry-collector:0.19.0 --config=/cfg/opentelemetry-collector-config/config.dev.yaml
4142
```
4243

4344
Note that the OTLP exporter connects to the Collector at `localhost:4317` by
4445
default. This can be changed with first argument from command-line, for example:
45-
`./example_otlp gateway.docker.internal:4317`.
46+
`./example_otlp_grpc gateway.docker.internal:4317` and
47+
`./example_otlp_http gateway.docker.internal:55681/v1/traces`.
4648

4749
Once you have the Collector running, see
4850
[CONTRIBUTING.md](../../CONTRIBUTING.md) for instructions on building and

0 commit comments

Comments
 (0)