1// Copyright 2021 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
15// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17// Package trace is an auto-generated package for the
18// Stackdriver Trace API.
19//
20// Sends application trace data to Stackdriver Trace for viewing. Trace data
21// is collected for all App Engine applications by default. Trace data from
22// other applications can be provided using this API. This library is used to
23// interact with the Trace API directly. If you are looking to instrument
24// your application for Stackdriver Trace, we recommend using OpenCensus.
25//
26// Use of Context
27//
28// The ctx passed to NewClient is used for authentication requests and
29// for creating the underlying connection, but is not used for subsequent calls.
30// Individual methods on the client use the ctx given to them.
31//
32// To close the open connection, use the Close() method.
33//
34// For information about setting deadlines, reusing contexts, and more
35// please visit pkg.go.dev/cloud.google.com/go.
36package trace // import "cloud.google.com/go/trace/apiv1"
37
38import (
39	"context"
40	"os"
41	"runtime"
42	"strconv"
43	"strings"
44	"unicode"
45
46	"google.golang.org/api/option"
47	"google.golang.org/grpc/metadata"
48)
49
50// For more information on implementing a client constructor hook, see
51// https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors.
52type clientHookParams struct{}
53type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error)
54
55const versionClient = "20210402"
56
57func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context {
58	out, _ := metadata.FromOutgoingContext(ctx)
59	out = out.Copy()
60	for _, md := range mds {
61		for k, v := range md {
62			out[k] = append(out[k], v...)
63		}
64	}
65	return metadata.NewOutgoingContext(ctx, out)
66}
67
68func checkDisableDeadlines() (bool, error) {
69	raw, ok := os.LookupEnv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE")
70	if !ok {
71		return false, nil
72	}
73
74	b, err := strconv.ParseBool(raw)
75	return b, err
76}
77
78// DefaultAuthScopes reports the default set of authentication scopes to use with this package.
79func DefaultAuthScopes() []string {
80	return []string{
81		"https://www.googleapis.com/auth/cloud-platform",
82		"https://www.googleapis.com/auth/trace.append",
83		"https://www.googleapis.com/auth/trace.readonly",
84	}
85}
86
87// versionGo returns the Go runtime version. The returned string
88// has no whitespace, suitable for reporting in header.
89func versionGo() string {
90	const develPrefix = "devel +"
91
92	s := runtime.Version()
93	if strings.HasPrefix(s, develPrefix) {
94		s = s[len(develPrefix):]
95		if p := strings.IndexFunc(s, unicode.IsSpace); p >= 0 {
96			s = s[:p]
97		}
98		return s
99	}
100
101	notSemverRune := func(r rune) bool {
102		return !strings.ContainsRune("0123456789.", r)
103	}
104
105	if strings.HasPrefix(s, "go1") {
106		s = s[2:]
107		var prerelease string
108		if p := strings.IndexFunc(s, notSemverRune); p >= 0 {
109			s, prerelease = s[:p], s[p:]
110		}
111		if strings.HasSuffix(s, ".") {
112			s += "0"
113		} else if strings.Count(s, ".") < 2 {
114			s += ".0"
115		}
116		if prerelease != "" {
117			s += "-" + prerelease
118		}
119		return s
120	}
121	return "UNKNOWN"
122}
123