Skip to content

Commit 5e4544d

Browse files
authored
Add resource attributes (#298)
1 parent ae8cc69 commit 5e4544d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/HypertraceResourceProvider.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@
2525
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
2626
import org.hypertrace.agent.config.Config.AgentConfig;
2727
import org.hypertrace.agent.core.config.HypertraceConfig;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
2830

2931
@AutoService(ResourceProvider.class)
3032
public class HypertraceResourceProvider implements ResourceProvider {
3133

34+
private static final Logger log =
35+
LoggerFactory.getLogger(HypertraceResourceProvider.class.getName());
36+
3237
private final CgroupsReader cgroupsReader = new CgroupsReader();
3338
private final AgentConfig agentConfig = HypertraceConfig.get();
3439

@@ -40,6 +45,23 @@ public Resource createResource(ConfigProperties config) {
4045
builder.put(ResourceAttributes.CONTAINER_ID, containerId);
4146
}
4247
builder.put(ResourceAttributes.SERVICE_NAME, agentConfig.getServiceName().getValue());
48+
builder.put(ResourceAttributes.TELEMETRY_SDK_NAME, "hypertrace");
49+
builder.put(ResourceAttributes.TELEMETRY_SDK_LANGUAGE, "java");
50+
String agentVersion = getAgentVersion();
51+
builder.put(ResourceAttributes.TELEMETRY_SDK_VERSION, agentVersion);
52+
builder.put(ResourceAttributes.TELEMETRY_AUTO_VERSION, agentVersion);
4353
return Resource.create(builder.build());
4454
}
55+
56+
private String getAgentVersion() {
57+
String agentVersion = "";
58+
try {
59+
Class<?> hypertraceAgentClass =
60+
Class.forName("org.hypertrace.agent.instrument.HypertraceAgent", true, null);
61+
agentVersion = hypertraceAgentClass.getPackage().getImplementationVersion();
62+
} catch (ClassNotFoundException e) {
63+
log.warn("Could not load HypertraceAgent class");
64+
}
65+
return agentVersion;
66+
}
4567
}

0 commit comments

Comments
 (0)