Skip to content

Commit

Permalink
[4.x] - Remove Microprofile dependencies from SE Telemetry (#6998)
Browse files Browse the repository at this point in the history
* Remove microprofile dependencies

* Tests for SE Agent detection.
  • Loading branch information
dalexandrov committed Jun 20, 2023
1 parent 66f14d7 commit c181cca
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 25 deletions.
16 changes: 16 additions & 0 deletions microprofile/telemetry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@
<artifactId>jakarta.activation-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.tests</groupId>
<artifactId>helidon-microprofile-tests-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.helidon.microprofile.telemetry;/*
* Copyright (c) 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import io.helidon.config.Config;
import io.helidon.microprofile.server.ServerCdiExtension;
import io.helidon.microprofile.tests.junit5.AddConfig;
import io.helidon.microprofile.tests.junit5.AddExtension;
import io.helidon.microprofile.tests.junit5.HelidonTest;
import io.helidon.tracing.opentelemetry.HelidonOpenTelemetry;
import jakarta.enterprise.inject.spi.CDI;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;


/**
* Check Agent Detector working correctly.
*/
@HelidonTest(resetPerTest = true)
@AddExtension(ServerCdiExtension.class)
class AgentDetectorTest {

public static final String OTEL_AGENT_PRESENT = "otel.agent.present";
public static final String IO_OPENTELEMETRY_JAVAAGENT = "io.opentelemetry.javaagent";

@Test
@AddConfig(key = OTEL_AGENT_PRESENT, value = "true")
void shouldBeNoOpTelemetry(){
Config config = CDI.current().select(Config.class).get();
boolean present = HelidonOpenTelemetry.AgentDetector.isAgentPresent(config);
assertThat(present, is(true));
}

@Test
@AddConfig(key = OTEL_AGENT_PRESENT, value = "false")
void shouldNotBeNoOpTelemetry(){
Config config = CDI.current().select(Config.class).get();
boolean present = HelidonOpenTelemetry.AgentDetector.isAgentPresent(config);
assertThat(present, is(false));
}

@Test
void checkEnvVariable(){
System.setProperty(IO_OPENTELEMETRY_JAVAAGENT, "true");
Config config = CDI.current().select(Config.class).get();
boolean present = HelidonOpenTelemetry.AgentDetector.isAgentPresent(config);
assertThat(present, is(true));
}
}
11 changes: 1 addition & 10 deletions tracing/opentelemetry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<scope>provided</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand All @@ -68,15 +69,5 @@
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.tests</groupId>
<artifactId>helidon-microprofile-tests-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.server</groupId>
<artifactId>helidon-microprofile-server</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
public final class HelidonOpenTelemetry {

private static final System.Logger LOGGER = System.getLogger(HelidonOpenTelemetry.class.getName());
static final String OTEL_AGENT_PRESENT_PROPERTY = "otel.agent.present";
static final String IO_OPENTELEMETRY_JAVAAGENT = "io.opentelemetry.javaagent";
private static final String OTEL_AGENT_PRESENT_PROPERTY = "otel.agent.present";
private static final String IO_OPENTELEMETRY_JAVAAGENT = "io.opentelemetry.javaagent";
private HelidonOpenTelemetry() {
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.tracing.opentelemetry;

import java.util.Map;

import io.helidon.config.Config;
import io.helidon.microprofile.server.ServerCdiExtension;
import io.helidon.microprofile.tests.junit5.AddConfig;
import io.helidon.microprofile.tests.junit5.AddExtension;
import io.helidon.microprofile.tests.junit5.HelidonTest;
import jakarta.enterprise.inject.spi.CDI;
import io.helidon.config.ConfigSources;

import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -30,30 +30,29 @@
/**
* Check Agent Detector working correctly.
*/
@HelidonTest(resetPerTest = true)
@AddExtension(ServerCdiExtension.class)
class AgentDetectorTest {

public static final String OTEL_AGENT_PRESENT = "otel.agent.present";
public static final String IO_OPENTELEMETRY_JAVAAGENT = "io.opentelemetry.javaagent";

@Test
@AddConfig(key = HelidonOpenTelemetry.OTEL_AGENT_PRESENT_PROPERTY, value = "true")
void shouldBeNoOpTelemetry(){
Config config = CDI.current().select(Config.class).get();
Config config = Config.create(ConfigSources.create(Map.of(OTEL_AGENT_PRESENT, "true")));
boolean present = HelidonOpenTelemetry.AgentDetector.isAgentPresent(config);
assertThat(present, is(true));
}

@Test
@AddConfig(key = HelidonOpenTelemetry.OTEL_AGENT_PRESENT_PROPERTY, value = "false")
void shouldNotBeNoOpTelemetry(){
Config config = CDI.current().select(Config.class).get();
Config config = Config.create(ConfigSources.create(Map.of(OTEL_AGENT_PRESENT, "false")));
boolean present = HelidonOpenTelemetry.AgentDetector.isAgentPresent(config);
assertThat(present, is(false));
}

@Test
void checkEnvVariable(){
System.setProperty(HelidonOpenTelemetry.IO_OPENTELEMETRY_JAVAAGENT, "true");
Config config = CDI.current().select(Config.class).get();
System.setProperty(IO_OPENTELEMETRY_JAVAAGENT, "true");
Config config = Config.create();
boolean present = HelidonOpenTelemetry.AgentDetector.isAgentPresent(config);
assertThat(present, is(true));
}
Expand Down

0 comments on commit c181cca

Please sign in to comment.