Skip to content

Commit 2181b01

Browse files
authored
Code improvements for ETW exporter (#519)
1 parent 9b6a50e commit 2181b01

32 files changed

+2647
-1061
lines changed

.github/CODEOWNERS

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Code owners file.
22
# This file controls who is tagged for review for any given pull request.
33

4+
# For ETW exporter
5+
exporters/etw/* @reyang @maxgolov @lalitb @ThomsonTan @open-telemetry/cpp-approvers
6+
47
# For anything not explicitly taken by someone else:
58
* @open-telemetry/cpp-approvers

CMakeLists.txt

+10-14
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ if(WIN32)
8787
option(WITH_ETW "Whether to include the ETW Exporter in the SDK" ON)
8888
if(WITH_ETW)
8989
add_definitions(-DHAVE_MSGPACK)
90-
# Option below will be removed once we donate the TraceLoggingDynamic.h to
91-
# OSS
92-
add_definitions(-DHAVE_NO_TLD)
9390
endif(WITH_ETW)
9491
endif(WIN32)
9592

@@ -167,8 +164,8 @@ endif()
167164

168165
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}")
169166

167+
include(CTest)
170168
if(BUILD_TESTING)
171-
include(CTest)
172169
if(EXISTS ${CMAKE_BINARY_DIR}/lib/libgtest.a)
173170
# Prefer GTest from build tree. GTest is not always working with
174171
# CMAKE_PREFIX_PATH
@@ -181,21 +178,17 @@ if(BUILD_TESTING)
181178
${CMAKE_BINARY_DIR}/lib/libgmock.a)
182179
elseif(WIN32)
183180
# Make sure we are always bootsrapped with vcpkg on Windows
184-
find_package(GTest CONFIG)
185-
if(NOT GTest_FOUND)
181+
find_package(GTest)
182+
if(NOT (GTEST_FOUND OR GTest_FOUND))
186183
install_windows_deps()
187-
find_package(GTest CONFIG REQUIRED)
184+
find_package(GTest REQUIRED)
188185
endif()
189-
set(GTEST_BOTH_LIBRARIES GTest::gtest GTest::gtest_main GTest::gmock)
190186
else()
191187
# Prefer GTest installed by OS distro, brew or vcpkg package manager
192-
find_package(GTest CONFIG REQUIRED)
193-
set(GTEST_BOTH_LIBRARIES GTest::gtest GTest::gtest_main GTest::gmock)
194-
endif()
195-
if(GTEST_INCLUDE_DIRS)
196-
include_directories(SYSTEM ${GTEST_INCLUDE_DIRS})
197-
message("GTEST_INCLUDE_DIRS = ${GTEST_INCLUDE_DIRS}")
188+
find_package(GTest REQUIRED)
198189
endif()
190+
include_directories(SYSTEM ${GTEST_INCLUDE_DIRS})
191+
message("GTEST_INCLUDE_DIRS = ${GTEST_INCLUDE_DIRS}")
199192
message("GTEST_BOTH_LIBRARIES = ${GTEST_BOTH_LIBRARIES}")
200193
enable_testing()
201194
# Benchmark respects the CMAKE_PREFIX_PATH
@@ -217,6 +210,9 @@ if(WITH_EXAMPLES)
217210
endif()
218211
add_subdirectory(ext)
219212

213+
# Add nlohmann/json submodule to include directories
214+
include_directories(third_party/nlohmann-json/single_include)
215+
220216
# Export cmake config and support find_packages(opentelemetry-cpp CONFIG) Write
221217
# config file for find_packages(opentelemetry-cpp CONFIG)
222218
set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")

CMakeSettings.json

+116-98
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,126 @@
11
{
2-
"configurations": [
2+
"configurations": [
3+
{
4+
"name": "nostd-x64-Debug",
5+
"generator": "Ninja",
6+
"configurationType": "Debug",
7+
"inheritEnvironments": [
8+
"msvc_x64_x64"
9+
],
10+
"buildRoot": "${projectDir}\\out\\vs2019\\${name}",
11+
"installRoot": "${projectDir}\\out\\vs2019\\${name}\\install",
12+
"cmakeCommandArgs": "",
13+
"buildCommandArgs": "",
14+
"ctestCommandArgs": "",
15+
"variables": [
316
{
4-
"name": "nostd-x64-Debug",
5-
"generator": "Ninja",
6-
"configurationType": "Debug",
7-
"inheritEnvironments": [ "msvc_x64_x64" ],
8-
"buildRoot": "${projectDir}\\out\\vs2019\\${name}",
9-
"installRoot": "${projectDir}\\out\\vs2019\\${name}\\install",
10-
"cmakeCommandArgs": "",
11-
"buildCommandArgs": "",
12-
"ctestCommandArgs": "",
13-
"variables": [
14-
{
15-
"name": "WITH_OTLP",
16-
"value": "True",
17-
"type": "BOOL"
18-
},
19-
{
20-
"name": "WITH_EXAMPLES",
21-
"value": "true",
22-
"type": "BOOL"
23-
}
24-
]
17+
"name": "WITH_OTLP",
18+
"value": "True",
19+
"type": "BOOL"
2520
},
2621
{
27-
"name": "nostd-x64-Release",
28-
"generator": "Ninja",
29-
"configurationType": "RelWithDebInfo",
30-
"inheritEnvironments": [ "msvc_x64_x64" ],
31-
"buildRoot": "${projectDir}\\out\\vs2019\\${name}",
32-
"installRoot": "${projectDir}\\out\\vs2019\\${name}\\install",
33-
"cmakeCommandArgs": "",
34-
"buildCommandArgs": "",
35-
"ctestCommandArgs": "",
36-
"cmakeToolchain": "",
37-
"variables": [
38-
{
39-
"name": "WITH_OTLP",
40-
"value": "True",
41-
"type": "BOOL"
42-
},
43-
{
44-
"name": "WITH_EXAMPLES",
45-
"value": "true",
46-
"type": "BOOL"
47-
}
48-
]
22+
"name": "WITH_EXAMPLES",
23+
"value": "true",
24+
"type": "BOOL"
25+
}
26+
]
27+
},
28+
{
29+
"name": "nostd-x64-Release",
30+
"generator": "Ninja",
31+
"configurationType": "Release",
32+
"inheritEnvironments": [
33+
"msvc_x64_x64"
34+
],
35+
"buildRoot": "${projectDir}\\out\\vs2019\\${name}",
36+
"installRoot": "${projectDir}\\out\\vs2019\\${name}\\install",
37+
"cmakeCommandArgs": "",
38+
"buildCommandArgs": "",
39+
"ctestCommandArgs": "",
40+
"cmakeToolchain": "",
41+
"variables": [
42+
{
43+
"name": "WITH_OTLP",
44+
"value": "True",
45+
"type": "BOOL"
46+
},
47+
{
48+
"name": "WITH_EXAMPLES",
49+
"value": "true",
50+
"type": "BOOL"
51+
}
52+
]
53+
},
54+
{
55+
"name": "stdlib-x64-Debug",
56+
"generator": "Ninja",
57+
"configurationType": "Debug",
58+
"inheritEnvironments": [
59+
"msvc_x64_x64"
60+
],
61+
"buildRoot": "${projectDir}\\out\\vs2019\\${name}",
62+
"installRoot": "${projectDir}\\out\\vs2019\\${name}\\install",
63+
"cmakeCommandArgs": "",
64+
"buildCommandArgs": "",
65+
"ctestCommandArgs": "",
66+
"variables": [
67+
{
68+
"name": "WITH_STL",
69+
"value": "True",
70+
"type": "BOOL"
71+
},
72+
{
73+
"name": "WITH_OTLP",
74+
"value": "True",
75+
"type": "BOOL"
76+
},
77+
{
78+
"name": "WITH_EXAMPLES",
79+
"value": "true",
80+
"type": "BOOL"
81+
},
82+
{
83+
"name": "WITH_PROMETHEUS",
84+
"value": "True",
85+
"type": "BOOL"
86+
}
87+
]
88+
},
89+
{
90+
"name": "stdlib-x64-Release",
91+
"generator": "Ninja",
92+
"configurationType": "Release",
93+
"inheritEnvironments": [
94+
"msvc_x64_x64"
95+
],
96+
"buildRoot": "${projectDir}\\out\\vs2019\\${name}",
97+
"installRoot": "${projectDir}\\out\\vs2019\\${name}\\install",
98+
"cmakeCommandArgs": "",
99+
"buildCommandArgs": "",
100+
"ctestCommandArgs": "",
101+
"cmakeToolchain": "",
102+
"variables": [
103+
{
104+
"name": "WITH_STL",
105+
"value": "True",
106+
"type": "BOOL"
107+
},
108+
{
109+
"name": "WITH_OTLP",
110+
"value": "True",
111+
"type": "BOOL"
49112
},
50113
{
51-
"name": "stdlib-x64-Debug",
52-
"generator": "Ninja",
53-
"configurationType": "Debug",
54-
"inheritEnvironments": [ "msvc_x64_x64" ],
55-
"buildRoot": "${projectDir}\\out\\vs2019\\${name}",
56-
"installRoot": "${projectDir}\\out\\vs2019\\${name}\\install",
57-
"cmakeCommandArgs": "",
58-
"buildCommandArgs": "",
59-
"ctestCommandArgs": "",
60-
"variables": [
61-
{
62-
"name": "WITH_STL",
63-
"value": "True",
64-
"type": "BOOL"
65-
},
66-
{
67-
"name": "WITH_OTLP",
68-
"value": "True",
69-
"type": "BOOL"
70-
},
71-
{
72-
"name": "WITH_EXAMPLES",
73-
"value": "true",
74-
"type": "BOOL"
75-
}
76-
]
114+
"name": "WITH_EXAMPLES",
115+
"value": "true",
116+
"type": "BOOL"
77117
},
78118
{
79-
"name": "stdlib-x64-Release",
80-
"generator": "Ninja",
81-
"configurationType": "RelWithDebInfo",
82-
"inheritEnvironments": [ "msvc_x64_x64" ],
83-
"buildRoot": "${projectDir}\\out\\vs2019\\${name}",
84-
"installRoot": "${projectDir}\\out\\vs2019\\${name}\\install",
85-
"cmakeCommandArgs": "",
86-
"buildCommandArgs": "",
87-
"ctestCommandArgs": "",
88-
"cmakeToolchain": "",
89-
"variables": [
90-
{
91-
"name": "WITH_STL",
92-
"value": "True",
93-
"type": "BOOL"
94-
},
95-
{
96-
"name": "WITH_OTLP",
97-
"value": "True",
98-
"type": "BOOL"
99-
},
100-
{
101-
"name": "WITH_EXAMPLES",
102-
"value": "true",
103-
"type": "BOOL"
104-
}
105-
]
119+
"name": "WITH_PROMETHEUS",
120+
"value": "True",
121+
"type": "BOOL"
106122
}
107-
]
123+
]
124+
}
125+
]
108126
}

api/include/opentelemetry/common/attribute_value.h

+15-22
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ using AttributeValue =
1818
uint64_t,
1919
double,
2020
nostd::string_view,
21-
#ifdef HAVE_CSTRING_TYPE
22-
// TODO: add C-string as possible value on API surface
23-
const char *,
24-
#endif
2521
#ifdef HAVE_SPAN_BYTE
2622
// TODO: 8-bit byte arrays / binary blobs are not part of OT spec yet!
2723
// Ref: https://github.com/open-telemetry/opentelemetry-specification/issues/780
@@ -37,26 +33,23 @@ using AttributeValue =
3733

3834
enum AttributeType
3935
{
40-
TYPE_BOOL,
41-
TYPE_INT,
42-
TYPE_INT64,
43-
TYPE_UINT,
44-
TYPE_UINT64,
45-
TYPE_DOUBLE,
46-
TYPE_STRING,
47-
#ifdef HAVE_CSTRING_TYPE
48-
TYPE_CSTRING,
49-
#endif
36+
kTypeBool,
37+
kTypeInt,
38+
kTypeInt64,
39+
kTypeUInt,
40+
kTypeUInt64,
41+
kTypeDouble,
42+
kTypeString,
5043
#ifdef HAVE_SPAN_BYTE
51-
TYPE_SPAN_BYTE,
44+
kTypeSpanByte,
5245
#endif
53-
TYPE_SPAN_BOOL,
54-
TYPE_SPAN_INT,
55-
TYPE_SPAN_INT64,
56-
TYPE_SPAN_UINT,
57-
TYPE_SPAN_UINT64,
58-
TYPE_SPAN_DOUBLE,
59-
TYPE_SPAN_STRING
46+
kTypeSpanBool,
47+
kTypeSpanInt,
48+
kTypeSpanInt64,
49+
kTypeSpanUInt,
50+
kTypeSpanUInt64,
51+
kTypeSpanDouble,
52+
kTypeSpanString
6053
};
6154

6255
} // namespace common

api/include/opentelemetry/common/key_value_iterable_view.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,19 @@ struct is_key_value_iterable
3030
};
3131
} // namespace detail
3232

33+
/**
34+
* @brief Container for key-value pairs that can transform every value in it to one of types
35+
* listed in common::AttributeValue. It may contain value types that are not directly map'able
36+
* to primitive value types. In that case the `ForEachKeyValue` method acts as a transform to
37+
* convert the value type to one listed under AtributeValue (bool, int32_t, int64_t, uint32_t,
38+
* uint64_t, double, nostd::string_view, or arrays of primite types). For example, if UUID,
39+
* GUID, or UTF-16 string type is passed as one of values stored inside this container, the
40+
* container itself may provide a custom implementation of `ForEachKeyValue` to transform the
41+
* 'non-standard' type to one of the standard types.
42+
*/
3343
template <class T>
3444
class KeyValueIterableView final : public KeyValueIterable
3545
{
36-
static_assert(detail::is_key_value_iterable<T>::value, "Must be a key-value iterable");
3746

3847
public:
3948
explicit KeyValueIterableView(const T &container) noexcept : container_{&container} {}

api/include/opentelemetry/trace/span_context_kv_iterable.h

+17
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,22 @@ class SpanContextKeyValueIterable
3030
*/
3131
virtual size_t size() const noexcept = 0;
3232
};
33+
34+
/**
35+
* @brief Null Span context that does not carry any information.
36+
*/
37+
class NullSpanContext : public SpanContextKeyValueIterable
38+
{
39+
public:
40+
bool ForEachKeyValue(
41+
nostd::function_ref<bool(SpanContext, const opentelemetry::common::KeyValueIterable &)>
42+
callback) const noexcept override
43+
{
44+
return true;
45+
}
46+
47+
size_t size() const noexcept override { return 0; };
48+
};
49+
3350
} // namespace trace
3451
OPENTELEMETRY_END_NAMESPACE

0 commit comments

Comments
 (0)