Skip to content

Commit 7560a51

Browse files
committed
semconv stable code
1 parent e865995 commit 7560a51

File tree

1 file changed

+27
-4
lines changed
  • instrumentation/log4j/log4j-appender-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/log4j/appender/v1_2

1 file changed

+27
-4
lines changed

instrumentation/log4j/log4j-appender-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/log4j/appender/v1_2/LogEventMapper.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
import io.opentelemetry.api.logs.LogRecordBuilder;
1515
import io.opentelemetry.api.logs.Severity;
1616
import io.opentelemetry.context.Context;
17+
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
1718
import io.opentelemetry.instrumentation.api.internal.cache.Cache;
1819
import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig;
20+
import io.opentelemetry.semconv.CodeAttributes;
1921
import io.opentelemetry.semconv.ExceptionAttributes;
2022
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
2123
import java.io.PrintWriter;
@@ -120,10 +122,24 @@ public void capture(
120122
LocationInfo locationInfo = new LocationInfo(new Throwable(), fqcn);
121123
String fileName = locationInfo.getFileName();
122124
if (fileName != null) {
123-
attributes.put(CODE_FILEPATH, fileName);
125+
if (SemconvStability.isEmitStableCodeSemconv()) {
126+
attributes.put(CodeAttributes.CODE_FILE_PATH, fileName);
127+
}
128+
if (SemconvStability.isEmitOldCodeSemconv()) {
129+
attributes.put(CODE_FILEPATH, fileName);
130+
}
131+
}
132+
133+
if (SemconvStability.isEmitStableCodeSemconv()) {
134+
attributes.put(
135+
CodeAttributes.CODE_FUNCTION_NAME,
136+
locationInfo.getClassName() + "." + locationInfo.getMethodName());
137+
}
138+
if (SemconvStability.isEmitOldCodeSemconv()) {
139+
attributes.put(CODE_NAMESPACE, locationInfo.getClassName());
140+
attributes.put(CODE_FUNCTION, locationInfo.getMethodName());
124141
}
125-
attributes.put(CODE_NAMESPACE, locationInfo.getClassName());
126-
attributes.put(CODE_FUNCTION, locationInfo.getMethodName());
142+
127143
String lineNumber = locationInfo.getLineNumber();
128144
int codeLineNo = 0;
129145
if (!lineNumber.equals("?")) {
@@ -133,7 +149,14 @@ public void capture(
133149
// ignore
134150
}
135151
}
136-
attributes.put(CODE_LINENO, codeLineNo);
152+
if (codeLineNo > 0) {
153+
if (SemconvStability.isEmitStableCodeSemconv()) {
154+
attributes.put(CodeAttributes.CODE_LINE_NUMBER, codeLineNo);
155+
}
156+
if (SemconvStability.isEmitOldCodeSemconv()) {
157+
attributes.put(CODE_LINENO, codeLineNo);
158+
}
159+
}
137160
}
138161

139162
builder.setAllAttributes(attributes.build());

0 commit comments

Comments
 (0)