25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

57 lines
1.8 KiB

  1. // Copyright 2018, OpenCensus Authors
  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. package ocgrpc
  15. import (
  16. "go.opencensus.io/trace"
  17. "golang.org/x/net/context"
  18. "google.golang.org/grpc/stats"
  19. )
  20. // ClientHandler implements a gRPC stats.Handler for recording OpenCensus stats and
  21. // traces. Use with gRPC clients only.
  22. type ClientHandler struct {
  23. // StartOptions allows configuring the StartOptions used to create new spans.
  24. //
  25. // StartOptions.SpanKind will always be set to trace.SpanKindClient
  26. // for spans started by this handler.
  27. StartOptions trace.StartOptions
  28. }
  29. // HandleConn exists to satisfy gRPC stats.Handler.
  30. func (c *ClientHandler) HandleConn(ctx context.Context, cs stats.ConnStats) {
  31. // no-op
  32. }
  33. // TagConn exists to satisfy gRPC stats.Handler.
  34. func (c *ClientHandler) TagConn(ctx context.Context, cti *stats.ConnTagInfo) context.Context {
  35. // no-op
  36. return ctx
  37. }
  38. // HandleRPC implements per-RPC tracing and stats instrumentation.
  39. func (c *ClientHandler) HandleRPC(ctx context.Context, rs stats.RPCStats) {
  40. traceHandleRPC(ctx, rs)
  41. statsHandleRPC(ctx, rs)
  42. }
  43. // TagRPC implements per-RPC context management.
  44. func (c *ClientHandler) TagRPC(ctx context.Context, rti *stats.RPCTagInfo) context.Context {
  45. ctx = c.traceTagRPC(ctx, rti)
  46. ctx = c.statsTagRPC(ctx, rti)
  47. return ctx
  48. }