Skip to content

Commit

Permalink
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java i…
Browse files Browse the repository at this point in the history
…nto grpc-nodeps
  • Loading branch information
Anuraag Agrawal committed Oct 5, 2021
2 parents 22723d5 + 8d7cca7 commit 25a8c5e
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 65 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ contain generated protobuf classes for the Jaeger API. If you were using these i
you must update your build configuration to also include the new `jaeger-proto` artifact. This
artifact will not be included in a future 2.0 release of the SDK so it is recommended to instead
generated the protobuf classes in your own build.
- BREAKING CHANGE: The `opentelemetry-exporter-otlp-http-*` exporter default endpoint ports have
changed from `4317` to `4318`, in line
with [recent changes](https://github.com/open-telemetry/opentelemetry-specification/pull/1970) to
the spec.

### Auto-configuration (alpha)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public final class OtlpHttpLogExporterBuilder {

private static final long DEFAULT_TIMEOUT_SECS = 10;
private static final String DEFAULT_ENDPOINT = "http://localhost:4317/v1/logs";
private static final String DEFAULT_ENDPOINT = "http://localhost:4318/v1/logs";

private long timeoutNanos = TimeUnit.SECONDS.toNanos(DEFAULT_TIMEOUT_SECS);
private String endpoint = DEFAULT_ENDPOINT;
Expand Down Expand Up @@ -76,15 +76,17 @@ public OtlpHttpLogExporterBuilder setEndpoint(String endpoint) {
}

/**
* Sets the method used to compress payloads. If unset, compression is disabled. Currently the
* only supported compression method is "gzip".
* Sets the method used to compress payloads. If unset, compression is disabled. Currently
* supported compression methods include "gzip" and "none".
*/
public OtlpHttpLogExporterBuilder setCompression(String compressionMethod) {
requireNonNull(compressionMethod, "compressionMethod");
checkArgument(
compressionMethod.equals("gzip"),
"Unsupported compression method. Supported compression methods include: gzip.");
this.compressionEnabled = true;
compressionMethod.equals("gzip") || compressionMethod.equals("none"),
"Unsupported compression method. Supported compression methods include: gzip, none.");
if (compressionMethod.equals("gzip")) {
this.compressionEnabled = true;
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.exporter.otlp.http.logs;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.google.protobuf.InvalidProtocolBufferException;
Expand Down Expand Up @@ -37,6 +38,7 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -94,6 +96,43 @@ void setup() {
.addHeader("foo", "bar");
}

@Test
@SuppressWarnings("PreferJavaTimeOverload")
void validConfig() {
assertThatCode(() -> OtlpHttpLogExporter.builder().setTimeout(0, TimeUnit.MILLISECONDS))
.doesNotThrowAnyException();
assertThatCode(() -> OtlpHttpLogExporter.builder().setTimeout(Duration.ofMillis(0)))
.doesNotThrowAnyException();
assertThatCode(() -> OtlpHttpLogExporter.builder().setTimeout(10, TimeUnit.MILLISECONDS))
.doesNotThrowAnyException();
assertThatCode(() -> OtlpHttpLogExporter.builder().setTimeout(Duration.ofMillis(10)))
.doesNotThrowAnyException();

assertThatCode(() -> OtlpHttpLogExporter.builder().setEndpoint("http://localhost:4317"))
.doesNotThrowAnyException();
assertThatCode(() -> OtlpHttpLogExporter.builder().setEndpoint("http://localhost"))
.doesNotThrowAnyException();
assertThatCode(() -> OtlpHttpLogExporter.builder().setEndpoint("https://localhost"))
.doesNotThrowAnyException();
assertThatCode(() -> OtlpHttpLogExporter.builder().setEndpoint("http://foo:bar@localhost"))
.doesNotThrowAnyException();

assertThatCode(() -> OtlpHttpLogExporter.builder().setCompression("gzip"))
.doesNotThrowAnyException();
assertThatCode(() -> OtlpHttpLogExporter.builder().setCompression("none"))
.doesNotThrowAnyException();

assertThatCode(
() -> OtlpHttpLogExporter.builder().addHeader("foo", "bar").addHeader("baz", "qux"))
.doesNotThrowAnyException();

assertThatCode(
() ->
OtlpHttpLogExporter.builder()
.setTrustedCertificates("foobar".getBytes(StandardCharsets.UTF_8)))
.doesNotThrowAnyException();
}

@Test
@SuppressWarnings("PreferJavaTimeOverload")
void invalidConfig() {
Expand Down Expand Up @@ -125,7 +164,8 @@ void invalidConfig() {
.hasMessage("compressionMethod");
assertThatThrownBy(() -> OtlpHttpLogExporter.builder().setCompression("foo"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Unsupported compression method. Supported compression methods include: gzip.");
.hasMessage(
"Unsupported compression method. Supported compression methods include: gzip, none.");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public final class OtlpHttpMetricExporterBuilder {

private static final long DEFAULT_TIMEOUT_SECS = 10;
private static final String DEFAULT_ENDPOINT = "http://localhost:4317/v1/metrics";
private static final String DEFAULT_ENDPOINT = "http://localhost:4318/v1/metrics";

private long timeoutNanos = TimeUnit.SECONDS.toNanos(DEFAULT_TIMEOUT_SECS);
private String endpoint = DEFAULT_ENDPOINT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void validConfig() {
assertThatCode(() -> OtlpHttpMetricExporter.builder().setTimeout(Duration.ofMillis(10)))
.doesNotThrowAnyException();

assertThatCode(() -> OtlpHttpMetricExporter.builder().setEndpoint("http://localhost:4317"))
assertThatCode(() -> OtlpHttpMetricExporter.builder().setEndpoint("http://localhost:4318"))
.doesNotThrowAnyException();
assertThatCode(() -> OtlpHttpMetricExporter.builder().setEndpoint("http://localhost"))
.doesNotThrowAnyException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public final class OtlpHttpSpanExporterBuilder {

private static final long DEFAULT_TIMEOUT_SECS = 10;
private static final String DEFAULT_ENDPOINT = "http://localhost:4317/v1/traces";
private static final String DEFAULT_ENDPOINT = "http://localhost:4318/v1/traces";

private long timeoutNanos = TimeUnit.SECONDS.toNanos(DEFAULT_TIMEOUT_SECS);
private String endpoint = DEFAULT_ENDPOINT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void validConfig() {
assertThatCode(() -> OtlpHttpSpanExporter.builder().setTimeout(Duration.ofMillis(10)))
.doesNotThrowAnyException();

assertThatCode(() -> OtlpHttpSpanExporter.builder().setEndpoint("http://localhost:4317"))
assertThatCode(() -> OtlpHttpSpanExporter.builder().setEndpoint("http://localhost:4318"))
.doesNotThrowAnyException();
assertThatCode(() -> OtlpHttpSpanExporter.builder().setEndpoint("http://localhost"))
.doesNotThrowAnyException();
Expand Down
6 changes: 3 additions & 3 deletions sdk-extensions/autoconfigure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ The [OpenTelemetry Protocol (OTLP)](https://github.com/open-telemetry/openteleme
|------------------------------|-----------------------------|---------------------------------------------------------------------------|
| otel.traces.exporter=otlp (default) | OTEL_TRACES_EXPORTER=otlp | Select the OpenTelemetry exporter for tracing (default) |
| otel.metrics.exporter=otlp | OTEL_METRICS_EXPORTER=otlp | Select the OpenTelemetry exporter for metrics |
| otel.exporter.otlp.endpoint | OTEL_EXPORTER_OTLP_ENDPOINT | The OTLP traces and metrics endpoint to connect to. Must be a URL with a scheme of either `http` or `https` based on the use of TLS. If protocol is `http/protobuf` the version and signal will be appended to the path (e.g. `v1/traces` or `v1/metrics`). Default is `http://localhost:4317` when protocol is `grpc`, and `http://localhost:4317/v1/{signal}` when protocol is `http/protobuf`. |
| otel.exporter.otlp.traces.endpoint | OTEL_EXPORTER_OTLP_TRACES_ENDPOINT | The OTLP traces endpoint to connect to. Must be a URL with a scheme of either `http` or `https` based on the use of TLS. Default is `http://localhost:4317` when protocol is `grpc`, and `http://localhost:4317/v1/traces` when protocol is `http/protobuf`. |
| otel.exporter.otlp.metrics.endpoint | OTEL_EXPORTER_OTLP_METRICS_ENDPOINT | The OTLP metrics endpoint to connect to. Must be a URL with a scheme of either `http` or `https` based on the use of TLS. Default is `http://localhost:4317` when protocol is `grpc`, and `http://localhost:4317/v1/metrics` when protocol is `http/protobuf`. |
| otel.exporter.otlp.endpoint | OTEL_EXPORTER_OTLP_ENDPOINT | The OTLP traces and metrics endpoint to connect to. Must be a URL with a scheme of either `http` or `https` based on the use of TLS. If protocol is `http/protobuf` the version and signal will be appended to the path (e.g. `v1/traces` or `v1/metrics`). Default is `http://localhost:4317` when protocol is `grpc`, and `http://localhost:4318/v1/{signal}` when protocol is `http/protobuf`. |
| otel.exporter.otlp.traces.endpoint | OTEL_EXPORTER_OTLP_TRACES_ENDPOINT | The OTLP traces endpoint to connect to. Must be a URL with a scheme of either `http` or `https` based on the use of TLS. Default is `http://localhost:4317` when protocol is `grpc`, and `http://localhost:4318/v1/traces` when protocol is `http/protobuf`. |
| otel.exporter.otlp.metrics.endpoint | OTEL_EXPORTER_OTLP_METRICS_ENDPOINT | The OTLP metrics endpoint to connect to. Must be a URL with a scheme of either `http` or `https` based on the use of TLS. Default is `http://localhost:4317` when protocol is `grpc`, and `http://localhost:4318/v1/metrics` when protocol is `http/protobuf`. |
| otel.exporter.otlp.certificate | OTEL_EXPORTER_OTLP_CERTIFICATE | The path to the file containing trusted certificates to use when verifying an OTLP trace or metric server's TLS credentials. The file should contain one or more X.509 certificates in PEM format. By default the host platform's trusted root certificates are used. |
| otel.exporter.otlp.traces.certificate | OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE | The path to the file containing trusted certificates to use when verifying an OTLP trace server's TLS credentials. The file should contain one or more X.509 certificates in PEM format. By default the host platform's trusted root certificates are used. |
| otel.exporter.otlp.metrics.certificate | OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE | The path to the file containing trusted certificates to use when verifying an OTLP metric server's TLS credentials. The file should contain one or more X.509 certificates in PEM format. By default the host platform's trusted root certificates are used. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void configureOtlpExporterBuilder_ValidEndpoints() {
configureEndpointCallable(
ImmutableMap.of(
GENERIC_ENDPOINT_KEY,
"http://localhost:4317/path",
"http://localhost:4318/path",
"otel.exporter.otlp.protocol",
"http/protobuf")))
.doesNotThrowAnyException();
Expand Down Expand Up @@ -141,123 +141,123 @@ private static ThrowingCallable configureEndpointCallable(Map<String, String> pr
void configureOtlpExporterBuilder_HttpGenericEndpointKey() {
assertThat(
configureEndpointForHttp(
DATA_TYPE_TRACES, GENERIC_ENDPOINT_KEY, "http://localhost:4317"))
.isEqualTo("http://localhost:4317/v1/traces");
DATA_TYPE_TRACES, GENERIC_ENDPOINT_KEY, "http://localhost:4318"))
.isEqualTo("http://localhost:4318/v1/traces");
assertThat(
configureEndpointForHttp(
DATA_TYPE_TRACES, GENERIC_ENDPOINT_KEY, "http://localhost:4317/"))
.isEqualTo("http://localhost:4317/v1/traces");
DATA_TYPE_TRACES, GENERIC_ENDPOINT_KEY, "http://localhost:4318/"))
.isEqualTo("http://localhost:4318/v1/traces");
assertThat(
configureEndpointForHttp(
DATA_TYPE_TRACES, GENERIC_ENDPOINT_KEY, "http://localhost:4317/foo"))
.isEqualTo("http://localhost:4317/foo/v1/traces");
DATA_TYPE_TRACES, GENERIC_ENDPOINT_KEY, "http://localhost:4318/foo"))
.isEqualTo("http://localhost:4318/foo/v1/traces");
assertThat(
configureEndpointForHttp(
DATA_TYPE_TRACES, GENERIC_ENDPOINT_KEY, "http://localhost:4317/foo/"))
.isEqualTo("http://localhost:4317/foo/v1/traces");
DATA_TYPE_TRACES, GENERIC_ENDPOINT_KEY, "http://localhost:4318/foo/"))
.isEqualTo("http://localhost:4318/foo/v1/traces");
assertThat(
configureEndpointForHttp(
DATA_TYPE_TRACES, GENERIC_ENDPOINT_KEY, "http://localhost:4317/v1/traces"))
.isEqualTo("http://localhost:4317/v1/traces/v1/traces");
DATA_TYPE_TRACES, GENERIC_ENDPOINT_KEY, "http://localhost:4318/v1/traces"))
.isEqualTo("http://localhost:4318/v1/traces/v1/traces");
assertThat(
configureEndpointForHttp(
DATA_TYPE_TRACES, GENERIC_ENDPOINT_KEY, "http://localhost:4317/v1/metrics"))
.isEqualTo("http://localhost:4317/v1/metrics/v1/traces");
DATA_TYPE_TRACES, GENERIC_ENDPOINT_KEY, "http://localhost:4318/v1/metrics"))
.isEqualTo("http://localhost:4318/v1/metrics/v1/traces");

assertThat(
configureEndpointForHttp(
DATA_TYPE_METRICS, GENERIC_ENDPOINT_KEY, "http://localhost:4317"))
.isEqualTo("http://localhost:4317/v1/metrics");
DATA_TYPE_METRICS, GENERIC_ENDPOINT_KEY, "http://localhost:4318"))
.isEqualTo("http://localhost:4318/v1/metrics");
assertThat(
configureEndpointForHttp(
DATA_TYPE_METRICS, GENERIC_ENDPOINT_KEY, "http://localhost:4317/"))
.isEqualTo("http://localhost:4317/v1/metrics");
DATA_TYPE_METRICS, GENERIC_ENDPOINT_KEY, "http://localhost:4318/"))
.isEqualTo("http://localhost:4318/v1/metrics");
assertThat(
configureEndpointForHttp(
DATA_TYPE_METRICS, GENERIC_ENDPOINT_KEY, "http://localhost:4317/foo"))
.isEqualTo("http://localhost:4317/foo/v1/metrics");
DATA_TYPE_METRICS, GENERIC_ENDPOINT_KEY, "http://localhost:4318/foo"))
.isEqualTo("http://localhost:4318/foo/v1/metrics");
assertThat(
configureEndpointForHttp(
DATA_TYPE_METRICS, GENERIC_ENDPOINT_KEY, "http://localhost:4317/foo/"))
.isEqualTo("http://localhost:4317/foo/v1/metrics");
DATA_TYPE_METRICS, GENERIC_ENDPOINT_KEY, "http://localhost:4318/foo/"))
.isEqualTo("http://localhost:4318/foo/v1/metrics");
assertThat(
configureEndpointForHttp(
DATA_TYPE_METRICS, GENERIC_ENDPOINT_KEY, "http://localhost:4317/v1/metrics"))
.isEqualTo("http://localhost:4317/v1/metrics/v1/metrics");
DATA_TYPE_METRICS, GENERIC_ENDPOINT_KEY, "http://localhost:4318/v1/metrics"))
.isEqualTo("http://localhost:4318/v1/metrics/v1/metrics");
assertThat(
configureEndpointForHttp(
DATA_TYPE_METRICS, GENERIC_ENDPOINT_KEY, "http://localhost:4317/v1/traces"))
.isEqualTo("http://localhost:4317/v1/traces/v1/metrics");
DATA_TYPE_METRICS, GENERIC_ENDPOINT_KEY, "http://localhost:4318/v1/traces"))
.isEqualTo("http://localhost:4318/v1/traces/v1/metrics");
}

@Test
void configureOtlpExporterBuilder_HttpTracesEndpointKey() {
assertThat(
configureEndpointForHttp(
DATA_TYPE_TRACES, TRACES_ENDPOINT_KEY, "http://localhost:4317"))
.isEqualTo("http://localhost:4317/");
DATA_TYPE_TRACES, TRACES_ENDPOINT_KEY, "http://localhost:4318"))
.isEqualTo("http://localhost:4318/");
assertThat(
configureEndpointForHttp(
DATA_TYPE_TRACES, TRACES_ENDPOINT_KEY, "http://localhost:4317"))
.isEqualTo("http://localhost:4317/");
DATA_TYPE_TRACES, TRACES_ENDPOINT_KEY, "http://localhost:4318"))
.isEqualTo("http://localhost:4318/");
assertThat(
configureEndpointForHttp(
DATA_TYPE_TRACES, TRACES_ENDPOINT_KEY, "http://localhost:4317/"))
.isEqualTo("http://localhost:4317/");
DATA_TYPE_TRACES, TRACES_ENDPOINT_KEY, "http://localhost:4318/"))
.isEqualTo("http://localhost:4318/");
assertThat(
configureEndpointForHttp(
DATA_TYPE_TRACES, TRACES_ENDPOINT_KEY, "http://localhost:4317/v1/traces"))
.isEqualTo("http://localhost:4317/v1/traces");
DATA_TYPE_TRACES, TRACES_ENDPOINT_KEY, "http://localhost:4318/v1/traces"))
.isEqualTo("http://localhost:4318/v1/traces");
assertThat(
configureEndpointForHttp(
DATA_TYPE_TRACES, TRACES_ENDPOINT_KEY, "http://localhost:4317/foo/bar"))
.isEqualTo("http://localhost:4317/foo/bar");
DATA_TYPE_TRACES, TRACES_ENDPOINT_KEY, "http://localhost:4318/foo/bar"))
.isEqualTo("http://localhost:4318/foo/bar");
assertThat(
configureEndpoint(
DATA_TYPE_TRACES,
ImmutableMap.of(
"otel.exporter.otlp.protocol",
PROTOCOL_HTTP_PROTOBUF,
GENERIC_ENDPOINT_KEY,
"http://localhost:4317/foo/bar",
"http://localhost:4318/foo/bar",
TRACES_ENDPOINT_KEY,
"http://localhost:4317/baz/qux")))
.isEqualTo("http://localhost:4317/baz/qux");
"http://localhost:4318/baz/qux")))
.isEqualTo("http://localhost:4318/baz/qux");
}

@Test
void configureOtlpExporterBuilder_HttpMetricsEndpointKey() {
assertThat(
configureEndpointForHttp(
DATA_TYPE_METRICS, METRICS_ENDPOINT_KEY, "http://localhost:4317"))
.isEqualTo("http://localhost:4317/");
DATA_TYPE_METRICS, METRICS_ENDPOINT_KEY, "http://localhost:4318"))
.isEqualTo("http://localhost:4318/");
assertThat(
configureEndpointForHttp(
DATA_TYPE_METRICS, METRICS_ENDPOINT_KEY, "http://localhost:4317"))
.isEqualTo("http://localhost:4317/");
DATA_TYPE_METRICS, METRICS_ENDPOINT_KEY, "http://localhost:4318"))
.isEqualTo("http://localhost:4318/");
assertThat(
configureEndpointForHttp(
DATA_TYPE_METRICS, METRICS_ENDPOINT_KEY, "http://localhost:4317/"))
.isEqualTo("http://localhost:4317/");
DATA_TYPE_METRICS, METRICS_ENDPOINT_KEY, "http://localhost:4318/"))
.isEqualTo("http://localhost:4318/");
assertThat(
configureEndpointForHttp(
DATA_TYPE_METRICS, METRICS_ENDPOINT_KEY, "http://localhost:4317/v1/traces"))
.isEqualTo("http://localhost:4317/v1/traces");
DATA_TYPE_METRICS, METRICS_ENDPOINT_KEY, "http://localhost:4318/v1/traces"))
.isEqualTo("http://localhost:4318/v1/traces");
assertThat(
configureEndpointForHttp(
DATA_TYPE_METRICS, METRICS_ENDPOINT_KEY, "http://localhost:4317/foo/bar"))
.isEqualTo("http://localhost:4317/foo/bar");
DATA_TYPE_METRICS, METRICS_ENDPOINT_KEY, "http://localhost:4318/foo/bar"))
.isEqualTo("http://localhost:4318/foo/bar");
assertThat(
configureEndpoint(
DATA_TYPE_METRICS,
ImmutableMap.of(
"otel.exporter.otlp.protocol",
PROTOCOL_HTTP_PROTOBUF,
GENERIC_ENDPOINT_KEY,
"http://localhost:4317/foo/bar",
"http://localhost:4318/foo/bar",
METRICS_ENDPOINT_KEY,
"http://localhost:4317/baz/qux")))
.isEqualTo("http://localhost:4317/baz/qux");
"http://localhost:4318/baz/qux")))
.isEqualTo("http://localhost:4318/baz/qux");
}

private static String configureEndpointForHttp(
Expand Down

0 comments on commit 25a8c5e

Please sign in to comment.