birschick-bq commented on code in PR #2729:
URL: https://github.com/apache/arrow-adbc/pull/2729#discussion_r2076244727
##########
go/adbc/driver/internal/driverbase/connection.go:
##########
@@ -714,4 +768,52 @@ func ValueOrZero[T any](val *T) T {
return *val
}
+func maybeAddTraceParent(ctx context.Context, cnxn adbc.OTelTracing, st
adbc.OTelTracing) (context.Context, error) {
+ var traceParentStr string
+ if st != nil && st.GetTraceParent() != "" {
+ traceParentStr = st.GetTraceParent()
+ } else if cnxn != nil && cnxn.GetTraceParent() != "" {
+ traceParentStr = cnxn.GetTraceParent()
+ }
+ if traceParentStr != "" {
+ spanContext, err := propagateTraceParent(ctx, traceParentStr)
+ if err != nil {
+ return ctx, err
+ }
+ ctx = trace.ContextWithRemoteSpanContext(ctx, spanContext)
+ }
+ return ctx, nil
+}
+
+func propagateTraceParent(ctx context.Context, traceParentStr string)
(trace.SpanContext, error) {
+ if strings.TrimSpace(traceParentStr) == "" {
+ return trace.SpanContext{}, fmt.Errorf("traceparent string is
empty")
+ }
+
+ propagator := propagation.TraceContext{}
+ carrier := propagation.MapCarrier{"traceparent": traceParentStr}
+ extractedContext := propagator.Extract(ctx, carrier)
+
+ spanContext := trace.SpanContextFromContext(extractedContext)
+ if !spanContext.IsValid() {
+ return trace.SpanContext{}, fmt.Errorf("invalid traceparent
string")
+ }
+ return spanContext, nil
+}
+
+func isValidateTraceParent(traceParent string) bool {
+ // Supports version-format 00
+ // see:
https://www.w3.org/TR/trace-context/#trace-context-http-headers-format
+ const tpPattern =
`^(?<version>[0]{2})-(?<traceId>[0-9a-f]{32})-(?<parentId>[0-9a-f]{16})-(?<traceFlags>[0-9a-f]{2})$`
+ tpRegExp := regexp.MustCompile(tpPattern)
Review Comment:
Moved to a global variable/constant. Thanks.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]