Support Otlp Tracing's GRPC port from service connections

Otlp Tracing's exporter is configured using Transport. Current support
for service connections read the mapped port for HTTP transport 4318.
This commits adds support to read port for GRPC transport 4317.

See gh-41333
This commit is contained in:
Eddú Meléndez
2024-07-05 09:43:41 -06:00
committed by Moritz Halbritter
parent f6505f7a18
commit 7baa553760
7 changed files with 51 additions and 10 deletions

View File

@@ -32,6 +32,7 @@ class OpenTelemetryTracingDockerComposeConnectionDetailsFactoryIntegrationTests
@DockerComposeTest(composeFile = "otlp-compose.yaml", image = TestImage.OPENTELEMETRY)
void runCreatesConnectionDetails(OtlpTracingConnectionDetails connectionDetails) {
assertThat(connectionDetails.getGrpcEndpoint()).startsWith("http://").endsWith("/v1/traces");
assertThat(connectionDetails.getUrl()).startsWith("http://").endsWith("/v1/traces");
}

View File

@@ -33,7 +33,9 @@ class OpenTelemetryTracingDockerComposeConnectionDetailsFactory
private static final String[] OPENTELEMETRY_IMAGE_NAMES = { "otel/opentelemetry-collector-contrib",
"grafana/otel-lgtm" };
private static final int OTLP_PORT = 4318;
private static final int OTLP_GRPC_PORT = 4317;
private static final int OTLP_HTTP_PORT = 4318;
OpenTelemetryTracingDockerComposeConnectionDetailsFactory() {
super(OPENTELEMETRY_IMAGE_NAMES,
@@ -50,17 +52,25 @@ class OpenTelemetryTracingDockerComposeConnectionDetailsFactory
private final String host;
private final int port;
private final int grpcPort;
private final int httPort;
private OpenTelemetryTracingDockerComposeConnectionDetails(RunningService source) {
super(source);
this.host = source.host();
this.port = source.ports().get(OTLP_PORT);
this.grpcPort = source.ports().get(OTLP_GRPC_PORT);
this.httPort = source.ports().get(OTLP_HTTP_PORT);
}
@Override
public String getUrl() {
return "http://%s:%d/v1/traces".formatted(this.host, this.port);
return "http://%s:%d/v1/traces".formatted(this.host, this.httPort);
}
@Override
public String getGrpcEndpoint() {
return "http://%s:%d/v1/traces".formatted(this.host, this.grpcPort);
}
}