-
Notifications
You must be signed in to change notification settings - Fork 0
Add runtime resource attributes, span status/kind, and fix ODR singletons #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
cc83134
1a7065e
cf47735
0c75f5b
154ba81
a639e5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -30,7 +30,7 @@ struct TraceContext { | |||||
| bool valid() const { return traceId.length() == 32 && spanId.length() == 16; } | ||||||
| }; | ||||||
|
|
||||||
| static inline TraceContext& currentTraceContext() { | ||||||
| inline TraceContext& currentTraceContext() { | ||||||
| static TraceContext ctx; | ||||||
| return ctx; | ||||||
| } | ||||||
|
|
@@ -405,20 +405,38 @@ static inline String generateSpanId() { | |||||
|
|
||||||
|
|
||||||
|
|
||||||
| // Add one string attribute to a resource attributes array | ||||||
| // ---- Deprecated: use buildResourceAttributes() instead ---------------------- | ||||||
| // Kept for backwards compatibility with existing user code. | ||||||
| [[deprecated("Use buildResourceAttributes() instead")]] | ||||||
| static inline void addResAttr(JsonArray& arr, const char* key, const String& value) { | ||||||
| JsonObject a = arr.add<JsonObject>(); | ||||||
| a["key"] = key; | ||||||
| a["value"].to<JsonObject>()["stringValue"] = value; | ||||||
| } | ||||||
|
|
||||||
| // ---- OTLP SpanKind constants ------------------------------------------------ | ||||||
| namespace SpanKind { | ||||||
| constexpr int INTERNAL = 1; | ||||||
| constexpr int SERVER = 2; | ||||||
| constexpr int CLIENT = 3; | ||||||
| constexpr int PRODUCER = 4; | ||||||
| constexpr int CONSUMER = 5; | ||||||
| } | ||||||
|
|
||||||
| // ---- OTLP StatusCode constants ---------------------------------------------- | ||||||
| namespace StatusCode { | ||||||
| constexpr int UNSET = 0; | ||||||
| constexpr int OK = 1; | ||||||
| constexpr int ERROR = 2; | ||||||
| } | ||||||
|
|
||||||
| // ---- Tracer configuration --------------------------------------------------- | ||||||
| struct TracerConfig { | ||||||
| String scopeName{"otel-embedded"}; | ||||||
| String scopeVersion{"0.1.0"}; | ||||||
| }; | ||||||
|
|
||||||
| static inline TracerConfig& tracerConfig() { | ||||||
| inline TracerConfig& tracerConfig() { | ||||||
| static TracerConfig cfg; | ||||||
| return cfg; | ||||||
| } | ||||||
|
|
@@ -460,6 +478,9 @@ class Span { | |||||
| prevSpanId_(std::move(o.prevSpanId_)), | ||||||
| attrs_(std::move(o.attrs_)), | ||||||
| events_(std::move(o.events_)), | ||||||
| kind_(o.kind_), | ||||||
| statusCode_(o.statusCode_), | ||||||
| statusMessage_(std::move(o.statusMessage_)), | ||||||
| ended_(o.ended_) | ||||||
| { | ||||||
| o.ended_ = true; // source dtor becomes a no-op | ||||||
|
|
@@ -478,6 +499,9 @@ class Span { | |||||
| prevSpanId_ = std::move(o.prevSpanId_); | ||||||
| attrs_ = std::move(o.attrs_); | ||||||
| events_ = std::move(o.events_); | ||||||
| kind_ = o.kind_; | ||||||
| statusCode_ = o.statusCode_; | ||||||
| statusMessage_ = std::move(o.statusMessage_); | ||||||
| ended_ = o.ended_; | ||||||
| o.ended_ = true; // source won't end() again | ||||||
| o.prevTraceId_ = ""; | ||||||
|
|
@@ -486,7 +510,35 @@ class Span { | |||||
| return *this; | ||||||
| } | ||||||
|
|
||||||
| // ---------- NEW: span attributes API --------------------------------------- | ||||||
| // ---------- Span status (OTLP StatusCode) ----------------------------------- | ||||||
| Span& setStatus(int code, const String& message = "") { | ||||||
| if (code >= StatusCode::UNSET && code <= StatusCode::ERROR) { | ||||||
| statusCode_ = code; | ||||||
| } else { | ||||||
| statusCode_ = StatusCode::UNSET; | ||||||
| Serial.printf("[otel] WARNING: invalid status code %d, defaulting to UNSET\n", code); | ||||||
| } | ||||||
| statusMessage_ = message; | ||||||
| return *this; | ||||||
| } | ||||||
| Span& setError(const String& message = "") { | ||||||
| return setStatus(StatusCode::ERROR, message); | ||||||
| } | ||||||
| Span& setOk() { | ||||||
| return setStatus(StatusCode::OK); | ||||||
| } | ||||||
|
|
||||||
| // ---------- Span kind (OTLP SpanKind) -------------------------------------- | ||||||
| Span& setKind(int kind) { | ||||||
| if (kind >= SpanKind::INTERNAL && kind <= SpanKind::CONSUMER) { | ||||||
| kind_ = kind; | ||||||
| } else { | ||||||
| Serial.printf("[otel] WARNING: invalid span kind %d, keeping SERVER\n", kind); | ||||||
|
||||||
| Serial.printf("[otel] WARNING: invalid span kind %d, keeping SERVER\n", kind); | |
| Serial.printf("[otel] WARNING: invalid span kind %d, keeping previous kind (%d)\n", kind, kind_); |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setStatus() / setKind() unconditionally emit warnings via Serial.printf, which introduces I/O side effects from a header-only library and may be undesirable in production builds (and printf support varies across Arduino cores). Consider guarding these warnings behind a compile-time flag (e.g., #ifdef DEBUG) or routing through an optional debug/log macro so normal builds stay silent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation in
buildResourceAttributes()is inconsistent with the surrounding code in this header (most functions use 2-space indentation). Reformatting this block to match the file’s existing style would improve readability and reduce diff noise in future changes.