Skip to content

[otel] Share OTLP exporter config between metrics surfacer and tracing - #1496

Merged
manugarg merged 2 commits into
mainfrom
otel-shared-exporter-proto
Sep 23, 2026
Merged

manugarg merged 2 commits into
mainfrom
otel-shared-exporter-proto

Conversation

@manugarg

@manugarg manugarg commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

The OTLP exporter messages were defined twice, field for field: once in internal/surfacers/otel/proto and once in internal/tracing/proto (added by #1358). Both defined Compression, HTTPExporter and GRPCExporter identically. This moves them to a shared internal/otel/proto, which both configs now import. SurfacerConf and TracingConfig stay where they are.

Compatibility

Textproto configs are unaffected — textproto doesn't encode nested message type names, only field names. Verified by parsing a config with both an otel_surfacer and a tracing block against the new protos.

Go callers building configs programmatically are unaffected. internal/surfacers/otel/proto keeps compatibility aliases under the old names, so the generated pkg/protos/surfacers facade still exports OtelHTTPExporter, OtelGRPCExporter, OtelCompression and the Compression constants exactly as before. The only facade diff in this PR is PrometheusDefault_SurfacerConf_StaleMetricsExpirationSec, which the regeneration picked up — the checked-in facade was stale.

Keeping OtelCompression needed a genprotofacade fix: under gotypesalias=1 an alias to an enum is a *types.Alias, not a *types.Named, so isEnum() skipped it and the symbol silently dropped out of the facade. Unwrapped with types.Unalias, with a regression test covering a package of aliases.

Go side

The getExporter option plumbing was duplicated too, and the copies had drifted. The signal-specific SDK option types (otlpmetrichttp.Option vs otlptracehttp.Option) can't be shared, but the config interpretation can, so validation and tls.Config construction now live in internal/otel. Each getExporter keeps its own explicit option list. This closes three divergences:

  • The surfacer hand-parsed endpoint_url into host/port/path; it now uses WithEndpointURL, like tracing. WithEndpointURL only logs a parse failure and then falls back to the default endpoint, so the surfacer's invalid-URL startup error is preserved in the shared helper — and tracing gains it.
  • insecure + tls_config together is now rejected by the surfacer, not just by tracing. See the behavior-change note below.
  • Both use tlsconfig.FromProto instead of allocating a tls.Config and calling UpdateTLSConfig on it.

Net: ~560 lines of duplicated generated code removed. Tests added on both sides for the endpoint-URL and insecure/TLS paths.

⚠️ Behavior change worth a release note

Rejecting insecure + tls_config is a startup-breaking change for existing metrics-surfacer configs. Before this PR:

otel_surfacer {
  otlp_grpc_exporter { endpoint: "..." insecure: true tls_config { ... } }
}

started fine — WithInsecure() set Insecure=true and WithTLSCredentials set GRPCCredentials, and oconf.NewGRPCConfig prioritizes credentials over insecure ("passing both is an error", per the SDK's own comment), so TLS silently won. After this PR the same config makes cloudprober fail to boot.

The old behavior was ambiguous and the SDK itself calls it an error, so failing loudly seems right — and it matches what tracing already does since #1358. But it turns a working deployment into a boot failure on upgrade, so it should be called out in the release notes. Happy to make the surfacer lenient instead (warn and let TLS win) if we'd rather not break anyone.

Second commit

c768e2b tightens the endpoint_url validation. url.Parse is scheme-blind, so a schemeless otel.example.com:4318 — the shape otlp_grpc_exporter's endpoint takes, an easy mix-up — parsed as scheme otel.example.com with an empty host and passed the check. WithEndpointURL then derived Endpoint="" and Insecure=true, so the exporter built successfully and every export failed against an empty host. Now an http/https scheme and a non-empty host are required.

The OTLP exporter messages were defined twice, field for field: once in
internal/surfacers/otel/proto and once in internal/tracing/proto (added
by #1358). Move Compression, HTTPExporter and GRPCExporter to a new
shared internal/otel/proto, and have both configs import them.

Existing textproto configs are unaffected: textproto doesn't encode
nested message type names, only field names.

Go callers building configs programmatically are unaffected too.
internal/surfacers/otel/proto keeps compatibility aliases under the old
names, so the generated pkg/protos/surfacers facade still exports
OtelHTTPExporter, OtelGRPCExporter, OtelCompression and the Compression
constants exactly as before.

Keeping OtelCompression needed a genprotofacade fix: under
gotypesalias=1 an alias to an enum is a *types.Alias, not a
*types.Named, so isEnum() skipped it and the symbol silently dropped out
of the facade. Unwrap with types.Unalias.

The getExporter option plumbing was duplicated as well, and the copies
had drifted. The signal-specific SDK option types can't be shared, but
the config interpretation can, so validation and tls.Config construction
now live in internal/otel. That closes three divergences:

  - The surfacer hand-parsed endpoint_url; it now uses WithEndpointURL,
    like tracing. WithEndpointURL only logs a parse failure and falls
    back to the default endpoint, so the surfacer's invalid-URL error is
    preserved in the shared helper -- and tracing gains it.
  - insecure + tls_config is now rejected by the surfacer, not just by
    tracing.
  - Both use tlsconfig.FromProto instead of allocating a tls.Config and
    calling UpdateTLSConfig on it.
The endpoint_url check only looked at url.Parse's error, but url.Parse is
scheme-blind and accepts the most likely misconfiguration: a schemeless
"otel.example.com:4318" -- the shape otlp_grpc_exporter's endpoint takes
-- parses as scheme "otel.example.com" with an empty host.

WithEndpointURL would then derive Endpoint="" and Insecure=true from it,
so the exporter built fine and every export failed against an empty
host. That's the silent misdirection the check was meant to prevent, so
require an http or https scheme and a non-empty host.
@manugarg
manugarg merged commit b053548 into main Sep 23, 2026
12 of 13 checks passed
@manugarg
manugarg deleted the otel-shared-exporter-proto branch September 23, 2026 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant