SetAttribute 设置属性到当前 span
(ctx context.Context, key string, value any)
| 156 | |
| 157 | // SetAttribute 设置属性到当前 span |
| 158 | func 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 |
| 177 | func RecordError(ctx context.Context, err error) { |
nothing calls this directly
no test coverage detected