@@ -44,20 +44,23 @@ const includeDirs = [
44
44
path . resolve ( __dirname , '../../otlp-grpc-exporter-base/protos' ) ,
45
45
] ;
46
46
47
- const address = 'localhost:1503' ;
47
+ const httpAddr = 'https://localhost:1503' ;
48
+ const udsAddr = 'unix:///tmp/otlp-logs.sock' ;
48
49
49
50
type TestParams = {
51
+ address ?: string ;
50
52
useTLS ?: boolean ;
51
53
metadata ?: grpc . Metadata ;
52
54
} ;
53
55
54
56
const metadata = new grpc . Metadata ( ) ;
55
57
metadata . set ( 'k' , 'v' ) ;
56
58
57
- const testCollectorExporter = ( params : TestParams ) =>
58
- describe ( `OTLPLogExporter - node ${ params . useTLS ? 'with' : 'without' } TLS, ${
59
- params . metadata ? 'with' : 'without'
60
- } metadata`, ( ) => {
59
+ const testCollectorExporter = ( params : TestParams ) => {
60
+ const { address = httpAddr , useTLS, metadata } = params ;
61
+ return describe ( `OTLPLogExporter - node ${ useTLS ? 'with' : 'without' } TLS, ${
62
+ metadata ? 'with' : 'without'
63
+ } metadata, target ${ address } `, ( ) => {
61
64
let collectorExporter : OTLPLogExporter ;
62
65
let server : grpc . Server ;
63
66
let exportedData : IResourceLogs | undefined ;
@@ -92,7 +95,7 @@ const testCollectorExporter = (params: TestParams) =>
92
95
} ,
93
96
}
94
97
) ;
95
- const credentials = params . useTLS
98
+ const credentials = useTLS
96
99
? grpc . ServerCredentials . createSsl (
97
100
fs . readFileSync ( './test/certs/ca.crt' ) ,
98
101
[
@@ -103,10 +106,15 @@ const testCollectorExporter = (params: TestParams) =>
103
106
]
104
107
)
105
108
: grpc . ServerCredentials . createInsecure ( ) ;
106
- server . bindAsync ( address , credentials , ( ) => {
107
- server . start ( ) ;
108
- done ( ) ;
109
- } ) ;
109
+ const serverAddr = new URL ( address ) ;
110
+ server . bindAsync (
111
+ serverAddr . protocol === 'https:' ? serverAddr . host : address ,
112
+ credentials ,
113
+ ( ) => {
114
+ server . start ( ) ;
115
+ done ( ) ;
116
+ }
117
+ ) ;
110
118
} ) ;
111
119
} ) ;
112
120
@@ -115,17 +123,17 @@ const testCollectorExporter = (params: TestParams) =>
115
123
} ) ;
116
124
117
125
beforeEach ( done => {
118
- const credentials = params . useTLS
126
+ const credentials = useTLS
119
127
? grpc . credentials . createSsl (
120
128
fs . readFileSync ( './test/certs/ca.crt' ) ,
121
129
fs . readFileSync ( './test/certs/client.key' ) ,
122
130
fs . readFileSync ( './test/certs/client.crt' )
123
131
)
124
132
: grpc . credentials . createInsecure ( ) ;
125
133
collectorExporter = new OTLPLogExporter ( {
126
- url : 'https://' + address ,
134
+ url : address ,
127
135
credentials,
128
- metadata : params . metadata ,
136
+ metadata : metadata ,
129
137
} ) ;
130
138
done ( ) ;
131
139
} ) ;
@@ -141,7 +149,7 @@ const testCollectorExporter = (params: TestParams) =>
141
149
// Need to stub/spy on the underlying logger as the 'diag' instance is global
142
150
const spyLoggerWarn = sinon . stub ( diag , 'warn' ) ;
143
151
collectorExporter = new OTLPLogExporter ( {
144
- url : `http:// ${ address } ` ,
152
+ url : address ,
145
153
headers : {
146
154
foo : 'bar' ,
147
155
} ,
@@ -150,9 +158,13 @@ const testCollectorExporter = (params: TestParams) =>
150
158
assert . strictEqual ( args [ 0 ] , 'Headers cannot be set when using grpc' ) ;
151
159
} ) ;
152
160
it ( 'should warn about path in url' , ( ) => {
161
+ if ( new URL ( address ) . protocol === 'unix:' ) {
162
+ // Skip this test for UDS
163
+ return ;
164
+ }
153
165
const spyLoggerWarn = sinon . stub ( diag , 'warn' ) ;
154
166
collectorExporter = new OTLPLogExporter ( {
155
- url : `http:// ${ address } /v1/logs` ,
167
+ url : `${ address } /v1/logs` ,
156
168
} ) ;
157
169
const args = spyLoggerWarn . args [ 0 ] ;
158
170
assert . strictEqual (
@@ -190,7 +202,7 @@ const testCollectorExporter = (params: TestParams) =>
190
202
} , 500 ) ;
191
203
} ) ;
192
204
it ( 'should log deadline exceeded error' , done => {
193
- const credentials = params . useTLS
205
+ const credentials = useTLS
194
206
? grpc . credentials . createSsl (
195
207
fs . readFileSync ( './test/certs/ca.crt' ) ,
196
208
fs . readFileSync ( './test/certs/client.key' ) ,
@@ -199,9 +211,9 @@ const testCollectorExporter = (params: TestParams) =>
199
211
: grpc . credentials . createInsecure ( ) ;
200
212
201
213
const collectorExporterWithTimeout = new OTLPLogExporter ( {
202
- url : 'grpcs://' + address ,
214
+ url : address ,
203
215
credentials,
204
- metadata : params . metadata ,
216
+ metadata : metadata ,
205
217
timeoutMillis : 100 ,
206
218
} ) ;
207
219
@@ -222,21 +234,21 @@ const testCollectorExporter = (params: TestParams) =>
222
234
} ) ;
223
235
describe ( 'export - with gzip compression' , ( ) => {
224
236
beforeEach ( ( ) => {
225
- const credentials = params . useTLS
237
+ const credentials = useTLS
226
238
? grpc . credentials . createSsl (
227
239
fs . readFileSync ( './test/certs/ca.crt' ) ,
228
240
fs . readFileSync ( './test/certs/client.key' ) ,
229
241
fs . readFileSync ( './test/certs/client.crt' )
230
242
)
231
243
: grpc . credentials . createInsecure ( ) ;
232
244
collectorExporter = new OTLPLogExporter ( {
233
- url : 'https://' + address ,
245
+ url : address ,
234
246
credentials,
235
- metadata : params . metadata ,
247
+ metadata : metadata ,
236
248
compression : CompressionAlgorithm . GZIP ,
237
249
} ) ;
238
250
} ) ;
239
- it ( 'should successfully send the spans ' , done => {
251
+ it ( 'should successfully send the log records ' , done => {
240
252
const responseSpy = sinon . spy ( ) ;
241
253
const logRecords = [ Object . assign ( { } , mockedReadableLogRecord ) ] ;
242
254
collectorExporter . export ( logRecords , responseSpy ) ;
@@ -248,13 +260,13 @@ const testCollectorExporter = (params: TestParams) =>
248
260
const logs = exportedData . scopeLogs [ 0 ] . logRecords ;
249
261
const resource = exportedData . resource ;
250
262
251
- assert . ok ( typeof logs !== 'undefined' , 'spans do not exist' ) ;
263
+ assert . ok ( typeof logs !== 'undefined' , 'log records do not exist' ) ;
252
264
ensureExportedLogRecordIsCorrect ( logs [ 0 ] ) ;
253
265
254
266
assert . ok ( typeof resource !== 'undefined' , "resource doesn't exist" ) ;
255
267
ensureResourceIsCorrect ( resource ) ;
256
268
257
- ensureMetadataIsCorrect ( reqMetadata , params . metadata ) ;
269
+ ensureMetadataIsCorrect ( reqMetadata , metadata ) ;
258
270
259
271
done ( ) ;
260
272
} , 500 ) ;
@@ -263,7 +275,7 @@ const testCollectorExporter = (params: TestParams) =>
263
275
describe ( 'Logs Exporter with compression' , ( ) => {
264
276
const envSource = process . env ;
265
277
it ( 'should return gzip compression algorithm on exporter' , ( ) => {
266
- const credentials = params . useTLS
278
+ const credentials = useTLS
267
279
? grpc . credentials . createSsl (
268
280
fs . readFileSync ( './test/certs/ca.crt' ) ,
269
281
fs . readFileSync ( './test/certs/client.key' ) ,
@@ -273,9 +285,9 @@ const testCollectorExporter = (params: TestParams) =>
273
285
274
286
envSource . OTEL_EXPORTER_OTLP_COMPRESSION = 'gzip' ;
275
287
collectorExporter = new OTLPLogExporter ( {
276
- url : 'https://' + address ,
288
+ url : address ,
277
289
credentials,
278
- metadata : params . metadata ,
290
+ metadata : metadata ,
279
291
} ) ;
280
292
assert . strictEqual (
281
293
collectorExporter . compression ,
@@ -285,6 +297,7 @@ const testCollectorExporter = (params: TestParams) =>
285
297
} ) ;
286
298
} ) ;
287
299
} ) ;
300
+ } ;
288
301
289
302
describe ( 'OTLPLogExporter - node (getDefaultUrl)' , ( ) => {
290
303
it ( 'should default to localhost' , done => {
@@ -344,3 +357,5 @@ describe('when configuring via environment', () => {
344
357
testCollectorExporter ( { useTLS : true } ) ;
345
358
testCollectorExporter ( { useTLS : false } ) ;
346
359
testCollectorExporter ( { metadata } ) ;
360
+ // skip UDS tests on windows
361
+ process . platform !== 'win32' && testCollectorExporter ( { address : udsAddr } ) ;
0 commit comments