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

Function TestClient_TraceByID

modules/querier/external/client_test.go:18–83  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestClient_TraceByID(t *testing.T) {
19 traceID := []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10}
20 userID := "test-tenant"
21 expectedPath := "/api/traces/" + hex.EncodeToString(traceID)
22
23 // Create a test trace to return
24 testTrace := &tempopb.Trace{
25 ResourceSpans: []*v1_trace.ResourceSpans{
26 {
27 ScopeSpans: []*v1_trace.ScopeSpans{
28 {
29 Spans: []*v1_trace.Span{
30 {
31 TraceId: traceID,
32 SpanId: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08},
33 Name: "test-span",
34 },
35 },
36 },
37 },
38 },
39 },
40 }
41
42 // Create httptest server that validates the request
43 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
44 // Validate path
45 require.Equal(t, expectedPath, r.URL.Path, "path should match expected trace path")
46
47 // Validate headers
48 require.Equal(t, api.HeaderAcceptProtobuf, r.Header.Get(api.HeaderAccept), "Accept header should be protobuf")
49 require.Equal(t, userID, r.Header.Get(user.OrgIDHeaderName), "X-Scope-OrgID header should match userID")
50
51 // Validate method
52 require.Equal(t, http.MethodGet, r.Method, "method should be GET")
53
54 // Validate query parameters
55 require.Equal(t, "123", r.URL.Query().Get("start"), "start query parameter should be 123")
56 require.Equal(t, "456", r.URL.Query().Get("end"), "end query parameter should be 456")
57
58 // Marshal and return the trace
59 traceBytes, err := testTrace.Marshal()
60 require.NoError(t, err)
61
62 w.Header().Set("Content-Type", api.HeaderAcceptProtobuf)
63 w.WriteHeader(http.StatusOK)
64 _, err = w.Write(traceBytes)
65 require.NoError(t, err)
66 }))
67 defer server.Close()
68
69 // Create client
70 client, err := NewClient(server.URL, 10*time.Second)
71 require.NoError(t, err)
72
73 // Call TraceByID
74 ctx := context.Background()
75 resp, err := client.TraceByID(ctx, userID, traceID, 123, 456)

Callers

nothing calls this directly

Calls 13

MarshalMethod · 0.95
TraceByIDMethod · 0.95
EncodeToStringMethod · 0.80
QueryMethod · 0.80
NewClientFunction · 0.70
GetMethod · 0.65
SetMethod · 0.65
WriteMethod · 0.65
CloseMethod · 0.65
LenMethod · 0.65
EqualMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected