(t *testing.T)
| 34 | } |
| 35 | |
| 36 | func TestOTelTracing(t *testing.T) { |
| 37 | httpAddress := "127.0.0.1" |
| 38 | |
| 39 | httpMethod := http.MethodGet |
| 40 | |
| 41 | helloRouteName := "hello" |
| 42 | helloRouteTmpl := "/hello" |
| 43 | helloPathParamRouteTmpl := "/hello/{pathParam}" |
| 44 | helloRoutePath := "/hello" |
| 45 | helloPathParamRoutePath := "/hello/world" |
| 46 | |
| 47 | // extracted route names or path templates are converted to a Prometheus-compatible label value |
| 48 | expectedHelloRouteLabel := middleware.MakeLabelValue(helloRouteName) |
| 49 | expectedHelloPathParamRouteLabel := middleware.MakeLabelValue(helloPathParamRouteTmpl) |
| 50 | |
| 51 | // define expected span attributes for the HTTP handler spans, so we can assert that they are the same |
| 52 | // regardless of whether the request is routed through the gRPC Handle method first |
| 53 | expectedOpNameHelloHTTPSpan := "HTTP " + httpMethod + " - " + expectedHelloRouteLabel |
| 54 | expectedAttrsHelloHTTPSpan := []attribute.KeyValue{ |
| 55 | attribute.String("url.path", helloRoutePath), |
| 56 | attribute.String("http.request.method", httpMethod), |
| 57 | attribute.String("http.route", helloRouteName), |
| 58 | } |
| 59 | expectedOpNameHelloPathParamHTTPSpan := "HTTP " + httpMethod + " - " + expectedHelloPathParamRouteLabel |
| 60 | expectedAttrsHelloPathParamHTTPSpan := []attribute.KeyValue{ |
| 61 | attribute.String("url.path", helloPathParamRoutePath), |
| 62 | attribute.String("http.request.method", httpMethod), |
| 63 | attribute.String("http.route", expectedHelloPathParamRouteLabel), |
| 64 | } |
| 65 | |
| 66 | tests := map[string]struct { |
| 67 | useHTTPOverGRPC bool |
| 68 | useOtherGRPC bool |
| 69 | routeName string // leave blank for unnamed route tests |
| 70 | routeTmpl string |
| 71 | reqPath string |
| 72 | reqHeaders map[string]string |
| 73 | expectedAttributesByOpName map[string][]attribute.KeyValue |
| 74 | unexpectedAttributesByOpName map[string][]attribute.Key |
| 75 | |
| 76 | traceHeaders bool |
| 77 | excludedTraceHeaders []string |
| 78 | }{ |
| 79 | "HTTP over gRPC: named route with no params in path template": { |
| 80 | useHTTPOverGRPC: true, |
| 81 | routeName: helloRouteName, |
| 82 | routeTmpl: helloRouteTmpl, |
| 83 | reqPath: helloRoutePath, |
| 84 | expectedAttributesByOpName: map[string][]attribute.KeyValue{ |
| 85 | "httpgrpc.HTTP/Handle": expectedAttrsHelloHTTPSpan, |
| 86 | expectedOpNameHelloHTTPSpan: expectedAttrsHelloHTTPSpan, |
| 87 | }, |
| 88 | }, |
| 89 | "HTTP direct request: named route with no params in path template": { |
| 90 | useHTTPOverGRPC: false, |
| 91 | routeName: helloRouteName, |
| 92 | routeTmpl: helloRouteTmpl, |
| 93 | reqPath: helloRoutePath, |
nothing calls this directly
no test coverage detected