MCPcopy
hub / github.com/grafana/tempo / getForWithContext

Method getForWithContext

pkg/httpclient/client.go:114–146  ·  view source on GitHub ↗
(ctx context.Context, url string, m proto.Message)

Source from the content-addressed store, hash-verified

112}
113
114func (c *Client) getForWithContext(ctx context.Context, url string, m proto.Message) (*http.Response, error) {
115 req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
116 if err != nil {
117 return nil, err
118 }
119
120 marshallingFormat := applicationJSON
121 if strings.Contains(url, QueryTraceEndpoint) || strings.Contains(url, QueryTraceV2Endpoint) {
122 marshallingFormat = applicationProtobuf
123 }
124 // Set 'Accept' header to 'application/protobuf'.
125 // This is required for the /api/traces and /api/v2/traces endpoint to return a protobuf response.
126 // JSON lost backwards compatibility with the upgrade to `opentelemetry-proto` v0.18.0.
127 req.Header.Set(acceptHeader, marshallingFormat)
128
129 resp, body, err := c.doRequest(req)
130 if err != nil {
131 return nil, err
132 }
133
134 switch marshallingFormat {
135 case applicationJSON:
136 if err = jsonpb.UnmarshalString(string(body), m); err != nil {
137 return resp, fmt.Errorf("error decoding %T json, err: %v body: %s", m, err, string(body))
138 }
139 default:
140 if err = proto.Unmarshal(body, m); err != nil {
141 return resp, fmt.Errorf("error decoding %T proto, err: %w body: %s", m, err, string(body))
142 }
143 }
144
145 return resp, nil
146}
147
148// doRequest sends the given request, it injects X-Scope-OrgID and handles bad status codes.
149func (c *Client) doRequest(req *http.Request) (*http.Response, []byte, error) {

Callers 3

getForMethod · 0.95
SearchWithRangeMethod · 0.95
QueryTraceWithRangeMethod · 0.95

Calls 3

doRequestMethod · 0.95
SetMethod · 0.65
UnmarshalMethod · 0.65

Tested by

no test coverage detected