jaegertracing/jaeger · warning

bad request

Error message

bad request

What it means

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.

Source

Thrown at internal/sampling/http/handler.go:20

// Copyright (c) 2017 Uber Technologies, Inc.
// SPDX-License-Identifier: Apache-2.0

package http

import (
	"context"
	"errors"
	"fmt"
	"net/http"

	"github.com/jaegertracing/jaeger-idl/proto-gen/api_v2"
	"github.com/jaegertracing/jaeger/internal/metrics"
	p2json "github.com/jaegertracing/jaeger/internal/uimodel/converter/v1/json"
)

const mimeTypeApplicationJSON = "application/json"

var errBadRequest = errors.New("bad request")

type ClientConfigManager interface {
	GetSamplingStrategy(ctx context.Context, serviceName string) (*api_v2.SamplingStrategyResponse, error)
}

// HandlerParams contains parameters that must be passed to NewHTTPHandler.
type HandlerParams struct {
	ConfigManager  ClientConfigManager // required
	MetricsFactory metrics.Factory     // required
}

// Handler implements endpoints for used by Jaeger clients to retrieve client configuration,
// such as sampling strategies.
type Handler struct {
	params  HandlerParams
	metrics struct {
		// Number of good sampling requests
		SamplingRequestSuccess metrics.Counter `metric:"http-server.requests" tags:"type=sampling"`

View on GitHub (pinned to 806f444784)

Solutions

  1. Include the service name in the request, e.g. GET /api/sampling?service=myservice.
  2. URL-encode the service name properly on the client.
  3. Check client SDK configuration so the remote sampling URL points at the correct endpoint with required parameters.
  4. Return HTTP 400 with the specific wrapped reason so callers can self-correct.

Example fix

// before
GET http://jaeger-agent:5778/sampling
// after
GET http://jaeger-agent:5778/sampling?service=frontend
Defensive patterns

Strategy: validation

Validate before calling

service := r.URL.Query().Get("service")
if service == "" {
    http.Error(w, "missing required 'service' query parameter", http.StatusBadRequest)
    return
}

Try / catch

resp, err := http.Get(baseURL + "/sampling?service=" + url.QueryEscape(svc))
if err != nil || resp.StatusCode == http.StatusBadRequest {
    return nil, fmt.Errorf("sampling request rejected: check service parameter")
}

Prevention

When it happens

Trigger: GET/POST to the sampling endpoint without a valid service name (missing "service" query parameter, empty value, or malformed request) causing serviceFromRequest to fail.

Common situations: 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.

Understand the failure class

Background: BAD_REQUEST error code: request rejected as invalid (HTTP 400) - causes and fixes across libraries — this error's family across 8 libraries.

Related errors


AI-assisted analysis of jaegertracing/jaeger@806f444784 (2026-09-01). Data as JSON: /api/errors/e2e53e5eab73cf33. Report an issue: GitHub.