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

fix(go): make sure metric and logs events are added to the current span #172

Merged
merged 1 commit into from
Aug 19, 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
14 changes: 8 additions & 6 deletions go/adapter/stdout/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ func (s *StdoutAdapter) printEvents(event observe.CallEvent, indentation int) {
for _, event := range event.Within() {
if call, ok := event.(observe.CallEvent); ok {
s.printEvents(call, indentation+1)
}
if alloc, ok := event.(observe.MemoryGrowEvent); ok {
log.Println(strings.Repeat(" ", indentation), "Allocated", alloc.MemoryGrowAmount(), "pages of memory in", name)
}
if spanTags, ok := event.(observe.SpanTagsEvent); ok {
log.Println(strings.Repeat(" ", indentation), "Span tags:", spanTags.Tags)
} else if alloc, ok := event.(observe.MemoryGrowEvent); ok {
log.Println(strings.Repeat(" ", indentation), " - Allocated", alloc.MemoryGrowAmount(), "pages of memory in", name)
} else if spanTags, ok := event.(observe.SpanTagsEvent); ok {
log.Println(strings.Repeat(" ", indentation), " - Span tags:", spanTags.Tags)
} else if metric, ok := event.(observe.MetricEvent); ok {
log.Println(strings.Repeat(" ", indentation), " - Metric:", metric.Message)
} else if logEvent, ok := event.(observe.LogEvent); ok {
log.Println(strings.Repeat(" ", indentation), " - Log:", logEvent.Message)
}
}
}
Expand Down
23 changes: 17 additions & 6 deletions go/trace_ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ func (t *TraceCtx) init(ctx context.Context, r wazero.Runtime) error {
t.pushFunction(fn)
}

metricFunc := func(ctx context.Context, m api.Module, f uint32, ptr uint32, len uint32) {
metricFunc := func(ctx context.Context, m api.Module, f uint32, ptr uint32, l uint32) {
format := MetricFormat(f)
buffer, ok := m.Memory().Read(ptr, len)
buffer, ok := m.Memory().Read(ptr, l)
if !ok {
log.Printf("metric: failed to read memory at offset %v with length %v\n", ptr, len)
log.Printf("metric: failed to read memory at offset %v with length %v\n", ptr, l)
}

event := MetricEvent{
Expand All @@ -169,7 +169,13 @@ func (t *TraceCtx) init(ctx context.Context, r wazero.Runtime) error {
Message: string(buffer),
}

t.events = append(t.events, event)
fn, ok := t.popFunction()
if !ok {
t.events = append(t.events, event)
return
}
fn.within = append(fn.within, event)
t.pushFunction(fn)
}

oldMetricFunc := func(ctx context.Context, m api.Module, f uint32, ptr uint64, len uint32) {
Expand Down Expand Up @@ -201,7 +207,6 @@ func (t *TraceCtx) init(ctx context.Context, r wazero.Runtime) error {
}
fn.within = append(fn.within, event)
t.pushFunction(fn)

}

oldSpanTagsFunc := func(ctx context.Context, m api.Module, ptr uint64, len uint32) {
Expand All @@ -226,7 +231,13 @@ func (t *TraceCtx) init(ctx context.Context, r wazero.Runtime) error {
Message: string(buffer),
}

t.events = append(t.events, event)
fn, ok := t.popFunction()
if !ok {
t.events = append(t.events, event)
return
}
fn.within = append(fn.within, event)
t.pushFunction(fn)
}

oldLogFunc := func(ctx context.Context, m api.Module, l uint32, ptr uint64, len uint32) {
Expand Down
Loading