Skip to content
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

chore: namespace observe c api #164

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions go/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,15 @@ func (b *AdapterBase) MakeOtelCallSpans(event CallEvent, parentId []byte, traceI
spans = append(spans, b.MakeOtelCallSpans(call, span.SpanId, traceId)...)
}
if alloc, ok := ev.(MemoryGrowEvent); ok {
last := spans[len(spans)-1]

kv := NewOtelKeyValueInt64("allocation", int64(alloc.MemoryGrowAmount()))
i, existing := GetOtelAttrFromSpan("allocation", last)
i, existing := GetOtelAttrFromSpan("allocation", span)
if existing != nil {
last.Attributes[i] = AddOtelKeyValueInt64(kv, existing)
span.Attributes[i] = AddOtelKeyValueInt64(kv, existing)
} else {
last.Attributes = append(last.Attributes, kv)
span.Attributes = append(span.Attributes, kv)
}
}
if tags, ok := ev.(SpanTagsEvent); ok {
last := spans[len(spans)-1]

for _, tag := range tags.Tags {
parts := strings.Split(tag, ":")
if len(parts) != 2 {
Expand All @@ -121,7 +117,7 @@ func (b *AdapterBase) MakeOtelCallSpans(event CallEvent, parentId []byte, traceI
}

kv := NewOtelKeyValueString(parts[0], parts[1])
last.Attributes = append(last.Attributes, kv)
span.Attributes = append(span.Attributes, kv)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions observe-api/c/observe_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
#include <stdlib.h>
#include <string.h>

void span_enter(const char *name) {
void observe_api_span_enter(const char *name) {
const uint32_t uint32_ptr = (uint32_t)name;
const uint32_t uint32_length = strlen(name);
_span_enter(uint32_ptr, uint32_length);
}

void span_exit(void) { _span_exit(); }
void observe_api_span_exit(void) { _span_exit(); }

void metric(const char *metric) {
void observe_api_metric(const char *metric) {
const uint32_t uint32_ptr = (uint32_t)metric;
const uint32_t uint32_length = strlen(metric);
_metric(1, uint32_ptr, uint32_length);
}

void write_log(const enum DO_LOG_LEVEL level, const char *msg) {
void observe_api_write_log(const enum DO_LOG_LEVEL level, const char *msg) {
const uint32_t uint32_ptr = (uint32_t)msg;
const uint32_t uint32_length = strlen(msg);
const uint32_t uint32_level = level;
Expand Down
16 changes: 12 additions & 4 deletions observe-api/c/observe_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ enum DO_LOG_LEVEL {
DO_LL_TRACE = 4
};

void span_enter(const char *name);
void span_exit(void);
void metric(const char *metric);
void write_log(const enum DO_LOG_LEVEL level, const char *msg);
#ifdef __cplusplus
extern "C" {
#endif

void observe_api_span_enter(const char *name);
void observe_api_span_exit(void);
void observe_api_metric(const char *metric);
void observe_api_write_log(const enum DO_LOG_LEVEL level, const char *msg);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 4 additions & 4 deletions observe-api/test/c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#include <stdlib.h>

void run() {
span_enter("printf");
observe_api_span_enter("printf");
printf("Hello from Wasm!\n");
span_exit();
observe_api_span_exit();
}

int main(int argc, char *argv[]) {
span_enter("run");
observe_api_span_enter("run");
run();
span_exit();
observe_api_span_exit();

return 0;
}
Binary file modified observe-api/test/c_guest.wasm
Binary file not shown.
Binary file modified observe-api/test/cxx_guest.wasm
Binary file not shown.
Loading