Skip to content

Commit 8d392ab

Browse files
committed
refactor end span
1 parent e0a5b01 commit 8d392ab

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

.golangci.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@ linters:
7272
forbid:
7373
- pattern: "^new$"
7474
msg: "Use &Type{} instead."
75-
# - pattern: os\.Getenv
76-
# msg: "Add your field to the configuration model instead."
75+
# - pattern: os\.Getenv
76+
# msg: "Add your field to the configuration model instead."
7777

7878
gocritic:
7979
disabled-checks:
8080
- appendAssign
8181
revive:
8282
enable-all-rules: true
8383
rules:
84-
- { disabled: true, name: add-constant } # todo: enable this
84+
- { disabled: true, name: add-constant } # todo: enable this
8585
- { disabled: true, name: argument-limit }
8686
- { disabled: true, name: bare-return }
8787
- { disabled: true, name: blank-imports }
@@ -96,7 +96,7 @@ linters:
9696
- { disabled: true, name: early-return }
9797
- { disabled: true, name: enforce-switch-style }
9898
- { disabled: true, name: exported }
99-
- { disabled: true, name: flag-parameter } # todo: enable this
99+
- { disabled: true, name: flag-parameter } # todo: enable this
100100
- { disabled: true, name: function-length }
101101
- { disabled: true, name: function-result-limit }
102102
- { disabled: true, name: get-return }
@@ -109,24 +109,24 @@ linters:
109109
- { disabled: true, name: package-comments }
110110
- { disabled: true, name: unchecked-type-assertion }
111111
- { disabled: true, name: unexported-naming }
112-
- { disabled: true, name: unhandled-error } # todo: enable this
113-
- { disabled: true, name: unnecessary-format } # todo: enable this
114-
- { disabled: true, name: unnecessary-stmt } # todo: enable this
112+
- { disabled: true, name: unhandled-error } # todo: enable this
113+
- { disabled: true, name: unnecessary-format } # todo: enable this
114+
- { disabled: true, name: unnecessary-stmt } # todo: enable this
115115
- { disabled: true, name: unused-receiver }
116-
- { disabled: true, name: use-errors-new } # todo: enable this
116+
- { disabled: true, name: use-errors-new } # todo: enable this
117117
- { disabled: true, name: var-declaration }
118118
- { disabled: true, name: var-naming }
119119

120120
staticcheck:
121121
checks:
122122
- all
123-
- -S1002 # Omit comparison with boolean constant
124-
- -SA1019 # TODO: Remove (Using a deprecated function, variable, constant or field)
125-
- -ST1000 # Incorrect or missing package comment
126-
- -ST1020 # The documentation of an exported function should start with the function’s name
127-
- -ST1021 # The documentation of an exported type should start with type’s name
128-
- -ST1003 # Poorly chosen identifier
129-
- -QF1008 # Omit embedded fields from selector expression
123+
- -S1002 # Omit comparison with boolean constant
124+
- -SA1019 # TODO: Remove (Using a deprecated function, variable, constant or field)
125+
- -ST1000 # Incorrect or missing package comment
126+
- -ST1020 # The documentation of an exported function should start with the function’s name
127+
- -ST1021 # The documentation of an exported type should start with type’s name
128+
- -ST1003 # Poorly chosen identifier
129+
- -QF1008 # Omit embedded fields from selector expression
130130

131131
run:
132132
go: 1.24.7

packages/orchestrator/internal/sandbox/sandbox.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (f *Factory) CreateSandbox(
170170
apiConfigToStore *orchestrator.SandboxConfig,
171171
) (s *Sandbox, e error) {
172172
ctx, span := tracer.Start(ctx, "create sandbox")
173-
defer func() { endSpan(span, e) }()
173+
defer endSpan(span, &e)
174174

175175
execCtx, execSpan := startExecutionSpan(ctx)
176176

@@ -181,7 +181,7 @@ func (f *Factory) CreateSandbox(
181181
if e != nil {
182182
cleanupErr := cleanup.Run(ctx)
183183
e = errors.Join(e, cleanupErr)
184-
endSpan(execSpan, e)
184+
endSpan(execSpan, &e)
185185
}
186186
}()
187187

@@ -331,10 +331,11 @@ func (f *Factory) CreateSandbox(
331331
return sbx, nil
332332
}
333333

334-
func endSpan(span trace.Span, err error) {
335-
if err != nil {
336-
span.RecordError(err)
337-
span.SetStatus(codes.Error, err.Error())
334+
// Usage: defer endSpan(span, &err)
335+
func endSpan(span trace.Span, err *error) {
336+
if err != nil && *err != nil {
337+
span.RecordError(*err)
338+
span.SetStatus(codes.Error, (*err).Error())
338339
}
339340

340341
span.End()
@@ -352,7 +353,7 @@ func (f *Factory) ResumeSandbox(
352353
apiConfigToStore *orchestrator.SandboxConfig,
353354
) (s *Sandbox, e error) {
354355
ctx, span := tracer.Start(ctx, "resume sandbox")
355-
defer func() { endSpan(span, e) }()
356+
defer endSpan(span, &e)
356357

357358
execCtx, execSpan := startExecutionSpan(ctx)
358359

@@ -363,7 +364,7 @@ func (f *Factory) ResumeSandbox(
363364
if e != nil {
364365
cleanupErr := cleanup.Run(ctx)
365366
e = errors.Join(e, cleanupErr)
366-
endSpan(execSpan, e)
367+
endSpan(execSpan, &e)
367368
}
368369
}()
369370

0 commit comments

Comments
 (0)