Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

153 wiersze
5.0 KiB

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