1414import io .opentelemetry .api .logs .LogRecordBuilder ;
1515import io .opentelemetry .api .logs .Severity ;
1616import io .opentelemetry .context .Context ;
17+ import io .opentelemetry .instrumentation .api .internal .SemconvStability ;
1718import io .opentelemetry .instrumentation .api .internal .cache .Cache ;
1819import io .opentelemetry .javaagent .bootstrap .internal .AgentInstrumentationConfig ;
20+ import io .opentelemetry .semconv .CodeAttributes ;
1921import io .opentelemetry .semconv .ExceptionAttributes ;
2022import io .opentelemetry .semconv .incubating .ThreadIncubatingAttributes ;
2123import 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