Skip to content

Add proxy support with Basic authentication to OTLP exporters - #9064

Draft
cleverchuk wants to merge 2 commits into
open-telemetry:mainfrom
cleverchuk:otlp-exporter-proxy-auth
Draft

cleverchuk wants to merge 2 commits into
open-telemetry:mainfrom
cleverchuk:otlp-exporter-proxy-auth

Conversation

@cleverchuk

Copy link
Copy Markdown
Contributor

Implements open-telemetry/opentelemetry-configuration#807

TL;DR

  • ProxyOptions gains optional Basic credentials and an explicit noProxy().
  • OTLP HTTP exporters (OkHttp and JDK senders) authenticate to the proxy when credentials are set.
  • OTLP gRPC exporters get setProxy(ProxyOptions), including plaintext (http://) endpoints,
    which are tunnelled through the proxy with CONNECT on every supported OkHttp version.
  • Declarative config gets proxy/development (url, username, password) on otlp_http and
    otlp_grpc exporters.
  • Draft: the declarative config part depends on Add experimental proxy configuration to OTLP exporters opentelemetry-configuration#807
    (schema pinned to that commit).

Changes

ProxyOptions

  • create(InetSocketAddress, String username, String password) — HTTP proxy at the address, with
    Basic authentication to the proxy.
  • noProxy() — always connect directly, ignoring ambient JVM proxy configuration
    (http(s).proxyHost, ProxySelector.getDefault()). Differs from leaving proxy options unset,
    which keeps the sender's default behavior.
  • getUsername() / getPassword(); the password is never included in toString().
  • GrpcSenderConfig#getProxyOptions() (default null) so gRPC sender providers receive proxy
    options.

HTTP senders

  • OkHttp: a proxy authenticator answers proxy challenges with Basic credentials, including
    OkHttp's preemptive challenge for CONNECT tunnels. It only answers 407s from the proxy (never
    server challenges) and gives up after one rejection instead of retrying forever.
  • JDK: an Authenticator that supplies credentials for RequestorType.PROXY only. The JDK
    HttpClient disables Basic for CONNECT tunnels by default
    (jdk.http.auth.tunneling.disabledSchemes), so authenticated proxies for https endpoints need
    that property overridden; this is documented in the sender, not worked around.

gRPC exporters

  • setProxy(ProxyOptions) on the OTLP span, metric, log and profiles gRPC exporter builders, wired
    through GrpcSenderConfig to the OkHttp gRPC sender.
  • https endpoints: OkHttp's native CONNECT tunnelling plus the proxy authenticator above.
  • Plaintext http endpoints (h2c prior knowledge): OkHttp 5 tunnels H2_PRIOR_KNOWLEDGE
    through HTTP proxies, but OkHttp 4.x only tunnels TLS and would send HTTP/2 frames straight to
    the proxy. To behave the same on both, when the selector picks an HTTP proxy for an http
    endpoint the sender configures OkHttp with Proxy.NO_PROXY and a socket factory that establishes
    the tunnel itself:
    • connects to the proxy, sends CONNECT host:port (IPv6 literals bracketed) with a preemptive
      Proxy-Authorization header when credentials are set;
    • reads the response head byte by byte, capped at 8 KiB, so no tunnelled bytes are consumed;
      accepts only 2xx, closes the socket on failure;
    • skips local DNS so the proxy resolves the target (the target may only be resolvable from
      the proxy's network); falls back to a direct connection if the selector stops returning an
      HTTP proxy.

Declarative configuration

  • proxy/development on otlp_http and otlp_grpc exporters:
    otlp_grpc:
      endpoint: http://collector:4317
      proxy/development:
        url: http://proxy:3128      # required, must include a host; port defaults to 80
        username: user              # optional, must be set together with password
        password: secret
  • When proxy/development is absent, exporters created from declarative config use
    ProxyOptions.noProxy(), i.e. they no longer pick up ambient JVM proxy settings.
  • The schema is pinned to the opentelemetry-configuration#807 commit and the OTLP exporter models
    are regenerated (ExperimentalProxyModel plus accessors). Revert to a release tag once Array values for span attributes #807 ships.

API compatibility

  • Additive only (see apidiffs): ProxyOptions methods, GrpcSenderConfig#getProxyOptions()
    (default method), and setProxy on the three stable OTLP gRPC exporter builders.
  • Existing HTTP builder methods are unchanged (setProxy on the span builder, setProxyOptions on
    the log and metric builders).

Testing

  • TestHttpProxy: a minimal CONNECT-only test proxy with optional Basic auth that records the
    method, target and Proxy-Authorization of each request; non-CONNECT requests get 405.
  • gRPC exporters: proxy tunnel tests for https and plaintext http endpoints, with and without
    Basic auth, on OkHttp 5 and OkHttp 4.11 (skipped for the ManagedChannel-based senders).
  • HTTP exporters: authenticated CONNECT tunnel to an https endpoint (OkHttp; skipped for the JDK
    sender, see above) and rejection on wrong credentials.
  • Unit tests for the plaintext tunnel socket factory (success, Basic auth, 407, malformed and
    oversized responses, direct fallback) and proxy/development parsing (value retained, no
    "unknown property" warning).
  • Also verified end to end with the Java agent against Squid with Basic auth: plaintext gRPC to a
    local collector and TLS gRPC to a remote collector.

- ProxyOptions: optional Basic credentials (create(address, username,
  password)), noProxy(), credentials redacted from toString().
- OkHttp senders: install a proxy authenticator that answers proxy
  challenges (including OkHttp's preemptive CONNECT challenge) with
  Basic credentials, sent only to the proxy.
- JDK HTTP sender: proxy credentials support.
- gRPC exporters: setProxy(ProxyOptions) on the OTLP span, metric, log
  and profiles gRPC exporter builders, wired through GrpcSenderConfig.
- Plaintext gRPC (http:// endpoints) through an HTTP proxy on all
  supported OkHttp versions: OkHttp 4.x does not CONNECT-tunnel HTTP/2
  prior-knowledge connections, so OkHttpGrpcSender establishes the
  tunnel itself (GrpcH2cConnectTunnelSocketFactory) and lets the proxy
  resolve the target hostname.
- Declarative config: proxy/development (url, username, password) on
  otlp_http and otlp_grpc exporters. Schema pinned to
  open-telemetry/opentelemetry-configuration#807 and the OTLP exporter
  models regenerated (ExperimentalProxyModel and accessors).
- Tests: TestHttpProxy (CONNECT-only proxy with optional Basic auth),
  proxy tunnel tests for gRPC and HTTP exporters on OkHttp 4 and 5,
  GrpcH2cConnectTunnelSocketFactory, ProxyOptions and proxy/development
  parsing.
- Update apidiffs.
Regenerating models from the pinned opentelemetry-configuration commit
also picks up upstream schema changes unrelated to proxy support:
max_export_batch_size on the periodic metric reader graduated from
max_export_batch_size/development to a stable property.

- PeriodicMetricReaderModel: stable maxExportBatchSize property; the
  /development key is still read via the graduation fallback.
- MetricReaderFactory and MetricReaderFactoryTest use the stable
  getter/setter.
- Remove PeriodicMetricReaderModelAccessor, left behind by the
  generator now that the property is stable.
- ExperimentalResourceDetectionModel: detectors Javadoc updated from
  the schema.
@otelbot otelbot Bot added the api-change Changes to public API surface area label Nov 26, 2026
@otelbot

otelbot Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

⚠️ API changes detected — additional maintainer review required

@jack-berg @jkwatson

This PR modifies the public API surface area of the following module(s):

  • opentelemetry-exporter-otlp
  • opentelemetry-sdk-common

Please review the changes in docs/apidiffs/current_vs_latest/ carefully before approving.

@opentelemetry-pr-dashboard

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-11-26 05:36 UTC

Move out of draft to request review.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-change Changes to public API surface area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant