lidavidm commented on code in PR #2825: URL: https://github.com/apache/arrow-adbc/pull/2825#discussion_r2113032371
########## go/adbc/utils/utils.go: ########## @@ -73,3 +81,50 @@ func removeFieldMetadata(field *arrow.Field) arrow.Field { Metadata: arrow.Metadata{}, } } + +func SetErrorOnSpan(span trace.Span, err error) bool { + if err != nil { + span.RecordError(err) + if adbcError, ok := err.(adbc.Error); ok { + span.SetAttributes(attribute.String(TraceAttributeErrorType, adbcError.Code.String())) + } + span.SetStatus(codes.Error, err.Error()) + return true + } + return false +} + +func TraceSpan( + ctx context.Context, + tracing adbc.OTelTracing, + spanName string, + execFunc func(ctx context.Context, span trace.Span) error, + opts ...trace.SpanStartOption, +) error { Review Comment: I guess there's no better way to do this in Go but it's a bit unfortunate that all our code has to creep towards the right ########## go/adbc/utils/utils.go: ########## @@ -73,3 +81,50 @@ func removeFieldMetadata(field *arrow.Field) arrow.Field { Metadata: arrow.Metadata{}, } } + +func SetErrorOnSpan(span trace.Span, err error) bool { + if err != nil { + span.RecordError(err) + if adbcError, ok := err.(adbc.Error); ok { + span.SetAttributes(attribute.String(TraceAttributeErrorType, adbcError.Code.String())) + } + span.SetStatus(codes.Error, err.Error()) + return true + } + return false +} + +func TraceSpan( + ctx context.Context, + tracing adbc.OTelTracing, + spanName string, + execFunc func(ctx context.Context, span trace.Span) error, + opts ...trace.SpanStartOption, +) error { + var span trace.Span + attrs := tracing.GetInitialSpanAttributes() + *attrs = append(*attrs, attribute.String(TraceAttributeDbOperationName, spanName)) + ctx, span = tracing.StartSpan(ctx, spanName, trace.WithAttributes(*attrs...)) + err := execFunc(ctx, span) + defer func() { + if !SetErrorOnSpan(span, err) { + span.SetStatus(codes.Ok, codes.Ok.String()) + } + span.End() + }() + return err +} + +const ( + TraceAttributeDbDriverOptionGet = "db.driver.option.get" + TraceAttributeDbSystemName = "db.system.name" + TraceAttributeDbNamespace = "db.namespace" + TraceAttributeDbCollectionName = "db.collection.name" + TraceAttributeDbOperationBatchSize = "db.operation.batch.size" + TraceAttributeDbOperationName = "db.operation.name" + TraceAttributeDbResponseStatusCode = "db.response.status_code" + TraceAttributeDbResponseRetRows = "db.response.returned_rows" + TraceAttributeErrorType = "error.type" + TraceAttributeServerPort = "server.port" + TraceAttributeServerAddress = "server.address" +) Review Comment: Does upstream not define these? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org