github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/util/tracing/test_utils.go (about) 1 // Copyright 2018 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package tracing 12 13 import ( 14 "fmt" 15 "strings" 16 ) 17 18 // FindMsgInRecording returns the index of the first span containing msg in its 19 // logs, or -1 if no span is found. 20 func FindMsgInRecording(recording Recording, msg string) int { 21 for i, recSp := range recording { 22 spMsg := "" 23 for _, l := range recSp.Logs { 24 for _, f := range l.Fields { 25 spMsg = spMsg + fmt.Sprintf(" %s: %v", f.Key, f.Value) 26 } 27 } 28 if strings.Contains(spMsg, msg) { 29 return i 30 } 31 } 32 return -1 33 }