Skip to content

Commit

Permalink
add default service name
Browse files Browse the repository at this point in the history
  • Loading branch information
EddeCCC committed Jul 2, 2024
1 parent 2d4e554 commit b79f885
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ To add the extension to the instrumentation agent:

```bash
java -javaagent:path/to/opentelemetry-javaagent.jar \
-Dotel.javaagent.extensions=build/libs/opentelemetry-javaagent.jar
-Dotel.javaagent.extensions=build/libs/opentelemetry-javaagent.jar \
-Dotel.service.name="my-service"
-jar myapp.jar
```

Expand All @@ -36,6 +37,7 @@ To configure TLS
```bash
java -javaagent:path/to/opentelemetry-javaagent.jar \
-Dotel.javaagent.extensions=build/libs/opentelemetry-javaagent.jar \
-Dotel.service.name="my-service" \
-Djavax.net.ssl.trustStore="path\to\keystore\agent-keystore.jks" \
-Djavax.net.ssl.trustStorePassword="password"
-jar myapp.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.opentelemetry.javaagent.tooling.AgentVersion;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.Objects;

/** Meta-information about the current agent */
public class AgentInfo {
Expand All @@ -30,11 +31,10 @@ public class AgentInfo {
private final long pid;

private AgentInfo() {
InstrumentationConfig config = InstrumentationConfig.get();
this.serviceName = config.getString("otel.service.name");
this.serviceName = getServiceName();
this.gepardVersion = "0.0.1";
this.otelVersion = AgentVersion.VERSION;
this.javaVersion = config.getString("java.version");
this.javaVersion = System.getProperty("java.version");
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
this.startTime = runtime.getStartTime();
this.pid = runtime.getPid();
Expand All @@ -47,4 +47,18 @@ private AgentInfo() {
public static String getAsString() throws JsonProcessingException {
return mapper.writeValueAsString(INFO);
}

/**
* Returns current service name. If no service name was configured, or it's blank, a default
* service name will be returned.
*
* @return Current service name
*/
private String getServiceName() {
InstrumentationConfig config = InstrumentationConfig.get();
String serviceName = config.getString("otel.service.name");
return Objects.isNull(serviceName) || serviceName.isBlank()
? "inspectit-gepard-agent"
: serviceName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public void agentInformationContainsProperties() throws JsonProcessingException
String info = AgentInfo.getAsString();

assertTrue(info.contains("serviceName"));
assertTrue(info.contains("inspectit-gepard-agent"));
assertTrue(info.contains("gepardVersion"));
assertTrue(info.contains("otelVersion"));
assertTrue(info.contains("javaVersion"));
Expand Down

0 comments on commit b79f885

Please sign in to comment.