77import static org .junit .jupiter .api .Assertions .assertNotNull ;
88import static org .junit .jupiter .api .Assertions .assertNull ;
99
10- import java .time .Instant ;
1110import java .util .Map ;
1211
1312import io .opentelemetry .api .trace .SpanContext ;
14- import io .opentelemetry .api .trace .SpanId ;
15- import io .opentelemetry .api .trace .TraceFlags ;
16- import io .opentelemetry .api .trace .TraceId ;
17- import io .opentelemetry .api .trace .TraceState ;
1813import io .opentelemetry .sdk .common .InstrumentationScopeInfo ;
1914import io .opentelemetry .sdk .logs .data .Body ;
2015import io .opentelemetry .sdk .logs .data .LogRecordData ;
3530class LogDataMapperTest {
3631 @ Test
3732 void testCustomEventName () {
38- LogRecordData logRecordData = new LogRecordData () {
39- @ Override
40- public Resource getResource () {
41- return Resource .empty ();
42- }
43-
44- @ Override
45- public Attributes getAttributes () {
46- return Attributes .builder ().put ("microsoft.custom_event.name" , "TestEvent" ).build ();
47- }
48-
49- @ Override
50- public InstrumentationScopeInfo getInstrumentationScopeInfo () {
51- return InstrumentationScopeInfo .create ("TestScope" , null , null );
52- }
53-
54- @ Override
55- public long getTimestampEpochNanos () {
56- return Instant .now ().toEpochMilli () * 1_000_000 ; // Convert millis to nanos
57- }
58-
59- @ Override
60- public long getObservedTimestampEpochNanos () {
61- return Instant .now ().toEpochMilli () * 1_000_000 ;
62- }
63-
64- @ Override
65- public SpanContext getSpanContext () {
66- return SpanContext .create (TraceId .fromLongs (12345L , 67890L ), SpanId .fromLong (12345L ),
67- TraceFlags .getDefault (), TraceState .getDefault ());
68- }
69-
70- @ Override
71- public Severity getSeverity () {
72- return Severity .INFO ;
73- }
74-
75- @ Override
76- public String getSeverityText () {
77- return "INFO" ;
78- }
79-
80- @ Override
81- public Body getBody () {
82- return Body .string ("Test log message" );
83- }
84-
85- @ Override
86- public int getTotalAttributeCount () {
87- return 1 ;
88- }
89- };
33+ Attributes attributes = Attributes .builder ().put ("microsoft.custom_event.name" , "TestEvent" ).build ();
34+
35+ LogRecordData logRecordData = new SimpleLogRecordData (attributes );
9036
9137 LogDataMapper logDataMapper = new LogDataMapper (true , true , (b , r ) -> {
9238 // Initialize telemetry builder with resource
@@ -167,12 +113,11 @@ void testStableCodeFunctionWithoutNamespace() {
167113 }
168114
169115 private static final class SimpleLogRecordData implements LogRecordData {
116+
170117 private final Attributes attributes ;
171- private final long timestamp ;
172118
173119 private SimpleLogRecordData (Attributes attributes ) {
174120 this .attributes = attributes ;
175- this .timestamp = Instant .now ().toEpochMilli () * 1_000_000 ;
176121 }
177122
178123 @ Override
@@ -192,12 +137,12 @@ public InstrumentationScopeInfo getInstrumentationScopeInfo() {
192137
193138 @ Override
194139 public long getTimestampEpochNanos () {
195- return timestamp ;
140+ return 0 ;
196141 }
197142
198143 @ Override
199144 public long getObservedTimestampEpochNanos () {
200- return timestamp ;
145+ return 0 ;
201146 }
202147
203148 @ Override
@@ -212,12 +157,12 @@ public Severity getSeverity() {
212157
213158 @ Override
214159 public String getSeverityText () {
215- return " INFO" ;
160+ return Severity . INFO . name () ;
216161 }
217162
218163 @ Override
219164 public Body getBody () {
220- return Body .string ( "Test log message" );
165+ return Body .empty ( );
221166 }
222167
223168 @ Override
0 commit comments