Skip to content

Commit

Permalink
add otel config file
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikeytewari-ul committed Jul 11, 2024
1 parent 8ad684e commit 7c7baef
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 0 deletions.
108 changes: 108 additions & 0 deletions src/main/java/io/unlogged/logging/perthread/MethodMetadata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package io.unlogged.logging.perthread;

public class MethodMetadata {

private String className;
private String methodName;
private String argumentTypes;
private String returnType;
private String methodDesc;
private boolean isStatic;
private boolean isPublic;
private boolean usesFields;
private int methodAccess;

public MethodMetadata(
String className,
String methodName,
String argumentTypes,
String returnType,
boolean isStatic,
boolean isPublic,
boolean usesFields,
int methodAccess,
String methodDesc) {

this.className = className;
this.methodName = methodName;
this.argumentTypes = argumentTypes;
this.returnType = returnType;
this.isStatic = isStatic;
this.isPublic = isPublic;
this.usesFields = usesFields;
this.methodAccess = methodAccess;
this.methodDesc = methodDesc;
}

public String getClassName() {
return className;
}

public void setClassName(String className) {
this.className = className;
}

public String getMethodName() {
return methodName;
}

public void setMethodName(String methodName) {
this.methodName = methodName;
}

public String getArgumentTypes() {
return argumentTypes;
}

public void setArgumentTypes(String argumentTypes) {
this.argumentTypes = argumentTypes;
}

public String getReturnType() {
return returnType;
}

public void setReturnType(String returnType) {
this.returnType = returnType;
}

public boolean isStatic() {
return isStatic;
}

public void setStatic(boolean aStatic) {
isStatic = aStatic;
}

public boolean isPublic() {
return isPublic;
}

public void setPublic(boolean aPublic) {
isPublic = aPublic;
}

public boolean isUsesFields() {
return usesFields;
}

public void setUsesFields(boolean usesFields) {
this.usesFields = usesFields;
}

public int getMethodAccess() {
return methodAccess;
}

public void setMethodAccess(int methodAccess) {
this.methodAccess = methodAccess;
}

public String getMethodDesc() {
return methodDesc;
}

public void setMethodDesc(String methodDesc) {
this.methodDesc = methodDesc;
}
}
58 changes: 58 additions & 0 deletions src/main/java/io/unlogged/logging/perthread/OtelConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.unlogged.logging.perthread;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;

public class OtelConfig {

private static final Tracer tracer = GlobalOpenTelemetry.getTracer("unlogged-spring-maven-demo");

private static ObjectMapper instance;

static {
instance = new ObjectMapper();
}

public static void makeSpan(String keyValue, Object objectValue) {

// serialise object
Span span = tracer.spanBuilder("custom_tracer.1").startSpan();
try {
String objectString = instance.writeValueAsString(objectValue);
span.setAttribute(keyValue, objectString);
}
catch (JsonProcessingException e){
e.printStackTrace();
span.setAttribute(keyValue, "null");
}
span.end();
}

public static void registerMethod(
Span span,
int id,
String className,
String methodName,
String argumentTypes,
String returnType,
boolean isStatic,
boolean isPublic,
boolean usesFields,
int methodAccess,
String methodDesc
) {

MethodMetadata methodMetadata = new MethodMetadata(className, methodName, argumentTypes, returnType, isStatic, isPublic, usesFields, methodAccess, methodDesc);
try {
String objectString = instance.writeValueAsString(methodMetadata);
span.setAttribute("methodRegistration-" + id, objectString);
} catch (JsonProcessingException e) {
e.printStackTrace();
span.setAttribute("method_registration", "method registration have failed");
}
}

}

0 comments on commit 7c7baef

Please sign in to comment.