You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

154 lines
5.0 KiB

  1. // Copyright 2018 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. // https://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. // AUTO-GENERATED CODE. DO NOT EDIT.
  15. package trace
  16. import (
  17. "time"
  18. "cloud.google.com/go/internal/version"
  19. gax "github.com/googleapis/gax-go"
  20. "golang.org/x/net/context"
  21. "google.golang.org/api/option"
  22. "google.golang.org/api/transport"
  23. cloudtracepb "google.golang.org/genproto/googleapis/devtools/cloudtrace/v2"
  24. "google.golang.org/grpc"
  25. "google.golang.org/grpc/codes"
  26. "google.golang.org/grpc/metadata"
  27. )
  28. // CallOptions contains the retry settings for each method of Client.
  29. type CallOptions struct {
  30. BatchWriteSpans []gax.CallOption
  31. CreateSpan []gax.CallOption
  32. }
  33. func defaultClientOptions() []option.ClientOption {
  34. return []option.ClientOption{
  35. option.WithEndpoint("cloudtrace.googleapis.com:443"),
  36. option.WithScopes(DefaultAuthScopes()...),
  37. }
  38. }
  39. func defaultCallOptions() *CallOptions {
  40. retry := map[[2]string][]gax.CallOption{
  41. {"default", "idempotent"}: {
  42. gax.WithRetry(func() gax.Retryer {
  43. return gax.OnCodes([]codes.Code{
  44. codes.DeadlineExceeded,
  45. codes.Unavailable,
  46. }, gax.Backoff{
  47. Initial: 100 * time.Millisecond,
  48. Max: 1000 * time.Millisecond,
  49. Multiplier: 1.2,
  50. })
  51. }),
  52. },
  53. }
  54. return &CallOptions{
  55. BatchWriteSpans: retry[[2]string{"default", "non_idempotent"}],
  56. CreateSpan: retry[[2]string{"default", "idempotent"}],
  57. }
  58. }
  59. // Client is a client for interacting with Stackdriver Trace API.
  60. //
  61. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  62. type Client struct {
  63. // The connection to the service.
  64. conn *grpc.ClientConn
  65. // The gRPC API client.
  66. client cloudtracepb.TraceServiceClient
  67. // The call options for this service.
  68. CallOptions *CallOptions
  69. // The x-goog-* metadata to be sent with each request.
  70. xGoogMetadata metadata.MD
  71. }
  72. // NewClient creates a new trace service client.
  73. //
  74. // This file describes an API for collecting and viewing traces and spans
  75. // within a trace. A Trace is a collection of spans corresponding to a single
  76. // operation or set of operations for an application. A span is an individual
  77. // timed event which forms a node of the trace tree. A single trace may
  78. // contain span(s) from multiple services.
  79. func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
  80. conn, err := transport.DialGRPC(ctx, append(defaultClientOptions(), opts...)...)
  81. if err != nil {
  82. return nil, err
  83. }
  84. c := &Client{
  85. conn: conn,
  86. CallOptions: defaultCallOptions(),
  87. client: cloudtracepb.NewTraceServiceClient(conn),
  88. }
  89. c.setGoogleClientInfo()
  90. return c, nil
  91. }
  92. // Connection returns the client's connection to the API service.
  93. func (c *Client) Connection() *grpc.ClientConn {
  94. return c.conn
  95. }
  96. // Close closes the connection to the API service. The user should invoke this when
  97. // the client is no longer required.
  98. func (c *Client) Close() error {
  99. return c.conn.Close()
  100. }
  101. // setGoogleClientInfo sets the name and version of the application in
  102. // the `x-goog-api-client` header passed on each request. Intended for
  103. // use by Google-written clients.
  104. func (c *Client) setGoogleClientInfo(keyval ...string) {
  105. kv := append([]string{"gl-go", version.Go()}, keyval...)
  106. kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", grpc.Version)
  107. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  108. }
  109. // BatchWriteSpans sends new spans to new or existing traces. You cannot update
  110. // existing spans.
  111. func (c *Client) BatchWriteSpans(ctx context.Context, req *cloudtracepb.BatchWriteSpansRequest, opts ...gax.CallOption) error {
  112. ctx = insertMetadata(ctx, c.xGoogMetadata)
  113. opts = append(c.CallOptions.BatchWriteSpans[0:len(c.CallOptions.BatchWriteSpans):len(c.CallOptions.BatchWriteSpans)], opts...)
  114. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  115. var err error
  116. _, err = c.client.BatchWriteSpans(ctx, req, settings.GRPC...)
  117. return err
  118. }, opts...)
  119. return err
  120. }
  121. // CreateSpan creates a new span.
  122. func (c *Client) CreateSpan(ctx context.Context, req *cloudtracepb.Span, opts ...gax.CallOption) (*cloudtracepb.Span, error) {
  123. ctx = insertMetadata(ctx, c.xGoogMetadata)
  124. opts = append(c.CallOptions.CreateSpan[0:len(c.CallOptions.CreateSpan):len(c.CallOptions.CreateSpan)], opts...)
  125. var resp *cloudtracepb.Span
  126. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  127. var err error
  128. resp, err = c.client.CreateSpan(ctx, req, settings.GRPC...)
  129. return err
  130. }, opts...)
  131. if err != nil {
  132. return nil, err
  133. }
  134. return resp, nil
  135. }