// NewClient creates a new Google Stackdriver Trace client. func NewClient(ctx context.Context, projectID string, opts ...option.ClientOption) (*Client, error) { o := []option.ClientOption{ option.WithScopes(cloudPlatformScope), option.WithUserAgent(userAgent), } o = append(o, opts...) hc, basePath, err := transport.NewHTTPClient(ctx, o...) if err != nil { return nil, fmt.Errorf("creating HTTP client for Google Stackdriver Trace API: %v", err) } apiService, err := api.New(hc) if err != nil { return nil, fmt.Errorf("creating Google Stackdriver Trace API client: %v", err) } if basePath != "" { // An option set a basepath, so override api.New's default. apiService.BasePath = basePath } c := &Client{ service: apiService, projectID: projectID, } bundler := bundler.NewBundler((*api.Trace)(nil), func(bundle interface{}) { traces := bundle.([]*api.Trace) err := c.upload(traces) if err != nil { log.Printf("failed to upload %d traces to the Cloud Trace server.", len(traces)) } }) bundler.DelayThreshold = 2 * time.Second bundler.BundleCountThreshold = 100 // We're not measuring bytes here, we're counting traces and spans as one "byte" each. bundler.BundleByteThreshold = 1000 bundler.BundleByteLimit = 1000 bundler.BufferedByteLimit = 10000 c.bundler = bundler return c, nil }
// NewClient creates a new Google Stackdriver Trace client. func NewClient(ctx context.Context, projectID string, opts ...cloud.ClientOption) (*Client, error) { o := []cloud.ClientOption{ cloud.WithScopes(cloudPlatformScope), cloud.WithUserAgent(userAgent), } o = append(o, opts...) hc, basePath, err := transport.NewHTTPClient(ctx, o...) if err != nil { return nil, fmt.Errorf("creating HTTP client for Google Stackdriver Trace API: %v", err) } apiService, err := api.New(hc) if err != nil { return nil, fmt.Errorf("creating Google Stackdriver Trace API client: %v", err) } if basePath != "" { // An option set a basepath, so override api.New's default. apiService.BasePath = basePath } return &Client{ service: apiService, projectID: projectID, }, nil }