25
25
import io .opentelemetry .semconv .resource .attributes .ResourceAttributes ;
26
26
import org .hypertrace .agent .config .Config .AgentConfig ;
27
27
import org .hypertrace .agent .core .config .HypertraceConfig ;
28
+ import org .slf4j .Logger ;
29
+ import org .slf4j .LoggerFactory ;
28
30
29
31
@ AutoService (ResourceProvider .class )
30
32
public class HypertraceResourceProvider implements ResourceProvider {
31
33
34
+ private static final Logger log =
35
+ LoggerFactory .getLogger (HypertraceResourceProvider .class .getName ());
36
+
32
37
private final CgroupsReader cgroupsReader = new CgroupsReader ();
33
38
private final AgentConfig agentConfig = HypertraceConfig .get ();
34
39
@@ -40,6 +45,23 @@ public Resource createResource(ConfigProperties config) {
40
45
builder .put (ResourceAttributes .CONTAINER_ID , containerId );
41
46
}
42
47
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 );
43
53
return Resource .create (builder .build ());
44
54
}
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
+ }
45
67
}
0 commit comments