Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

60 linhas
1.6 KiB

  1. // Copyright 2017 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // +build go1.8
  15. package spanner
  16. import (
  17. "fmt"
  18. "go.opencensus.io/trace"
  19. "golang.org/x/net/context"
  20. )
  21. func traceStartSpan(ctx context.Context, name string) context.Context {
  22. ctx, _ = trace.StartSpan(ctx, name)
  23. return ctx
  24. }
  25. func traceEndSpan(ctx context.Context, err error) {
  26. span := trace.FromContext(ctx)
  27. if err != nil {
  28. // TODO(jba): Add error code to the status.
  29. span.SetStatus(trace.Status{Message: err.Error()})
  30. }
  31. span.End()
  32. }
  33. func tracePrintf(ctx context.Context, attrMap map[string]interface{}, format string, args ...interface{}) {
  34. var attrs []trace.Attribute
  35. for k, v := range attrMap {
  36. var a trace.Attribute
  37. switch v := v.(type) {
  38. case string:
  39. a = trace.StringAttribute(k, v)
  40. case bool:
  41. a = trace.BoolAttribute(k, v)
  42. case int:
  43. a = trace.Int64Attribute(k, int64(v))
  44. case int64:
  45. a = trace.Int64Attribute(k, v)
  46. default:
  47. a = trace.StringAttribute(k, fmt.Sprintf("%#v", v))
  48. }
  49. attrs = append(attrs, a)
  50. }
  51. trace.FromContext(ctx).Annotatef(attrs, format, args...)
  52. }