Skip to content

Commit f8c96db

Browse files
authored
fixes generation error creation (#15)
### TL;DR Fix generation error handling and add documentation to trace.go ### What changed? - Fixed the `SetError` method in `Generation` to use "result" instead of "update" event type and properly structure the error data - Added automatic call to `End()` after setting an error in a generation - Updated `SetGenerationError` in `Logger` to match the same pattern and end the generation after setting an error - Added documentation comments to all functions and types in trace.go ### How to test? 1. Verify that error handling in generations works correctly by triggering an error condition 2. Confirm that generations are properly ended after an error is set 3. Check that the error data is correctly structured in the logs ### Why make this change? This change ensures consistent error handling in generations and properly ends generations after errors occur, preventing hanging or incomplete generation records. The added documentation in trace.go improves code readability and helps developers understand the purpose of each component in the tracing system.
2 parents dc5cefa + 809d543 commit f8c96db

File tree

4 files changed

+71
-5
lines changed

4 files changed

+71
-5
lines changed

.gitignore

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,54 @@
1-
testConfig.json
1+
# Project specific
2+
testConfig.json
3+
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool
15+
*.out
16+
coverage.txt
17+
coverage.html
18+
19+
# Dependency directories
20+
vendor/
21+
22+
# Go workspace file
23+
go.work
24+
go.work.sum
25+
26+
# Build artifacts
27+
dist/
28+
build/
29+
bin/
30+
31+
# IDE specific files
32+
.vscode/
33+
.idea/
34+
*.swp
35+
*.swo
36+
*~
37+
.DS_Store
38+
39+
# Air (live reload) tmp directory
40+
tmp/
41+
42+
# Environment variables
43+
.env
44+
.env.local
45+
.env.*.local
46+
47+
# Logs
48+
*.log
49+
50+
# Debug files
51+
__debug_bin
52+
debug
53+
54+
.DS_Store

logging/generation.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,12 @@ func (g *Generation) SetResult(r interface{}) {
288288

289289
func (g *Generation) SetError(err *GenerationError) {
290290
g.error = err
291-
g.commit("update", map[string]interface{}{
292-
"error": g.error,
291+
g.commit("result", map[string]interface{}{
292+
"result": map[string]interface{}{
293+
"error": g.error,
294+
},
293295
})
296+
g.End()
294297
}
295298

296299
func (g *Generation) data() map[string]interface{} {

logging/logger.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,12 @@ func (l *Logger) AddResultToGeneration(gId string, result interface{}) {
253253

254254
// SetGenerationError sets an error for the specified generation
255255
func (l *Logger) SetGenerationError(gId string, error *GenerationError) {
256-
l.writer.commit(newCommitLog(EntityGeneration, gId, "error", map[string]interface{}{
257-
"error": error,
256+
l.writer.commit(newCommitLog(EntityGeneration, gId, "result", map[string]interface{}{
257+
"result": map[string]interface{}{
258+
"error": error,
259+
},
258260
}))
261+
end(l.writer, EntityGeneration, gId)
259262
}
260263

261264
// EndGeneration marks the specified generation as ended

logging/trace.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package logging
22

3+
// TraceConfig represents the configuration for a trace
34
type TraceConfig struct {
45
Id string `json:"id"`
56
SpanId *string `json:"spanId,omitempty"`
@@ -8,11 +9,13 @@ type TraceConfig struct {
89
SessionId *string
910
}
1011

12+
// Trace represents a trace in the logging system
1113
type Trace struct {
1214
*eventEmitter
1315
SessionId *string
1416
}
1517

18+
// newTrace creates a new trace
1619
func newTrace(c *TraceConfig, w *writer) *Trace {
1720
t := &Trace{
1821
eventEmitter: &eventEmitter{
@@ -31,6 +34,7 @@ func newTrace(c *TraceConfig, w *writer) *Trace {
3134
return t
3235
}
3336

37+
// AddGeneration adds a generation to the trace
3438
func (t *Trace) AddGeneration(c *GenerationConfig) *Generation {
3539
g := newGeneration(c, t.writer)
3640
gData := g.data()
@@ -39,10 +43,12 @@ func (t *Trace) AddGeneration(c *GenerationConfig) *Generation {
3943
return g
4044
}
4145

46+
// SetFeedback adds a feedback to the trace
4247
func (t *Trace) SetFeedback(f *Feedback) {
4348
t.commit("add-feedback", f)
4449
}
4550

51+
// AddSpan adds a span to the trace
4652
func (t *Trace) AddSpan(c *SpanConfig) *Span {
4753
s := newSpan(c, t.writer)
4854
sData := s.data()
@@ -51,6 +57,7 @@ func (t *Trace) AddSpan(c *SpanConfig) *Span {
5157
return s
5258
}
5359

60+
// AddRetrieval adds a retrieval to the trace
5461
func (t *Trace) AddRetrieval(c *RetrievalConfig) *Retrieval {
5562
r := newRetrieval(c, t.writer)
5663
rData := r.data()

0 commit comments

Comments
 (0)