Skip to content

Commit 84ba218

Browse files
authored
Merge branch 'main' into exporter-elasticsearch-resources
2 parents f9ade0a + 95d039c commit 84ba218

File tree

31 files changed

+523
-58
lines changed

31 files changed

+523
-58
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,3 +925,42 @@ jobs:
925925
- name: run ./ci/docfx.cmd
926926
shell: cmd
927927
run: ./ci/docfx.cmd
928+
929+
w3c_trace_context_compliance_v1:
930+
name: W3C Distributed Tracing Validation V1
931+
runs-on: ubuntu-latest
932+
steps:
933+
- name: Checkout open-telemetry/opentelemetry-cpp
934+
uses: actions/checkout@v4
935+
with:
936+
submodules: 'recursive'
937+
- name: setup
938+
env:
939+
CC: /usr/bin/gcc-10
940+
CXX: /usr/bin/g++-10
941+
run: |
942+
sudo -E ./ci/setup_googletest.sh
943+
sudo -E ./ci/setup_ci_environment.sh
944+
- name: run w3c trace-context test server (background)
945+
env:
946+
CXX_STANDARD: '14'
947+
run: |
948+
./ci/do_ci.sh cmake.w3c.trace-context.build-server
949+
cd $HOME/build/ext/test/w3c_tracecontext_test
950+
./w3c_tracecontext_test &
951+
- name: Checkout w3c/trace-context repo
952+
uses: actions/checkout@v4
953+
with:
954+
repository: w3c/trace-context
955+
path: trace-context
956+
- name: install dependencies
957+
run: |
958+
sudo apt update && sudo apt install python3-pip
959+
sudo pip3 install aiohttp
960+
- name: run w3c trace-context test suite
961+
env:
962+
SPEC_LEVEL: 1
963+
run:
964+
|
965+
python ${GITHUB_WORKSPACE}/trace-context/test/test.py http://localhost:30000/test TraceContextTest AdvancedTest
966+
curl http://localhost:30000/stop

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Increment the:
1515

1616
## [Unreleased]
1717

18+
* [API] Comply with W3C Trace Context [#3115](https://github.com/open-telemetry/opentelemetry-cpp/pull/3115)
19+
* Also adds CI check to ensure continued compliance
20+
1821
* [API] Jaeger Propagator should not be deprecated
1922
[#3086](https://github.com/open-telemetry/opentelemetry-cpp/pull/3086)
2023

@@ -29,6 +32,9 @@ Important changes:
2932
as the Jaeger propagator can be used without the (now removed)
3033
Jaeger exporter.
3134

35+
* Upgrade to prometheus 1.3.0
36+
[#3122](https://github.com/open-telemetry/opentelemetry-cpp/pull/3122)
37+
3238
## [1.17 2024-10-07]
3339

3440
* [CI] Add a clang-tidy build

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ option(
215215
"Whether to include gzip compression for the OTLP http exporter in the SDK"
216216
OFF)
217217

218+
option(WITH_CURL_LOGGING "Whether to enable select CURL verbosity in OTel logs"
219+
OFF)
220+
218221
option(WITH_ZIPKIN "Whether to include the Zipkin exporter in the SDK" OFF)
219222

220223
option(WITH_PROMETHEUS "Whether to include the Prometheus Client in the SDK"

api/include/opentelemetry/common/spin_lock_mutex.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ class SpinLockMutex
6868
# else
6969
__builtin_ia32_pause();
7070
# endif
71-
#elif defined(__arm__)
72-
__asm__ volatile("yield" ::: "memory");
71+
#elif defined(__armel__) || defined(__ARMEL__)
72+
asm volatile("nop" ::: "memory");
73+
#elif defined(__arm__) || defined(__aarch64__) // arm big endian / arm64
74+
__asm__ __volatile__("yield" ::: "memory");
7375
#else
7476
// TODO: Issue PAGE/YIELD on other architectures.
7577
#endif

api/include/opentelemetry/common/string_util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ class StringUtil
1515
public:
1616
static nostd::string_view Trim(nostd::string_view str, size_t left, size_t right) noexcept
1717
{
18-
while (left <= right && str[static_cast<std::size_t>(left)] == ' ')
18+
while (left <= right && isspace(str[left]))
1919
{
2020
left++;
2121
}
22-
while (left <= right && str[static_cast<std::size_t>(right)] == ' ')
22+
while (left <= right && isspace(str[right]))
2323
{
2424
right--;
2525
}

api/include/opentelemetry/logs/event_logger.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ class EventLogger
6565
}
6666
nostd::unique_ptr<LogRecord> log_record = delegate_logger->CreateLogRecord();
6767

68-
IgnoreTraitResult(
69-
detail::LogRecordSetterTrait<typename std::decay<ArgumentType>::type>::template Set(
70-
log_record.get(), std::forward<ArgumentType>(args))...);
68+
IgnoreTraitResult(detail::LogRecordSetterTrait<typename std::decay<ArgumentType>::type>::Set(
69+
log_record.get(), std::forward<ArgumentType>(args))...);
7170

7271
EmitEvent(event_name, std::move(log_record));
7372
}

api/include/opentelemetry/logs/logger.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ class Logger
7272
return;
7373
}
7474

75-
IgnoreTraitResult(
76-
detail::LogRecordSetterTrait<typename std::decay<ArgumentType>::type>::template Set(
77-
log_record.get(), std::forward<ArgumentType>(args))...);
75+
IgnoreTraitResult(detail::LogRecordSetterTrait<typename std::decay<ArgumentType>::type>::Set(
76+
log_record.get(), std::forward<ArgumentType>(args))...);
7877

7978
EmitLogRecord(std::move(log_record));
8079
}

api/include/opentelemetry/logs/logger_type_traits.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ struct LogRecordSetterTrait
166166
* = nullptr>
167167
inline static LogRecord *Set(LogRecord *log_record, ArgumentType &&arg) noexcept
168168
{
169-
return LogRecordSetterTrait<common::KeyValueIterable>::template Set(
170-
log_record, std::forward<ArgumentType>(arg));
169+
return LogRecordSetterTrait<common::KeyValueIterable>::Set(log_record,
170+
std::forward<ArgumentType>(arg));
171171
}
172172

173173
template <class ArgumentType,

api/include/opentelemetry/trace/propagation/http_trace_context.h

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,8 @@ class HttpTraceContext : public context::propagation::TextMapPropagator
8686
}
8787

8888
private:
89-
static constexpr uint8_t kInvalidVersion = 0xFF;
90-
91-
static bool IsValidVersion(nostd::string_view version_hex)
92-
{
93-
uint8_t version;
94-
detail::HexToBinary(version_hex, &version, sizeof(version));
95-
return version != kInvalidVersion;
96-
}
89+
static constexpr uint8_t kInvalidVersion = 0xFF;
90+
static constexpr uint8_t kDefaultAssumedVersion = 0x00;
9791

9892
static void InjectImpl(context::propagation::TextMapCarrier &carrier,
9993
const SpanContext &span_context)
@@ -122,11 +116,6 @@ class HttpTraceContext : public context::propagation::TextMapPropagator
122116
static SpanContext ExtractContextFromTraceHeaders(nostd::string_view trace_parent,
123117
nostd::string_view trace_state)
124118
{
125-
if (trace_parent.size() != kTraceParentSize)
126-
{
127-
return SpanContext::GetInvalid();
128-
}
129-
130119
std::array<nostd::string_view, 4> fields{};
131120
if (detail::SplitString(trace_parent, '-', fields.data(), 4) != 4)
132121
{
@@ -150,11 +139,33 @@ class HttpTraceContext : public context::propagation::TextMapPropagator
150139
return SpanContext::GetInvalid();
151140
}
152141

153-
if (!IsValidVersion(version_hex))
142+
// hex is valid, convert it to binary
143+
uint8_t version_binary;
144+
detail::HexToBinary(version_hex, &version_binary, sizeof(version_binary));
145+
if (version_binary == kInvalidVersion)
154146
{
147+
// invalid version encountered
155148
return SpanContext::GetInvalid();
156149
}
157150

151+
// See https://www.w3.org/TR/trace-context/#versioning-of-traceparent
152+
if (version_binary > kDefaultAssumedVersion)
153+
{
154+
// higher than default version detected
155+
if (trace_parent.size() < kTraceParentSize)
156+
{
157+
return SpanContext::GetInvalid();
158+
}
159+
}
160+
else
161+
{
162+
// version is either lower or same as the default version
163+
if (trace_parent.size() != kTraceParentSize)
164+
{
165+
return SpanContext::GetInvalid();
166+
}
167+
}
168+
158169
TraceId trace_id = TraceIdFromHex(trace_id_hex);
159170
SpanId span_id = SpanIdFromHex(span_id_hex);
160171

@@ -169,7 +180,8 @@ class HttpTraceContext : public context::propagation::TextMapPropagator
169180

170181
static SpanContext ExtractImpl(const context::propagation::TextMapCarrier &carrier)
171182
{
172-
nostd::string_view trace_parent = carrier.Get(kTraceParent);
183+
// Get trace_parent after trimming the leading and trailing whitespaces
184+
nostd::string_view trace_parent = common::StringUtil::Trim(carrier.Get(kTraceParent));
173185
nostd::string_view trace_state = carrier.Get(kTraceState);
174186
if (trace_parent == "")
175187
{

api/include/opentelemetry/trace/trace_state.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class OPENTELEMETRY_EXPORT TraceState
5959
size_t cnt = kv_str_tokenizer.NumTokens(); // upper bound on number of kv pairs
6060
if (cnt > kMaxKeyValuePairs)
6161
{
62-
cnt = kMaxKeyValuePairs;
62+
// trace state should be discarded if count exceeds
63+
return GetDefault();
6364
}
6465

6566
nostd::shared_ptr<TraceState> ts(new TraceState(cnt));

0 commit comments

Comments
 (0)