-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ad684e
commit 7c7baef
Showing
2 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
src/main/java/io/unlogged/logging/perthread/MethodMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
58
src/main/java/io/unlogged/logging/perthread/OtelConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
|
||
} |