Skip to content

Commit

Permalink
Rename netty always-create-connect-span property to `connection-tel… (
Browse files Browse the repository at this point in the history
open-telemetry#5834)

* Rename netty `always-create-connect-span` property to `connection-telemetry`

* formatting

* warn when deprecated property is used

* errorprone
  • Loading branch information
Mateusz Rzeszutek authored and RashmiRam committed May 23, 2022
1 parent 0483e9e commit 3befd85
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.instrumentation.api.config;

import io.opentelemetry.instrumentation.api.internal.DeprecatedConfigPropertyWarning;

public final class ExperimentalConfig {

private static final ExperimentalConfig instance = new ExperimentalConfig(Config.get());
Expand All @@ -22,6 +24,10 @@ public ExperimentalConfig(Config config) {

public boolean controllerTelemetryEnabled() {
// TODO: remove that `suppress...` flag after 1.13 release
DeprecatedConfigPropertyWarning.warnIfUsed(
config,
"otel.instrumentation.common.experimental.suppress-controller-spans",
"otel.instrumentation.common.experimental.controller-telemetry.enabled");
boolean suppressControllerSpans =
config.getBoolean(
"otel.instrumentation.common.experimental.suppress-controller-spans", false);
Expand All @@ -32,6 +38,10 @@ public boolean controllerTelemetryEnabled() {

public boolean viewTelemetryEnabled() {
// TODO: remove that `suppress...` flag after 1.13 release
DeprecatedConfigPropertyWarning.warnIfUsed(
config,
"otel.instrumentation.common.experimental.suppress-view-spans",
"otel.instrumentation.common.experimental.view-telemetry.enabled");
boolean suppressViewSpans =
config.getBoolean("otel.instrumentation.common.experimental.suppress-view-spans", false);
return config.getBoolean(
Expand All @@ -40,6 +50,10 @@ public boolean viewTelemetryEnabled() {

public boolean messagingReceiveInstrumentationEnabled() {
// TODO: remove that `suppress...` flag after 1.13 release
DeprecatedConfigPropertyWarning.warnIfUsed(
config,
"otel.instrumentation.common.experimental.suppress-messaging-receive-spans",
"otel.instrumentation.messaging.experimental.receive-telemetry.enabled");
boolean receiveSpansSuppressed =
config.getBoolean(
"otel.instrumentation.common.experimental.suppress-messaging-receive-spans", true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.api.internal;

import static java.util.logging.Level.WARNING;

import io.opentelemetry.instrumentation.api.config.Config;
import java.util.logging.Logger;

/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class DeprecatedConfigPropertyWarning {

private static final Logger logger =
Logger.getLogger(DeprecatedConfigPropertyWarning.class.getName());

public static void warnIfUsed(
Config config, String deprecatedPropertyName, String newPropertyName) {
if (config.getString(deprecatedPropertyName) != null) {
logger.log(
WARNING,
"Deprecated property '{0}' was used; use the '{1}' property instead",
new Object[] {deprecatedPropertyName, newPropertyName});
}
}

private DeprecatedConfigPropertyWarning() {}
}
8 changes: 4 additions & 4 deletions instrumentation/netty/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Settings for the Netty instrumentation

| System property | Type | Default | Description |
|---|---|---|---|
| `otel.instrumentation.netty.always-create-connect-span` | Boolean | `false` | Enable the creation of Connect and DNS spans by default for Netty 4.0 and higher instrumentation. |
| `otel.instrumentation.netty.ssl-telemetry.enabled` | Boolean | `false ` | Enable SSL telemetry for Netty 4.0 and higher instrumentation. |
| System property | Type | Default | Description |
|-----------------------------------------------------------|---------|---------|---------------------------------------------------------------------------------------------------|
| `otel.instrumentation.netty.connection-telemetry.enabled` | Boolean | `false` | Enable the creation of Connect and DNS spans by default for Netty 4.0 and higher instrumentation. |
| `otel.instrumentation.netty.ssl-telemetry.enabled` | Boolean | `false` | Enable SSL telemetry for Netty 4.0 and higher instrumentation. |
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
public final class NettyClientInstrumenterFactory {

private final String instrumentationName;
private final boolean alwaysCreateConnectSpan;
private final boolean connectionTelemetryEnabled;
private final boolean sslTelemetryEnabled;

public NettyClientInstrumenterFactory(
String instrumentationName, boolean alwaysCreateConnectSpan, boolean sslTelemetryEnabled) {
String instrumentationName, boolean connectionTelemetryEnabled, boolean sslTelemetryEnabled) {
this.instrumentationName = instrumentationName;
this.alwaysCreateConnectSpan = alwaysCreateConnectSpan;
this.connectionTelemetryEnabled = connectionTelemetryEnabled;
this.sslTelemetryEnabled = sslTelemetryEnabled;
}

Expand Down Expand Up @@ -58,11 +58,11 @@ public NettyConnectionInstrumenter createConnectionInstrumenter() {
.addAttributesExtractor(PeerServiceAttributesExtractor.create(netAttributesGetter))
.setTimeExtractor(new NettyConnectionTimeExtractor())
.newInstrumenter(
alwaysCreateConnectSpan
connectionTelemetryEnabled
? SpanKindExtractor.alwaysInternal()
: SpanKindExtractor.alwaysClient());

return alwaysCreateConnectSpan
return connectionTelemetryEnabled
? new NettyConnectionInstrumenterImpl(instrumenter)
: new NettyErrorOnlyConnectionInstrumenter(instrumenter);
}
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/netty/netty-4.0/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ tasks {
includeTestsMatching("Netty40ClientSslTest")
}
include("**/Netty40ConnectionSpanTest.*", "**/Netty40ClientSslTest.*")
jvmArgs("-Dotel.instrumentation.netty.always-create-connect-span=true")
jvmArgs("-Dotel.instrumentation.netty.connection-telemetry.enabled=true")
jvmArgs("-Dotel.instrumentation.netty.ssl-telemetry.enabled=true")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,31 @@
import io.netty.handler.codec.http.HttpResponse;
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.internal.DeprecatedConfigPropertyWarning;
import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel;
import io.opentelemetry.javaagent.instrumentation.netty.common.client.NettyClientInstrumenterFactory;
import io.opentelemetry.javaagent.instrumentation.netty.common.client.NettyConnectionInstrumenter;
import io.opentelemetry.javaagent.instrumentation.netty.common.client.NettySslInstrumenter;

public final class NettyClientSingletons {

private static final boolean alwaysCreateConnectSpan =
Config.get().getBoolean("otel.instrumentation.netty.always-create-connect-span", false);
private static final boolean sslTelemetryEnabled =
Config.get().getBoolean("otel.instrumentation.netty.ssl-telemetry.enabled", false);
private static final boolean connectionTelemetryEnabled;
private static final boolean sslTelemetryEnabled;

static {
Config config = Config.get();
DeprecatedConfigPropertyWarning.warnIfUsed(
config,
"otel.instrumentation.netty.always-create-connect-span",
"otel.instrumentation.netty.connection-telemetry.enabled");
boolean alwaysCreateConnectSpan =
config.getBoolean("otel.instrumentation.netty.always-create-connect-span", false);
connectionTelemetryEnabled =
config.getBoolean(
"otel.instrumentation.netty.connection-telemetry.enabled", alwaysCreateConnectSpan);
sslTelemetryEnabled =
config.getBoolean("otel.instrumentation.netty.ssl-telemetry.enabled", false);
}

private static final Instrumenter<HttpRequestAndChannel, HttpResponse> INSTRUMENTER;
private static final NettyConnectionInstrumenter CONNECTION_INSTRUMENTER;
Expand All @@ -27,7 +41,7 @@ public final class NettyClientSingletons {
static {
NettyClientInstrumenterFactory factory =
new NettyClientInstrumenterFactory(
"io.opentelemetry.netty-4.0", alwaysCreateConnectSpan, sslTelemetryEnabled);
"io.opentelemetry.netty-4.0", connectionTelemetryEnabled, sslTelemetryEnabled);
INSTRUMENTER = factory.createHttpInstrumenter();
CONNECTION_INSTRUMENTER = factory.createConnectionInstrumenter();
SSL_INSTRUMENTER = factory.createSslInstrumenter();
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/netty/netty-4.1/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ tasks {
includeTestsMatching("Netty41ClientSslTest")
}
include("**/Netty41ConnectionSpanTest.*", "**/Netty41ClientSslTest.*")
jvmArgs("-Dotel.instrumentation.netty.always-create-connect-span=true")
jvmArgs("-Dotel.instrumentation.netty.connection-telemetry.enabled=true")
jvmArgs("-Dotel.instrumentation.netty.ssl-telemetry.enabled=true")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.netty.util.AttributeKey;
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.internal.DeprecatedConfigPropertyWarning;
import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel;
import io.opentelemetry.javaagent.instrumentation.netty.common.client.NettyClientInstrumenterFactory;
import io.opentelemetry.javaagent.instrumentation.netty.common.client.NettyConnectionInstrumenter;
Expand All @@ -21,10 +22,23 @@ public final class NettyClientSingletons {
static final AttributeKey<HttpResponse> HTTP_RESPONSE =
AttributeKey.valueOf(NettyClientSingletons.class, "http-client-response");

private static final boolean alwaysCreateConnectSpan =
Config.get().getBoolean("otel.instrumentation.netty.always-create-connect-span", false);
private static final boolean sslTelemetryEnabled =
Config.get().getBoolean("otel.instrumentation.netty.ssl-telemetry.enabled", false);
private static final boolean connectionTelemetryEnabled;
private static final boolean sslTelemetryEnabled;

static {
Config config = Config.get();
DeprecatedConfigPropertyWarning.warnIfUsed(
config,
"otel.instrumentation.netty.always-create-connect-span",
"otel.instrumentation.netty.connection-telemetry.enabled");
boolean alwaysCreateConnectSpan =
config.getBoolean("otel.instrumentation.netty.always-create-connect-span", false);
connectionTelemetryEnabled =
config.getBoolean(
"otel.instrumentation.netty.connection-telemetry.enabled", alwaysCreateConnectSpan);
sslTelemetryEnabled =
config.getBoolean("otel.instrumentation.netty.ssl-telemetry.enabled", false);
}

private static final Instrumenter<HttpRequestAndChannel, HttpResponse> INSTRUMENTER;
private static final NettyConnectionInstrumenter CONNECTION_INSTRUMENTER;
Expand All @@ -33,7 +47,7 @@ public final class NettyClientSingletons {
static {
NettyClientInstrumenterFactory factory =
new NettyClientInstrumenterFactory(
"io.opentelemetry.netty-4.1", alwaysCreateConnectSpan, sslTelemetryEnabled);
"io.opentelemetry.netty-4.1", connectionTelemetryEnabled, sslTelemetryEnabled);
INSTRUMENTER = factory.createHttpInstrumenter();
CONNECTION_INSTRUMENTER = factory.createConnectionInstrumenter();
SSL_INSTRUMENTER = factory.createSslInstrumenter();
Expand Down
6 changes: 3 additions & 3 deletions instrumentation/reactor/reactor-netty/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Settings for the Reactor Netty instrumentation

| System property | Type | Default | Description |
|---|---|---|---|
| `otel.instrumentation.reactor-netty.always-create-connect-span` | Boolean | `false` | Enable the creation of Connect and DNS spans by default. |
| System property | Type | Default | Description |
|-------------------------------------------------------------------|---------|---------|----------------------------------------------------------|
| `otel.instrumentation.reactor-netty.connection-telemetry.enabled` | Boolean | `false` | Enable the creation of Connect and DNS spans by default. |
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ tasks {
includeTestsMatching("ReactorNettyConnectionSpanTest")
}
include("**/ReactorNettyConnectionSpanTest.*")
jvmArgs("-Dotel.instrumentation.netty.always-create-connect-span=true")
jvmArgs("-Dotel.instrumentation.netty.connection-telemetry.enabled=true")
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ tasks {
}
include("**/ReactorNettyConnectionSpanTest.*", "**/ReactorNettyClientSslTest.*")
jvmArgs("-Dotel.instrumentation.netty.ssl-telemetry.enabled=true")
jvmArgs("-Dotel.instrumentation.reactor-netty.always-create-connect-span=true")
jvmArgs("-Dotel.instrumentation.reactor-netty.connection-telemetry.enabled=true")
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.internal.DeprecatedConfigPropertyWarning;
import io.opentelemetry.javaagent.instrumentation.netty.common.client.NettyClientInstrumenterFactory;
import io.opentelemetry.javaagent.instrumentation.netty.common.client.NettyConnectionInstrumenter;
import reactor.netty.http.client.HttpClientConfig;
Expand All @@ -24,9 +25,21 @@ public final class ReactorNettySingletons {

private static final String INSTRUMENTATION_NAME = "io.opentelemetry.reactor-netty-1.0";

private static final boolean alwaysCreateConnectSpan =
Config.get()
.getBoolean("otel.instrumentation.reactor-netty.always-create-connect-span", false);
private static final boolean connectionTelemetryEnabled;

static {
Config config = Config.get();
DeprecatedConfigPropertyWarning.warnIfUsed(
config,
"otel.instrumentation.reactor-netty.always-create-connect-span",
"otel.instrumentation.reactor-netty.connection-telemetry.enabled");
boolean alwaysCreateConnectSpan =
config.getBoolean("otel.instrumentation.reactor-netty.always-create-connect-span", false);
connectionTelemetryEnabled =
config.getBoolean(
"otel.instrumentation.reactor-netty.connection-telemetry.enabled",
alwaysCreateConnectSpan);
}

private static final Instrumenter<HttpClientConfig, HttpClientResponse> INSTRUMENTER;
private static final NettyConnectionInstrumenter CONNECTION_INSTRUMENTER;
Expand All @@ -51,7 +64,7 @@ public final class ReactorNettySingletons {
.newInstrumenter(SpanKindExtractor.alwaysClient());

NettyClientInstrumenterFactory instrumenterFactory =
new NettyClientInstrumenterFactory(INSTRUMENTATION_NAME, alwaysCreateConnectSpan, false);
new NettyClientInstrumenterFactory(INSTRUMENTATION_NAME, connectionTelemetryEnabled, false);
CONNECTION_INSTRUMENTER = instrumenterFactory.createConnectionInstrumenter();
}

Expand Down

0 comments on commit 3befd85

Please sign in to comment.