Repository navigation
fix(auditlog_ng): infer OTLP protocol from endpoint when env unset - #411
Open
jeanscherf wants to merge 1 commit into
Open
jeanscherf wants to merge 1 commit into
jeanscherf wants to merge 1 commit into
Conversation
The audit client chose its OTLP protocol from OTEL_EXPORTER_OTLP_PROTOCOL, defaulting to gRPC when it was unset. The platform instrumentation never injects that variable, so an HTTP audit destination (http://host:4318/v1/logs) was always dialed with a gRPC exporter, breaking delivery. Derive the protocol from the resolved endpoint shape instead: an http(s) URL with a path -> http/protobuf, a bare host:port -> grpc. An explicit OTEL_EXPORTER_OTLP_PROTOCOL still wins when set, and gRPC remains the fallback when both the env and the endpoint shape are inconclusive. Add unit tests covering every branch of the shape inference and the resolver.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The Audit Log NG client picked its OTLP transport from
OTEL_EXPORTER_OTLP_PROTOCOL, defaulting to gRPC when that variable was unset (_create_log_exporterinsrc/sap_cloud_sdk/core/auditlog_ng/client.py). In common deployments that variable is never injected, so an HTTP audit endpoint (for examplehttp://host:4318/v1/logs) was always dialed with a gRPC exporter and delivery failed.This derives the protocol from the resolved
config.endpointinstead. New helper_infer_protocol_from_endpointreads the endpoint shape (an http(s) URL with a path meanshttp/protobuf; a barehost:portmeansgrpc), and_resolve_protocolapplies it: an explicitOTEL_EXPORTER_OTLP_PROTOCOLstill wins when set, inference is used when it is unset, and gRPC remains the fallback when both the env and the shape are inconclusive.Related Issue
N/A — no public issue reference.
Type of Change
How to Test
OTEL_EXPORTER_OTLP_PROTOCOL, buildAuditClientwithendpoint="http://host:4318/v1/logs", and confirm anHTTPLogExporteris constructed (previously aGRPCLogExporterwas used).endpoint="audit.example.com:443"; confirm aGRPCLogExporteris constructed.OTEL_EXPORTER_OTLP_PROTOCOL=grpcwith an HTTP endpoint and confirm gRPC is used (explicit override wins).uv run pytest tests/core/unit/auditlog_ng/unit/test_client.py -k "Protocol or Infer or Resolve".Checklist
Additional Notes
Design note: an endpoint with no path resolves to gRPC even when it carries an
http/httpsscheme, because a path is the only positive HTTP signal and OTLP/gRPC endpoints legitimately use an http(s) scheme to indicate (in)secure transport. The rare "HTTP base endpoint without/v1/logs" case is covered by settingOTEL_EXPORTER_OTLP_PROTOCOLexplicitly. This behavior is pinned by a test.Unit tests cover every branch of both helpers (http/grpc, with and without port, scheme vs no scheme, no host, empty/None, and the env precedence/fallback paths).
ruff formatalso normalized a few pre-existing long lines intests/core/unit/auditlog_ng/unit/test_client.py(imports, a helper signature, one assertion) that were touched by the required pre-commit hook.