Skip to content

Commit 688525f

Browse files
committed
feat: optional .end function to end spans, destruction still ends if not ended
1 parent cb2207f commit 688525f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

observe-api/cxx/observe_api.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,17 @@ void statsd(std::string_view mtc);
2828
void span_tags(std::vector<std::string> &tags);
2929

3030
class Span {
31+
bool ended;
32+
3133
public:
32-
Span(std::string_view name) { span_enter(name); }
33-
~Span() { span_exit(); }
34+
Span(std::string_view name) : ended(false) { span_enter(name); }
35+
void end() {
36+
if (!ended) {
37+
ended = true;
38+
span_exit();
39+
}
40+
}
41+
~Span() { end(); }
3442
void metric(enum DO_METRIC_FMT format, std::string_view mtc) {
3543
observe_api::metric(format, mtc);
3644
}

observe-api/test/cxx_guest_3.wasm

150 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)