MCPcopy Create free account
hub / github.com/cli/cli / NewTelemetryAPIProtobufClient

Function NewTelemetryAPIProtobufClient

internal/barista/observability/telemetry.twirp.go:54–85  ·  view source on GitHub ↗

NewTelemetryAPIProtobufClient creates a Protobuf client that implements the TelemetryAPI interface. It communicates using Protobuf and can be configured with a custom HTTPClient.

(baseURL string, client HTTPClient, opts ...twirp.ClientOption)

Source from the content-addressed store, hash-verified

52// NewTelemetryAPIProtobufClient creates a Protobuf client that implements the TelemetryAPI interface.
53// It communicates using Protobuf and can be configured with a custom HTTPClient.
54func NewTelemetryAPIProtobufClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) TelemetryAPI {
55 if c, ok := client.(*http.Client); ok {
56 client = withoutRedirects(c)
57 }
58
59 clientOpts := twirp.ClientOptions{}
60 for _, o := range opts {
61 o(&clientOpts)
62 }
63
64 // Using ReadOpt allows backwards and forwards compatibility with new options in the future
65 literalURLs := false
66 _ = clientOpts.ReadOpt("literalURLs", &literalURLs)
67 var pathPrefix string
68 if ok := clientOpts.ReadOpt("pathPrefix", &pathPrefix); !ok {
69 pathPrefix = "/twirp" // default prefix
70 }
71
72 // Build method URLs: <baseURL>[<prefix>]/<package>.<Service>/<Method>
73 serviceURL := sanitizeBaseURL(baseURL)
74 serviceURL += baseServicePath(pathPrefix, "clientappsfe.observability.v1", "TelemetryAPI")
75 urls := [1]string{
76 serviceURL + "RecordEvents",
77 }
78
79 return &telemetryAPIProtobufClient{
80 client: client,
81 urls: urls,
82 interceptor: twirp.ChainInterceptors(clientOpts.Interceptors...),
83 opts: clientOpts,
84 }
85}
86
87func (c *telemetryAPIProtobufClient) RecordEvents(ctx context.Context, in *RecordEventsRequest) (*RecordEventsResponse, error) {
88 ctx = ctxsetters.WithPackageName(ctx, "clientappsfe.observability.v1")

Callers 1

runSendTelemetryFunction · 0.92

Calls 3

withoutRedirectsFunction · 0.85
sanitizeBaseURLFunction · 0.85
baseServicePathFunction · 0.85

Tested by

no test coverage detected