MCPcopy Create free account
hub / github.com/astercloud/aster / SetAttribute

Function SetAttribute

server/observability/tracing.go:158–174  ·  view source on GitHub ↗

SetAttribute 设置属性到当前 span

(ctx context.Context, key string, value any)

Source from the content-addressed store, hash-verified

156
157// SetAttribute 设置属性到当前 span
158func SetAttribute(ctx context.Context, key string, value any) {
159 span := trace.SpanFromContext(ctx)
160 if span != nil && span.IsRecording() {
161 switch v := value.(type) {
162 case string:
163 span.SetAttributes(attribute.String(key, v))
164 case int:
165 span.SetAttributes(attribute.Int(key, v))
166 case int64:
167 span.SetAttributes(attribute.Int64(key, v))
168 case bool:
169 span.SetAttributes(attribute.Bool(key, v))
170 default:
171 span.SetAttributes(attribute.String(key, fmt.Sprintf("%v", v)))
172 }
173 }
174}
175
176// RecordError 记录错误到当前 span
177func RecordError(ctx context.Context, err error) {

Callers

nothing calls this directly

Calls 2

SetAttributesMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected