{"record":{"id":"e2e53e5eab73cf33","repo":"jaegertracing/jaeger","slug":"bad-request","errorCode":null,"errorMessage":"bad request","messagePattern":"bad request","errorType":"http","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"internal/sampling/http/handler.go","lineNumber":20,"sourceCode":"// Copyright (c) 2017 Uber Technologies, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\npackage http\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"fmt\"\n\t\"net/http\"\n\n\t\"github.com/jaegertracing/jaeger-idl/proto-gen/api_v2\"\n\t\"github.com/jaegertracing/jaeger/internal/metrics\"\n\tp2json \"github.com/jaegertracing/jaeger/internal/uimodel/converter/v1/json\"\n)\n\nconst mimeTypeApplicationJSON = \"application/json\"\n\nvar errBadRequest = errors.New(\"bad request\")\n\ntype ClientConfigManager interface {\n\tGetSamplingStrategy(ctx context.Context, serviceName string) (*api_v2.SamplingStrategyResponse, error)\n}\n\n// HandlerParams contains parameters that must be passed to NewHTTPHandler.\ntype HandlerParams struct {\n\tConfigManager  ClientConfigManager // required\n\tMetricsFactory metrics.Factory     // required\n}\n\n// Handler implements endpoints for used by Jaeger clients to retrieve client configuration,\n// such as sampling strategies.\ntype Handler struct {\n\tparams  HandlerParams\n\tmetrics struct {\n\t\t// Number of good sampling requests\n\t\tSamplingRequestSuccess metrics.Counter `metric:\"http-server.requests\" tags:\"type=sampling\"`","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/jaegertracing/jaeger/blob/806f4447841ecdb60519f408b004a599d515f437/internal/sampling/http/handler.go#L2-L38","documentation":"errBadRequest is the base error returned by serviceFromRequest in the sampling HTTP handler when an incoming HTTP sampling request cannot be converted into a service name lookup — typically a missing or malformed service name parameter. Handlers usually wrap it with more detail and respond with HTTP 400.","triggerScenarios":"GET/POST to the sampling endpoint without a valid service name (missing \"service\" query parameter, empty value, or malformed request) causing serviceFromRequest to fail.","commonSituations":"Clients (tracers, SDKs) calling /api/sampling without the service query parameter; URL-encoding problems dropping the parameter; probes/health-checkers hitting the sampling endpoint without parameters.","solutions":["Include the service name in the request, e.g. GET /api/sampling?service=myservice.","URL-encode the service name properly on the client.","Check client SDK configuration so the remote sampling URL points at the correct endpoint with required parameters.","Return HTTP 400 with the specific wrapped reason so callers can self-correct."],"exampleFix":"// before\nGET http://jaeger-agent:5778/sampling\n// after\nGET http://jaeger-agent:5778/sampling?service=frontend","handlingStrategy":"validation","validationCode":"service := r.URL.Query().Get(\"service\")\nif service == \"\" {\n    http.Error(w, \"missing required 'service' query parameter\", http.StatusBadRequest)\n    return\n}","typeGuard":null,"tryCatchPattern":"resp, err := http.Get(baseURL + \"/sampling?service=\" + url.QueryEscape(svc))\nif err != nil || resp.StatusCode == http.StatusBadRequest {\n    return nil, fmt.Errorf(\"sampling request rejected: check service parameter\")\n}","preventionTips":["Always send the service query parameter to the sampling endpoint.","URL-encode service names.","Configure SDK remote sampling URLs via the standard client config, not hand-built URLs."],"tags":["http","sampling","bad-request"],"backgroundTag":"bad-request","analyzedSha":"806f4447841ecdb60519f408b004a599d515f437","analyzedAt":"2026-09-01T02:39:22.140Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}