@@ -47,6 +47,27 @@ void getAggregationTemporality() {
47
47
.isEqualTo (AggregationTemporality .DELTA );
48
48
}
49
49
50
+ @ Test
51
+ void getAggregationTemporalityWithWrapperJsonObject () {
52
+ // Test that the new create method with wrapperJsonObject parameter maintains correct aggregation temporality
53
+ assertThat (
54
+ OtlpJsonLoggingMetricExporter .create (AggregationTemporality .CUMULATIVE , false )
55
+ .getAggregationTemporality (InstrumentType .COUNTER ))
56
+ .isEqualTo (AggregationTemporality .CUMULATIVE );
57
+ assertThat (
58
+ OtlpJsonLoggingMetricExporter .create (AggregationTemporality .DELTA , false )
59
+ .getAggregationTemporality (InstrumentType .COUNTER ))
60
+ .isEqualTo (AggregationTemporality .DELTA );
61
+ assertThat (
62
+ OtlpJsonLoggingMetricExporter .create (AggregationTemporality .CUMULATIVE , true )
63
+ .getAggregationTemporality (InstrumentType .COUNTER ))
64
+ .isEqualTo (AggregationTemporality .CUMULATIVE );
65
+ assertThat (
66
+ OtlpJsonLoggingMetricExporter .create (AggregationTemporality .DELTA , true )
67
+ .getAggregationTemporality (InstrumentType .COUNTER ))
68
+ .isEqualTo (AggregationTemporality .DELTA );
69
+ }
70
+
50
71
@ Test
51
72
void log () throws Exception {
52
73
testDataExporter .export (exporter );
@@ -60,6 +81,51 @@ void log() throws Exception {
60
81
assertThat (message ).doesNotContain ("\n " );
61
82
}
62
83
84
+ @ Test
85
+ void logWithWrapperJsonObjectFalse () throws Exception {
86
+ // Test that wrapperJsonObject=false produces the same output as the default create()
87
+ MetricExporter exporterWithoutWrapper = OtlpJsonLoggingMetricExporter .create (AggregationTemporality .CUMULATIVE , false );
88
+ testDataExporter .export (exporterWithoutWrapper );
89
+
90
+ assertThat (logs .getEvents ())
91
+ .hasSize (1 )
92
+ .allSatisfy (log -> assertThat (log .getLevel ()).isEqualTo (Level .INFO ));
93
+ String message = logs .getEvents ().get (0 ).getMessage ();
94
+ String expectedJson = testDataExporter .getExpectedJson (false );
95
+ JSONAssert .assertEquals ("Got \n " + message , expectedJson , message , /* strict= */ false );
96
+ assertThat (message ).doesNotContain ("\n " );
97
+ }
98
+
99
+ @ Test
100
+ void logWithWrapperJsonObjectTrue () throws Exception {
101
+ // Test that wrapperJsonObject=true produces wrapper format (enables low allocation)
102
+ MetricExporter exporterWithWrapper = OtlpJsonLoggingMetricExporter .create (AggregationTemporality .CUMULATIVE , true );
103
+ testDataExporter .export (exporterWithWrapper );
104
+
105
+ assertThat (logs .getEvents ())
106
+ .hasSize (1 )
107
+ .allSatisfy (log -> assertThat (log .getLevel ()).isEqualTo (Level .INFO ));
108
+ String message = logs .getEvents ().get (0 ).getMessage ();
109
+ String expectedJson = testDataExporter .getExpectedJson (true );
110
+ JSONAssert .assertEquals ("Got \n " + message , expectedJson , message , /* strict= */ false );
111
+ assertThat (message ).doesNotContain ("\n " );
112
+ }
113
+
114
+ @ Test
115
+ void logWithWrapperJsonObjectTrueAndDeltaTemporality () throws Exception {
116
+ // Test that wrapperJsonObject=true works with DELTA temporality too
117
+ MetricExporter exporterWithWrapper = OtlpJsonLoggingMetricExporter .create (AggregationTemporality .DELTA , true );
118
+ testDataExporter .export (exporterWithWrapper );
119
+
120
+ assertThat (logs .getEvents ())
121
+ .hasSize (1 )
122
+ .allSatisfy (log -> assertThat (log .getLevel ()).isEqualTo (Level .INFO ));
123
+ String message = logs .getEvents ().get (0 ).getMessage ();
124
+ String expectedJson = testDataExporter .getExpectedJson (true );
125
+ JSONAssert .assertEquals ("Got \n " + message , expectedJson , message , /* strict= */ false );
126
+ assertThat (message ).doesNotContain ("\n " );
127
+ }
128
+
63
129
@ Test
64
130
void flush () {
65
131
assertThat (exporter .flush ().isSuccess ()).isTrue ();
0 commit comments