Skip to content

Commit

Permalink
Merge pull request #246 from solarwinds/cc/NH-86983
Browse files Browse the repository at this point in the history
NH-86983: make otel log export opt-in only
  • Loading branch information
cleverchuk authored Jul 24, 2024
2 parents 7f7e9a3 + f3c2a67 commit 27d2df3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ private static void maybeFollowOtelConfigProperties(ConfigContainer configs) {

static void configOtelLogExport(ConfigContainer container) {
Boolean exportLog = (Boolean) container.get(ConfigProperty.AGENT_EXPORT_LOGS_ENABLED);
String collectorEndpoint = (String) container.get(ConfigProperty.AGENT_COLLECTOR);

if (exportLog == null || exportLog) {
if (exportLog != null && exportLog) {
String serviceKey = (String) container.get(ConfigProperty.AGENT_SERVICE_KEY);
String apiKey = ServiceKeyUtils.getApiKey(serviceKey);

String dataCell = "na-01";
String env = "cloud";
String collectorEndpoint = (String) container.get(ConfigProperty.AGENT_COLLECTOR);

if (collectorEndpoint != null) {
String[] fragments = collectorEndpoint.split("\\.");
if (fragments.length > 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,9 @@ void verifySettingOtelLogExportSystemVariablesWhenEnabled() throws InvalidConfig
@ClearSystemProperty(key = "otel.exporter.otlp.protocol")
@ClearSystemProperty(key = "otel.exporter.otlp.logs.headers")
@ClearSystemProperty(key = "otel.exporter.otlp.logs.endpoint")
void verifyOtelLogExportSystemVariablesAreNotSetWhenDisabled() throws InvalidConfigException {
void verifyOtelLogExportSystemVariablesAreNotSetWhenNotEnabled() throws InvalidConfigException {
ConfigContainer configContainer = new ConfigContainer();
configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service");
configContainer.putByStringValue(ConfigProperty.AGENT_EXPORT_LOGS_ENABLED, "false");
configContainer.putByStringValue(
ConfigProperty.AGENT_COLLECTOR, "apm.collector.na-02.cloud.solarwinds.com");

Expand All @@ -208,6 +207,7 @@ void verifyOtelLogExportEndpointIsProperlyFormed() throws InvalidConfigException
configContainer.putByStringValue(
ConfigProperty.AGENT_COLLECTOR, "apm.collector.na-02.staging.solarwinds.com");

configContainer.putByStringValue(ConfigProperty.AGENT_EXPORT_LOGS_ENABLED, "true");
ConfigurationLoader.configOtelLogExport(configContainer);

assertEquals(
Expand All @@ -223,6 +223,8 @@ void verifyOtelLogExportEndpointIsProperlyFormed() throws InvalidConfigException
void verifyDefaultEndpointIsUsed() throws InvalidConfigException {
ConfigContainer configContainer = new ConfigContainer();
configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service");

configContainer.putByStringValue(ConfigProperty.AGENT_EXPORT_LOGS_ENABLED, "true");
ConfigurationLoader.configOtelLogExport(configContainer);

assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public GenericContainer<?> build() {
String.format("authorization=Bearer %s", System.getenv("SW_APM_SERVICE_KEY")))
.withEnv("OTEL_SERVICE_NAME", "lambda-e2e")
.withEnv("SW_APM_TRANSACTION_NAME", "lambda-test-txn")
.withEnv("SW_APM_EXPORT_LOGS_ENABLED", "true")
.withStartupTimeout(Duration.ofMinutes(5))
.withCopyFileToContainer(
MountableFile.forHostPath(agentPath),
Expand Down Expand Up @@ -115,6 +116,7 @@ public GenericContainer<?> build() {
.withEnv("SW_APM_SQL_TAG", "true")
.withEnv("SW_APM_SQL_TAG_DATABASES", "postgresql")
.withEnv("SW_APM_SQL_TAG_PREPARED", "true")
.withEnv("SW_APM_EXPORT_LOGS_ENABLED", "true")
.withEnv("SW_APM_COLLECTOR", System.getenv("SW_APM_COLLECTOR"))
.withEnv("SW_APM_SERVICE_KEY", String.format("%s:java-apm-smoke-test", System.getenv("SW_APM_SERVICE_KEY")))
.withStartupTimeout(Duration.ofMinutes(5))
Expand Down

0 comments on commit 27d2df3

Please sign in to comment.