Skip to content

Commit 9dc43a9

Browse files
committed
map agent props
1 parent bb5f7dc commit 9dc43a9

File tree

3 files changed

+70
-10
lines changed

3 files changed

+70
-10
lines changed

javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/extension/DeclarativeConfigPropertiesBridge.java

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static io.opentelemetry.api.incubator.config.DeclarativeConfigProperties.empty;
99

1010
import io.opentelemetry.api.incubator.config.ConfigProvider;
11+
import io.opentelemetry.api.incubator.config.DeclarativeConfigException;
1112
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
1213
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
1314
import java.time.Duration;
@@ -64,13 +65,23 @@ public final class DeclarativeConfigPropertiesBridge implements ConfigProperties
6465

6566
static {
6667
JAVA_MAPPING_RULES.put("otel.instrumentation.common.default-enabled", "common.default.enabled");
68+
JAVA_MAPPING_RULES.put("otel.javaagent.logging.application.logs-buffer-max-records", "agent.logging.output.application.logs_buffer_max_records");
6769

6870
// not supported in SDK yet (this is strictly typed)
69-
// GENERAL_MAPPING_RULES.put("otel.instrumentation.http.known-methods", "http.known_methods");
70-
GENERAL_MAPPING_RULES.put("otel.instrumentation.http.client.capture-request-headers", "http.client.request_captured_headers");
71-
GENERAL_MAPPING_RULES.put("otel.instrumentation.http.client.capture-response-headers", "http.client.response_captured_headers");
72-
GENERAL_MAPPING_RULES.put("otel.instrumentation.http.server.capture-request-headers", "http.server.request_captured_headers");
73-
GENERAL_MAPPING_RULES.put("otel.instrumentation.http.server.capture-response-headers", "http.server.response_captured_headers");
71+
// GENERAL_MAPPING_RULES.put("otel.instrumentation.http.known-methods",
72+
// "http.known_methods");
73+
GENERAL_MAPPING_RULES.put(
74+
"otel.instrumentation.http.client.capture-request-headers",
75+
"http.client.request_captured_headers");
76+
GENERAL_MAPPING_RULES.put(
77+
"otel.instrumentation.http.client.capture-response-headers",
78+
"http.client.response_captured_headers");
79+
GENERAL_MAPPING_RULES.put(
80+
"otel.instrumentation.http.server.capture-request-headers",
81+
"http.server.request_captured_headers");
82+
GENERAL_MAPPING_RULES.put(
83+
"otel.instrumentation.http.server.capture-response-headers",
84+
"http.server.response_captured_headers");
7485
}
7586

7687
private static Map<String, String> getPeerServiceMapping(
@@ -99,6 +110,10 @@ public DeclarativeConfigPropertiesBridge(ConfigProvider configProvider) {
99110
@Nullable
100111
@Override
101112
public String getString(String propertyName) {
113+
if ("otel.javaagent.logging".equals(propertyName)) {
114+
return agentLoggerName();
115+
}
116+
102117
return getPropertyValue(propertyName, DeclarativeConfigProperties::getString);
103118
}
104119

@@ -215,4 +230,28 @@ private static String getJavaPath(String property) {
215230
}
216231
return null;
217232
}
233+
234+
private String agentLoggerName() {
235+
DeclarativeConfigProperties logOutput = getLogOutput();
236+
DeclarativeConfigProperties application = logOutput.getStructured("application");
237+
DeclarativeConfigProperties simple = logOutput.getStructured("simple");
238+
if (application != null) {
239+
if (simple != null) {
240+
throw new DeclarativeConfigException(
241+
"Both 'application' and 'simple' log output are configured. "
242+
+ "Please choose one of them.");
243+
}
244+
return "application";
245+
}
246+
// simple is the default
247+
return "simple";
248+
}
249+
250+
private DeclarativeConfigProperties getLogOutput() {
251+
return getAgent().getStructured("logging", empty()).getStructured("output", empty());
252+
}
253+
254+
private DeclarativeConfigProperties getAgent() {
255+
return instrumentationJavaNode.getStructured("agent", empty());
256+
}
218257
}

javaagent-extension-api/src/test/java/io/opentelemetry/javaagent/extension/DeclarativeConfigPropertiesBridgeTest.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Map;
2020
import java.util.Objects;
2121
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.DisplayName;
2223
import org.junit.jupiter.api.Test;
2324

2425
class DeclarativeConfigPropertiesBridgeTest {
@@ -107,15 +108,18 @@ void getProperties() {
107108
.isEqualTo(Arrays.asList("value1", "value2"));
108109
assertThat(bridge.getMap("otel.instrumentation.other-instrumentation.map_key", expectedMap))
109110
.isEqualTo(expectedMap);
111+
}
110112

111-
// specific property mappings
112-
assertThat(bridge.getBoolean("otel.javaagent.experimental.indy")).isTrue();
113-
assertThat(bridge.getBoolean("otel.instrumentation.common.default-enabled")).isFalse();
113+
// tests for specific properties
114+
115+
@DisplayName("properties from the general instrumentation section in config.yaml")
116+
@Test
117+
void general() {
114118
assertThat(bridge.getMap("otel.instrumentation.common.peer-service-mapping"))
115119
.containsOnly(entry("1.2.3.4", "FooService"), entry("2.3.4.5", "BarService"));
116120
// not supported in SDK yet (this is strictly typed)
117-
// assertThat(bridge.getList("otel.instrumentation.http.known-methods"))
118-
// .containsExactly("GET", "POST", "PUT");
121+
// assertThat(bridge.getList("otel.instrumentation.http.known-methods"))
122+
// .containsExactly("GET", "POST", "PUT");
119123
assertThat(bridge.getList("otel.instrumentation.http.client.capture-request-headers"))
120124
.containsExactly("Content-Type", "Accept");
121125
assertThat(bridge.getList("otel.instrumentation.http.client.capture-response-headers"))
@@ -125,4 +129,17 @@ void getProperties() {
125129
assertThat(bridge.getList("otel.instrumentation.http.server.capture-response-headers"))
126130
.containsExactly("Content-Type", "Content-Encoding");
127131
}
132+
133+
@Test
134+
void common() {
135+
assertThat(bridge.getBoolean("otel.instrumentation.common.default-enabled")).isFalse();
136+
}
137+
138+
@Test
139+
void agent() {
140+
assertThat(bridge.getBoolean("otel.javaagent.experimental.indy")).isTrue();
141+
assertThat(bridge.getString("otel.javaagent.logging")).isEqualTo("application");
142+
assertThat(bridge.getInt("otel.javaagent.logging.application.logs-buffer-max-records"))
143+
.isEqualTo(1000);
144+
}
128145
}

javaagent-extension-api/src/test/resources/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ instrumentation/development:
3131
agent:
3232
experimental:
3333
indy: true
34+
logging:
35+
output:
36+
application:
37+
logs_buffer_max_records: 1000
3438
common:
3539
default:
3640
enabled: false

0 commit comments

Comments
 (0)