@@ -19,49 +19,106 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests;
19
19
public sealed class IntegrationTests : IDisposable
20
20
{
21
21
private const string CollectorHostnameEnvVarName = "OTEL_COLLECTOR_HOSTNAME" ;
22
- private const int ExportIntervalMilliseconds = 10000 ;
22
+ private const int ExportIntervalMilliseconds = 10_000 ;
23
+ private const string GrpcEndpointHttp = ":4317" ;
24
+ private const string GrpcEndpointHttps = ":5317" ;
25
+ private const string ProtobufEndpointHttp = ":4318/v1/" ;
26
+ private const string ProtobufEndpointHttps = ":5318/v1/" ;
27
+
23
28
private static readonly SdkLimitOptions DefaultSdkLimitOptions = new ( ) ;
24
29
private static readonly ExperimentalOptions DefaultExperimentalOptions = new ( ) ;
25
30
private static readonly string ? CollectorHostname = SkipUnlessEnvVarFoundTheoryAttribute . GetEnvironmentVariable ( CollectorHostnameEnvVarName ) ;
31
+
32
+ private static readonly bool [ ] BooleanValues = [ false , true ] ;
33
+ private static readonly ExportProcessorType [ ] ExportProcessorTypes = [ ExportProcessorType . Batch , ExportProcessorType . Simple ] ;
34
+
26
35
private readonly OpenTelemetryEventListener openTelemetryEventListener ;
27
36
28
37
public IntegrationTests ( ITestOutputHelper outputHelper )
29
38
{
30
39
this . openTelemetryEventListener = new ( outputHelper ) ;
31
40
}
32
41
33
- public void Dispose ( )
42
+ public static TheoryData < OtlpExportProtocol , string , ExportProcessorType , bool , string > TraceTestCases ( )
43
+ {
44
+ var data = new TheoryData < OtlpExportProtocol , string , ExportProcessorType , bool , string > ( ) ;
45
+
46
+ #pragma warning disable CS0618 // Suppressing gRPC obsolete warning
47
+ foreach ( var exportType in ExportProcessorTypes )
48
+ {
49
+ foreach ( var forceFlush in BooleanValues )
50
+ {
51
+ data . Add ( OtlpExportProtocol . Grpc , GrpcEndpointHttp , exportType , forceFlush , Uri . UriSchemeHttp ) ;
52
+ data . Add ( OtlpExportProtocol . HttpProtobuf , $ "{ ProtobufEndpointHttp } traces", exportType , forceFlush , Uri . UriSchemeHttp ) ;
53
+ }
54
+ }
55
+
56
+ data . Add ( OtlpExportProtocol . Grpc , GrpcEndpointHttps , ExportProcessorType . Simple , true , Uri . UriSchemeHttps ) ;
57
+ data . Add ( OtlpExportProtocol . HttpProtobuf , $ "{ ProtobufEndpointHttps } traces", ExportProcessorType . Simple , true , Uri . UriSchemeHttps ) ;
58
+ #pragma warning restore CS0618 // Suppressing gRPC obsolete warning
59
+
60
+ return data ;
61
+ }
62
+
63
+ public static TheoryData < OtlpExportProtocol , string , bool , bool , string > MetricsTestCases ( )
34
64
{
35
- this . openTelemetryEventListener . Dispose ( ) ;
65
+ var data = new TheoryData < OtlpExportProtocol , string , bool , bool , string > ( ) ;
66
+
67
+ #pragma warning disable CS0618 // Suppressing gRPC obsolete warning
68
+ foreach ( var useManualExport in BooleanValues )
69
+ {
70
+ foreach ( var forceFlush in BooleanValues )
71
+ {
72
+ data . Add ( OtlpExportProtocol . Grpc , GrpcEndpointHttp , useManualExport , forceFlush , Uri . UriSchemeHttp ) ;
73
+ data . Add ( OtlpExportProtocol . HttpProtobuf , $ "{ ProtobufEndpointHttp } metrics", useManualExport , forceFlush , Uri . UriSchemeHttp ) ;
74
+ }
75
+ }
76
+
77
+ data . Add ( OtlpExportProtocol . Grpc , GrpcEndpointHttps , true , true , Uri . UriSchemeHttps ) ;
78
+ data . Add ( OtlpExportProtocol . HttpProtobuf , $ "{ ProtobufEndpointHttps } metrics", true , true , Uri . UriSchemeHttps ) ;
79
+ #pragma warning restore CS0618 // Suppressing gRPC obsolete warning
80
+
81
+ return data ;
36
82
}
37
83
84
+ public static TheoryData < OtlpExportProtocol , string , ExportProcessorType , string > LogsTestCases ( )
85
+ {
86
+ var data = new TheoryData < OtlpExportProtocol , string , ExportProcessorType , string > ( ) ;
87
+
38
88
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
39
- [ InlineData ( OtlpExportProtocol . Grpc , ":4317" , ExportProcessorType . Batch , false ) ]
40
- [ InlineData ( OtlpExportProtocol . HttpProtobuf , ":4318/v1/traces" , ExportProcessorType . Batch , false ) ]
41
- [ InlineData ( OtlpExportProtocol . Grpc , ":4317" , ExportProcessorType . Batch , true ) ]
42
- [ InlineData ( OtlpExportProtocol . HttpProtobuf , ":4318/v1/traces" , ExportProcessorType . Batch , true ) ]
43
- [ InlineData ( OtlpExportProtocol . Grpc , ":4317" , ExportProcessorType . Simple , false ) ]
44
- [ InlineData ( OtlpExportProtocol . HttpProtobuf , ":4318/v1/traces" , ExportProcessorType . Simple , false ) ]
45
- [ InlineData ( OtlpExportProtocol . Grpc , ":4317" , ExportProcessorType . Simple , true ) ]
46
- [ InlineData ( OtlpExportProtocol . HttpProtobuf , ":4318/v1/traces" , ExportProcessorType . Simple , true ) ]
47
- [ InlineData ( OtlpExportProtocol . Grpc , ":5317" , ExportProcessorType . Simple , true , "https" ) ]
48
- [ InlineData ( OtlpExportProtocol . HttpProtobuf , ":5318/v1/traces" , ExportProcessorType . Simple , true , "https" ) ]
89
+ foreach ( var exportType in ExportProcessorTypes )
90
+ {
91
+ data . Add ( OtlpExportProtocol . Grpc , GrpcEndpointHttp , exportType , Uri . UriSchemeHttp ) ;
92
+ data . Add ( OtlpExportProtocol . HttpProtobuf , $ "{ ProtobufEndpointHttp } logs", exportType , Uri . UriSchemeHttp ) ;
93
+ }
94
+
95
+ data . Add ( OtlpExportProtocol . Grpc , GrpcEndpointHttps , ExportProcessorType . Simple , Uri . UriSchemeHttps ) ;
96
+ data . Add ( OtlpExportProtocol . HttpProtobuf , $ "{ ProtobufEndpointHttps } logs", ExportProcessorType . Simple , Uri . UriSchemeHttps ) ;
49
97
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
98
+
99
+ return data ;
100
+ }
101
+
102
+ public void Dispose ( ) => this . openTelemetryEventListener . Dispose ( ) ;
103
+
50
104
[ Trait ( "CategoryName" , "CollectorIntegrationTests" ) ]
51
105
[ SkipUnlessEnvVarFoundTheory ( CollectorHostnameEnvVarName ) ]
52
- public void TraceExportResultIsSuccess ( OtlpExportProtocol protocol , string endpoint , ExportProcessorType exportProcessorType , bool forceFlush , string scheme = "http" )
106
+ [ MemberData ( nameof ( TraceTestCases ) ) ]
107
+ public void TraceExportResultIsSuccess (
108
+ OtlpExportProtocol protocol ,
109
+ string endpoint ,
110
+ ExportProcessorType exportProcessorType ,
111
+ bool forceFlush ,
112
+ string scheme )
53
113
{
54
- using EventWaitHandle handle = new ManualResetEvent ( false ) ;
114
+ using var handle = new ManualResetEvent ( false ) ;
115
+
116
+ var exporterOptions = CreateExporterOptions ( protocol , scheme , endpoint ) ;
55
117
56
- var exporterOptions = new OtlpExporterOptions
118
+ exporterOptions . ExportProcessorType = exportProcessorType ;
119
+ exporterOptions . BatchExportProcessorOptions = new ( )
57
120
{
58
- Endpoint = new Uri ( $ "{ scheme } ://{ CollectorHostname } { endpoint } ") ,
59
- Protocol = protocol ,
60
- ExportProcessorType = exportProcessorType ,
61
- BatchExportProcessorOptions = new ( )
62
- {
63
- ScheduledDelayMilliseconds = ExportIntervalMilliseconds ,
64
- } ,
121
+ ScheduledDelayMilliseconds = ExportIntervalMilliseconds ,
65
122
} ;
66
123
67
124
DelegatingExporter < Activity > ? delegatingExporter = null ;
@@ -121,29 +178,19 @@ public void TraceExportResultIsSuccess(OtlpExportProtocol protocol, string endpo
121
178
}
122
179
}
123
180
124
- #pragma warning disable CS0618 // Suppressing gRPC obsolete warning
125
- [ InlineData ( OtlpExportProtocol . Grpc , ":4317" , false , false ) ]
126
- [ InlineData ( OtlpExportProtocol . HttpProtobuf , ":4318/v1/metrics" , false , false ) ]
127
- [ InlineData ( OtlpExportProtocol . Grpc , ":4317" , false , true ) ]
128
- [ InlineData ( OtlpExportProtocol . HttpProtobuf , ":4318/v1/metrics" , false , true ) ]
129
- [ InlineData ( OtlpExportProtocol . Grpc , ":4317" , true , false ) ]
130
- [ InlineData ( OtlpExportProtocol . HttpProtobuf , ":4318/v1/metrics" , true , false ) ]
131
- [ InlineData ( OtlpExportProtocol . Grpc , ":4317" , true , true ) ]
132
- [ InlineData ( OtlpExportProtocol . HttpProtobuf , ":4318/v1/metrics" , true , true ) ]
133
- [ InlineData ( OtlpExportProtocol . Grpc , ":5317" , true , true , "https" ) ]
134
- [ InlineData ( OtlpExportProtocol . HttpProtobuf , ":5318/v1/metrics" , true , true , "https" ) ]
135
- #pragma warning restore CS0618 // Suppressing gRPC obsolete warning
136
181
[ Trait ( "CategoryName" , "CollectorIntegrationTests" ) ]
137
182
[ SkipUnlessEnvVarFoundTheory ( CollectorHostnameEnvVarName ) ]
138
- public void MetricExportResultIsSuccess ( OtlpExportProtocol protocol , string endpoint , bool useManualExport , bool forceFlush , string scheme = "http" )
183
+ [ MemberData ( nameof ( MetricsTestCases ) ) ]
184
+ public void MetricExportResultIsSuccess (
185
+ OtlpExportProtocol protocol ,
186
+ string endpoint ,
187
+ bool useManualExport ,
188
+ bool forceFlush ,
189
+ string scheme )
139
190
{
140
- using EventWaitHandle handle = new ManualResetEvent ( false ) ;
191
+ using var handle = new ManualResetEvent ( false ) ;
141
192
142
- var exporterOptions = new OtlpExporterOptions
143
- {
144
- Endpoint = new Uri ( $ "{ scheme } ://{ CollectorHostname } { endpoint } ") ,
145
- Protocol = protocol ,
146
- } ;
193
+ var exporterOptions = CreateExporterOptions ( protocol , scheme , endpoint ) ;
147
194
148
195
DelegatingExporter < Metric > ? delegatingExporter = null ;
149
196
var exportResults = new List < ExportResult > ( ) ;
@@ -207,25 +254,18 @@ public void MetricExportResultIsSuccess(OtlpExportProtocol protocol, string endp
207
254
}
208
255
}
209
256
210
- #pragma warning disable CS0618 // Suppressing gRPC obsolete warning
211
- [ InlineData ( OtlpExportProtocol . Grpc , ":4317" , ExportProcessorType . Batch ) ]
212
- [ InlineData ( OtlpExportProtocol . HttpProtobuf , ":4318/v1/logs" , ExportProcessorType . Batch ) ]
213
- [ InlineData ( OtlpExportProtocol . Grpc , ":4317" , ExportProcessorType . Simple ) ]
214
- [ InlineData ( OtlpExportProtocol . HttpProtobuf , ":4318/v1/logs" , ExportProcessorType . Simple ) ]
215
- [ InlineData ( OtlpExportProtocol . Grpc , ":5317" , ExportProcessorType . Simple , "https" ) ]
216
- [ InlineData ( OtlpExportProtocol . HttpProtobuf , ":5318/v1/logs" , ExportProcessorType . Simple , "https" ) ]
217
- #pragma warning restore CS0618 // Suppressing gRPC obsolete warning
218
257
[ Trait ( "CategoryName" , "CollectorIntegrationTests" ) ]
219
258
[ SkipUnlessEnvVarFoundTheory ( CollectorHostnameEnvVarName ) ]
220
- public void LogExportResultIsSuccess ( OtlpExportProtocol protocol , string endpoint , ExportProcessorType exportProcessorType , string scheme = "http" )
259
+ [ MemberData ( nameof ( LogsTestCases ) ) ]
260
+ public void LogExportResultIsSuccess (
261
+ OtlpExportProtocol protocol ,
262
+ string endpoint ,
263
+ ExportProcessorType exportProcessorType ,
264
+ string scheme )
221
265
{
222
- using EventWaitHandle handle = new ManualResetEvent ( false ) ;
266
+ using var handle = new ManualResetEvent ( false ) ;
223
267
224
- var exporterOptions = new OtlpExporterOptions
225
- {
226
- Endpoint = new Uri ( $ "{ scheme } ://{ CollectorHostname } { endpoint } ") ,
227
- Protocol = protocol ,
228
- } ;
268
+ var exporterOptions = CreateExporterOptions ( protocol , scheme , endpoint ) ;
229
269
230
270
DelegatingExporter < LogRecord > delegatingExporter ;
231
271
var exportResults = new List < ExportResult > ( ) ;
@@ -275,24 +315,26 @@ public void LogExportResultIsSuccess(OtlpExportProtocol protocol, string endpoin
275
315
Assert . Single ( exportResults ) ;
276
316
Assert . Equal ( ExportResult . Success , exportResults [ 0 ] ) ;
277
317
break ;
318
+
278
319
case ExportProcessorType . Simple :
279
320
Assert . Single ( exportResults ) ;
280
321
Assert . Equal ( ExportResult . Success , exportResults [ 0 ] ) ;
281
322
break ;
323
+
282
324
default :
283
325
throw new NotSupportedException ( "Unexpected processor type encountered." ) ;
284
326
}
285
327
}
286
328
287
- private sealed class OpenTelemetryEventListener : EventListener
288
- {
289
- private readonly ITestOutputHelper outputHelper ;
290
-
291
- public OpenTelemetryEventListener ( ITestOutputHelper outputHelper )
329
+ private static OtlpExporterOptions CreateExporterOptions ( OtlpExportProtocol protocol , string scheme , string endpoint ) =>
330
+ new ( )
292
331
{
293
- this . outputHelper = outputHelper ;
294
- }
332
+ Endpoint = new ( $ "{ scheme } ://{ CollectorHostname } { endpoint } ") ,
333
+ Protocol = protocol ,
334
+ } ;
295
335
336
+ private sealed class OpenTelemetryEventListener ( ITestOutputHelper outputHelper ) : EventListener
337
+ {
296
338
protected override void OnEventSourceCreated ( EventSource eventSource )
297
339
{
298
340
base . OnEventSourceCreated ( eventSource ) ;
@@ -305,17 +347,13 @@ protected override void OnEventSourceCreated(EventSource eventSource)
305
347
306
348
protected override void OnEventWritten ( EventWrittenEventArgs eventData )
307
349
{
308
- string ? message ;
309
- if ( eventData . Message != null && eventData . Payload != null && eventData . Payload . Count > 0 )
310
- {
311
- message = string . Format ( CultureInfo . InvariantCulture , eventData . Message , eventData . Payload . ToArray ( ) ) ;
312
- }
313
- else
314
- {
315
- message = eventData . Message ;
316
- }
350
+ var message = eventData . Message != null && eventData . Payload ? . Count > 0
351
+ ? string . Format ( CultureInfo . InvariantCulture , eventData . Message , [ .. eventData . Payload ] )
352
+ : eventData . Message ;
353
+
354
+ message = string . Format ( CultureInfo . InvariantCulture , "[{0}] {1}" , eventData . Level , message ) ;
317
355
318
- this . outputHelper . WriteLine ( message ) ;
356
+ outputHelper . WriteLine ( message ) ;
319
357
}
320
358
}
321
359
}
0 commit comments