File: ostream_log_test.cc

package info (click to toggle)
opentelemetry-cpp 1.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,372 kB
  • sloc: cpp: 96,239; sh: 1,766; makefile: 36; python: 31
file content (538 lines) | stat: -rw-r--r-- 21,560 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <gtest/gtest.h>
#include <array>
#include <chrono>
#include <initializer_list>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/common/key_value_iterable_view.h"
#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/exporters/ostream/log_record_exporter.h"
#include "opentelemetry/exporters/ostream/log_record_exporter_factory.h"
#include "opentelemetry/logs/event_id.h"
#include "opentelemetry/logs/logger.h"
#include "opentelemetry/logs/logger_provider.h"
#include "opentelemetry/logs/provider.h"
#include "opentelemetry/logs/severity.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/utility.h"
#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
#include "opentelemetry/sdk/logs/exporter.h"
#include "opentelemetry/sdk/logs/logger_provider.h"
#include "opentelemetry/sdk/logs/processor.h"
#include "opentelemetry/sdk/logs/provider.h"
#include "opentelemetry/sdk/logs/read_write_log_record.h"
#include "opentelemetry/sdk/logs/readable_log_record.h"
#include "opentelemetry/sdk/logs/recordable.h"
#include "opentelemetry/sdk/logs/simple_log_record_processor.h"
#include "opentelemetry/sdk/resource/resource.h"
#include "opentelemetry/sdk/version/version.h"
#include "opentelemetry/version.h"

namespace sdklogs      = opentelemetry::sdk::logs;
namespace logs_api     = opentelemetry::logs;
namespace nostd        = opentelemetry::nostd;
namespace exporterlogs = opentelemetry::exporter::logs;
namespace common       = opentelemetry::common;

using Attributes = std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>;

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace logs
{

namespace
{
static opentelemetry::sdk::instrumentationscope::InstrumentationScope GetTestInstrumentationScope()
{
  opentelemetry::sdk::instrumentationscope::InstrumentationScope result =
      opentelemetry::sdk::logs::ReadableLogRecord::GetDefaultInstrumentationScope();

  result.SetAttribute("scope.attr.key", "scope.attr.value");

  return result;
}
}  // namespace

// Test that when OStream Log exporter is shutdown, no logs should be sent to stream
TEST(OStreamLogRecordExporter, Shutdown)
{
  auto exporter =
      std::unique_ptr<sdklogs::LogRecordExporter>(new exporterlogs::OStreamLogRecordExporter);

  // Save cerr original buffer here
  std::streambuf *original = std::cerr.rdbuf();

  // Redirect cerr to our stringstream buffer
  std::stringstream output;
  std::cerr.rdbuf(output.rdbuf());

  EXPECT_TRUE(exporter->Shutdown());

  // After processor/exporter is shutdown, no logs should be sent to stream
  auto record = exporter->MakeRecordable();
  static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetBody("Log record not empty");
  exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&record, 1));

  // Restore original stringstream buffer
  std::cerr.rdbuf(original);
  std::string err_message =
      "[Ostream Log Exporter] Exporting 1 log(s) failed, exporter is shutdown";
  EXPECT_TRUE(output.str().find(err_message) != std::string::npos);
}

// ---------------------------------- Print to cout -------------------------

// Testing what a default log record that has no values changed will print out
// This function tests MakeRecordable() as well as Export().
TEST(OstreamLogExporter, DefaultLogRecordToCout)
{
  auto exporter = std::unique_ptr<sdklogs::LogRecordExporter>(
      new exporterlogs::OStreamLogRecordExporter(std::cout));

  // Save cout's original buffer here
  std::streambuf *original = std::cout.rdbuf();

  // Redirect cout to our stringstream buffer
  std::stringstream output;
  std::cout.rdbuf(output.rdbuf());

  // Pass a default recordable created by the exporter to be exported
  auto log_record = exporter->MakeRecordable();
  opentelemetry::sdk::instrumentationscope::InstrumentationScope instrumentation_scope =
      GetTestInstrumentationScope();
  log_record->SetInstrumentationScope(instrumentation_scope);
  exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&log_record, 1));

  // Restore cout's original stringstream
  std::cout.rdbuf(original);

  std::vector<std::string> expected_output{
      "{\n",
      "  timestamp          : 0\n",
      "  severity_num       : 0\n",
      "  severity_text      : INVALID\n",
      "  body               : \n",
      "  resource           : \n",
      std::string{"    telemetry.sdk.version: "} + OPENTELEMETRY_SDK_VERSION + "\n",
      "    telemetry.sdk.name: opentelemetry\n",
      "    telemetry.sdk.language: cpp\n",
      "  attributes         : \n",
      "  event_id           : 0\n",
      "  event_name         : \n",
      "  trace_id           : 00000000000000000000000000000000\n",
      "  span_id            : 0000000000000000\n",
      "  trace_flags        : 00\n",
      "  scope              : \n",
      "    name             : otel-cpp\n",
      std::string{"    version          : "} + OPENTELEMETRY_SDK_VERSION + "\n",
      "    schema_url       : https://opentelemetry.io/schemas/1.15.0\n",
      "    attributes       : \n",
      "      scope.attr.key: scope.attr.value\n",
      "}\n"};

  std::string ostream_output = output.str();
  for (auto &expected : expected_output)
  {
    std::string::size_type result = ostream_output.find(expected);
    if (result == std::string::npos)
    {
      std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n';
    }
    ASSERT_NE(result, std::string::npos);
  }
}

// Testing what a log record with only the "timestamp", "severity", "name" and "message" fields set,
// will print out
TEST(OStreamLogRecordExporter, SimpleLogToCout)
{
  // Initialize an Ostream exporter to std::cout
  auto exporter = std::unique_ptr<sdklogs::LogRecordExporter>(
      new exporterlogs::OStreamLogRecordExporter(std::cout));

  // Save original stream buffer, then redirect cout to our new stream buffer
  std::streambuf *original = std::cout.rdbuf();
  std::stringstream output;
  std::cout.rdbuf(output.rdbuf());

  // Pass a default recordable created by the exporter to be exported
  // Create a log record and manually timestamp, severity, name, message
  common::SystemTimestamp now(std::chrono::system_clock::now());

  auto record = std::unique_ptr<sdklogs::Recordable>(new sdklogs::ReadWriteLogRecord());
  static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetTimestamp(now);
  static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetObservedTimestamp(now);
  static_cast<sdklogs::ReadWriteLogRecord *>(record.get())
      ->SetSeverity(logs_api::Severity::kTrace);  // kTrace has enum value of 1
  static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetBody("Message");

  opentelemetry::sdk::instrumentationscope::InstrumentationScope instrumentation_scope =
      GetTestInstrumentationScope();
  record->SetInstrumentationScope(instrumentation_scope);

  // Log a record to cout
  exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&record, 1));

  // Reset cout's original stringstream buffer
  std::cout.rdbuf(original);

  std::vector<std::string> expected_output{
      "{\n",
      "  timestamp          : " + std::to_string(now.time_since_epoch().count()) +
          "\n"
          "  observed_timestamp : " +
          std::to_string(now.time_since_epoch().count()) +
          "\n"
          "  severity_num       : 1\n"
          "  severity_text      : TRACE\n"
          "  body               : Message\n",
      "  resource           : \n",
      std::string{"    telemetry.sdk.version: "} + OPENTELEMETRY_SDK_VERSION + "\n",
      "    telemetry.sdk.name: opentelemetry\n",
      "    telemetry.sdk.language: cpp\n",
      "  attributes         : \n",
      "  event_id           : 0\n",
      "  event_name         : \n",
      "  trace_id           : 00000000000000000000000000000000\n",
      "  span_id            : 0000000000000000\n",
      "  trace_flags        : 00\n",
      "  scope              : \n",
      "    name             : otel-cpp\n",
      std::string{"    version          : "} + OPENTELEMETRY_SDK_VERSION + "\n",
      "    schema_url       : https://opentelemetry.io/schemas/1.15.0\n",
      "    attributes       : \n",
      "      scope.attr.key: scope.attr.value\n",
      "}\n"};

  std::string ostream_output = output.str();
  for (auto &expected : expected_output)
  {
    std::string::size_type result = ostream_output.find(expected);
    if (result == std::string::npos)
    {
      std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n';
    }
    ASSERT_NE(result, std::string::npos);
  }
}

// ---------------------------------- Print to cerr --------------------------

// Testing what a log record with only the "resource" and "attributes" fields
// (i.e. KeyValueIterable types) set with primitive types, will print out
TEST(OStreamLogRecordExporter, LogWithStringAttributesToCerr)
{
  // Initialize an Ostream exporter to cerr
  auto exporter = std::unique_ptr<sdklogs::LogRecordExporter>(
      new exporterlogs::OStreamLogRecordExporter(std::cerr));

  // Save original stream buffer, then redirect cout to our new stream buffer
  std::streambuf *original = std::cerr.rdbuf();
  std::stringstream stdcerrOutput;
  std::cerr.rdbuf(stdcerrOutput.rdbuf());

  // Pass a recordable created by the exporter to be exported
  auto record = exporter->MakeRecordable();

  // Set resources for this log record only of type <string, string>
  auto resource = opentelemetry::sdk::resource::Resource::Create({{"key1", "val1"}});
  static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetResource(resource);

  // Set attributes to this log record of type <string, AttributeValue>
  static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetAttribute("a", true);

  opentelemetry::sdk::instrumentationscope::InstrumentationScope instrumentation_scope =
      GetTestInstrumentationScope();
  record->SetInstrumentationScope(instrumentation_scope);

  // Log record to cerr
  exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&record, 1));

  // Reset cerr's original stringstream buffer
  std::cerr.rdbuf(original);

  std::vector<std::string> expected_output{
      "{\n",
      "  timestamp          : 0\n",
      "  severity_num       : 0\n",
      "  severity_text      : INVALID\n",
      "  body               : \n",
      "  resource           : \n",
      std::string{"    telemetry.sdk.version: "} + OPENTELEMETRY_SDK_VERSION + "\n",
      "    telemetry.sdk.name: opentelemetry\n",
      "    telemetry.sdk.language: cpp\n",
      "    service.name: unknown_service\n",
      "    key1: val1\n",
      "  attributes         : \n",
      "    a: 1\n",
      "  event_id           : 0\n",
      "  event_name         : \n",
      "  trace_id           : 00000000000000000000000000000000\n",
      "  span_id            : 0000000000000000\n",
      "  trace_flags        : 00\n",
      "  scope              : \n",
      "    name             : otel-cpp\n",
      std::string{"    version          : "} + OPENTELEMETRY_SDK_VERSION + "\n",
      "    schema_url       : https://opentelemetry.io/schemas/1.15.0\n",
      "    attributes       : \n",
      "      scope.attr.key: scope.attr.value\n",
      "}\n"};

  std::string ostream_output = stdcerrOutput.str();
  for (auto &expected : expected_output)
  {
    std::string::size_type result = ostream_output.find(expected);
    if (result == std::string::npos)
    {
      std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n';
    }
    ASSERT_NE(result, std::string::npos);
  }
}

// ---------------------------------- Print to clog -------------------------

// Testing what a log record with only the "resource", and "attributes" fields
// (i.e. KeyValueIterable types), set with 2D arrays as values, will print out
TEST(OStreamLogRecordExporter, LogWithVariantTypesToClog)
{

  // Initialize an Ostream exporter to cerr
  auto exporter = std::unique_ptr<sdklogs::LogRecordExporter>(
      new exporterlogs::OStreamLogRecordExporter(std::clog));

  // Save original stream buffer, then redirect cout to our new stream buffer
  std::streambuf *original = std::clog.rdbuf();
  std::stringstream stdclogOutput;
  std::clog.rdbuf(stdclogOutput.rdbuf());

  // Pass a recordable created by the exporter to be exported
  auto record = exporter->MakeRecordable();

  // Set resources for this log record of only integer types as the value
  std::array<int, 3> array1 = {1, 2, 3};
  nostd::span<int> data1{array1.data(), array1.size()};

  auto resource = opentelemetry::sdk::resource::Resource::Create({{"res1", data1}});
  static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetResource(resource);

  // Set resources for this log record of bool types as the value
  // e.g. key/value is a par of type <string, array of bools>
  std::array<bool, 3> array = {false, true, false};
  static_cast<sdklogs::ReadWriteLogRecord *>(record.get())
      ->SetAttribute("attr1", nostd::span<bool>{array.data(), array.size()});

  opentelemetry::sdk::instrumentationscope::InstrumentationScope instrumentation_scope =
      GetTestInstrumentationScope();
  record->SetInstrumentationScope(instrumentation_scope);

  // Log a record to clog
  exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&record, 1));

  // Reset clog's original stringstream buffer
  std::clog.rdbuf(original);

  std::vector<std::string> expected_output{
      "{\n",
      "  timestamp          : 0\n",
      "  severity_num       : 0\n",
      "  severity_text      : INVALID\n",
      "  body               : \n",
      "  resource           : \n",
      "    service.name: unknown_service\n",
      std::string{"    telemetry.sdk.version: "} + OPENTELEMETRY_SDK_VERSION + "\n",
      "    telemetry.sdk.name: opentelemetry\n",
      "    telemetry.sdk.language: cpp\n",
      "    res1: [1,2,3]\n",
      "  attributes         : \n",
      "    attr1: [0,1,0]\n",
      "  event_id           : 0\n",
      "  event_name         : \n",
      "  trace_id           : 00000000000000000000000000000000\n",
      "  span_id            : 0000000000000000\n",
      "  trace_flags        : 00\n",
      "  scope              : \n",
      "    name             : otel-cpp\n",
      std::string{"    version          : "} + OPENTELEMETRY_SDK_VERSION + "\n",
      "    schema_url       : https://opentelemetry.io/schemas/1.15.0\n",
      "    attributes       : \n",
      "      scope.attr.key: scope.attr.value\n",
      "}\n"};

  std::string ostream_output = stdclogOutput.str();
  for (auto &expected : expected_output)
  {
    std::string::size_type result = ostream_output.find(expected);
    if (result == std::string::npos)
    {
      std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n';
    }
    ASSERT_NE(result, std::string::npos);
  }
}

// // ---------------------------------- Integration Tests -------------------------

// Test using the simple log processor and ostream exporter to cout
// and use the rest of the logging pipeline (Logger, LoggerProvider, Provider) as well
TEST(OStreamLogRecordExporter, IntegrationTest)
{
  // Initialize a logger
  auto exporter =
      std::unique_ptr<sdklogs::LogRecordExporter>(new exporterlogs::OStreamLogRecordExporter);
  auto sdkProvider = std::shared_ptr<sdklogs::LoggerProvider>(new sdklogs::LoggerProvider());
  sdkProvider->AddProcessor(std::unique_ptr<sdklogs::LogRecordProcessor>(
      new sdklogs::SimpleLogRecordProcessor(std::move(exporter))));
  auto apiProvider = nostd::shared_ptr<logs_api::LoggerProvider>(sdkProvider);
  auto provider    = nostd::shared_ptr<logs_api::LoggerProvider>(apiProvider);
  sdklogs::Provider::SetLoggerProvider(provider);
  const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"};
  auto logger = logs_api::Provider::GetLoggerProvider()->GetLogger(
      "Logger", "opentelelemtry_library", OPENTELEMETRY_SDK_VERSION, schema_url,
      {{"scope.attr.key", 123}});

  // Back up cout's streambuf
  std::streambuf *original = std::cout.rdbuf();

  // Redirect cout to our string stream
  std::stringstream stdcoutOutput;
  std::cout.rdbuf(stdcoutOutput.rdbuf());

  // Write a log to ostream exporter
  common::SystemTimestamp now(std::chrono::system_clock::now());
  logger->EmitLogRecord(logs_api::Severity::kDebug, "Hello", now);

  // Restore cout's original streambuf
  std::cout.rdbuf(original);

  // Compare actual vs expected outputs
  std::vector<std::string> expected_output{
      "{\n",
      "  timestamp          : " + std::to_string(now.time_since_epoch().count()) + "\n",
      "  severity_num       : 5\n",
      "  severity_text      : DEBUG\n",
      "  body               : Hello\n",
      "  resource           : \n",
      std::string{"    telemetry.sdk.version: "} + OPENTELEMETRY_SDK_VERSION + "\n",
      "    service.name: unknown_service\n",
      "    telemetry.sdk.name: opentelemetry\n",
      "    telemetry.sdk.language: cpp\n",
      "  attributes         : \n",
      "  event_id           : 0\n",
      "  event_name         : \n",
      "  trace_id           : 00000000000000000000000000000000\n",
      "  span_id            : 0000000000000000\n",
      "  trace_flags        : 00\n",
      "  scope              : \n",
      "    name             : opentelelemtry_library\n",
      std::string{"    version          : "} + OPENTELEMETRY_SDK_VERSION + "\n",
      "    schema_url       : https://opentelemetry.io/schemas/1.11.0\n",
      "    attributes       : \n",
      "      scope.attr.key: 123\n",
      "}\n"};

  std::string ostream_output = stdcoutOutput.str();
  for (auto &expected : expected_output)
  {
    std::string::size_type result = ostream_output.find(expected);
    if (result == std::string::npos)
    {
      std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n';
    }
    ASSERT_NE(result, std::string::npos);
  }
}

// Test using the simple log processor and ostream exporter to cout
// and use the rest of the logging pipeline (Logger, LoggerProvider, Provider) and user-facing API
// as well
TEST(OStreamLogRecordExporter, IntegrationTestWithEventId)
{
  // Initialize a logger
  auto exporter =
      std::unique_ptr<sdklogs::LogRecordExporter>(new exporterlogs::OStreamLogRecordExporter);
  auto sdkProvider = std::shared_ptr<sdklogs::LoggerProvider>(new sdklogs::LoggerProvider());
  sdkProvider->AddProcessor(std::unique_ptr<sdklogs::LogRecordProcessor>(
      new sdklogs::SimpleLogRecordProcessor(std::move(exporter))));
  auto apiProvider = nostd::shared_ptr<logs_api::LoggerProvider>(sdkProvider);
  auto provider    = nostd::shared_ptr<logs_api::LoggerProvider>(apiProvider);
  sdklogs::Provider::SetLoggerProvider(provider);
  const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"};
  auto logger = logs_api::Provider::GetLoggerProvider()->GetLogger(
      "Logger", "opentelelemtry_library", OPENTELEMETRY_SDK_VERSION, schema_url,
      {{"scope.attr.key", 123}});

  // Back up cout's streambuf
  std::streambuf *original = std::cout.rdbuf();

  // Redirect cout to our string stream
  std::stringstream stdcoutOutput;
  std::cout.rdbuf(stdcoutOutput.rdbuf());

  logs_api::EventId event_id{12345678, "test_event_id"};

  // Write a log to ostream exporter
  logger->Debug(event_id, "Hello {key1} {key2}",
                common::MakeKeyValueIterableView<Attributes>({{"key1", 123}, {"key2", "value2"}}));

  // Restore cout's original streambuf
  std::cout.rdbuf(original);

  // Compare actual vs expected outputs
  std::vector<std::string> expected_output{
      "  severity_num       : 5\n",
      "  severity_text      : DEBUG\n",
      "  body               : Hello {key1} {key2}\n",
      "  resource           : \n",
      std::string{"    telemetry.sdk.version: "} + OPENTELEMETRY_SDK_VERSION + "\n",
      "    service.name: unknown_service\n",
      "    telemetry.sdk.name: opentelemetry\n",
      "    telemetry.sdk.language: cpp\n",
      "  attributes         : \n",
      "  event_id           : 12345678\n",
      "  event_name         : test_event_id\n",
      "  trace_id           : 00000000000000000000000000000000\n",
      "  span_id            : 0000000000000000\n",
      "  trace_flags        : 00\n",
      "  scope              : \n",
      "    name             : opentelelemtry_library\n",
      std::string{"    version          : "} + OPENTELEMETRY_SDK_VERSION + "\n",
      "    schema_url       : https://opentelemetry.io/schemas/1.11.0\n",
      "    attributes       : \n",
      "      scope.attr.key: 123\n",
      "}\n"};

  std::string ostream_output = stdcoutOutput.str();
  for (auto &expected : expected_output)
  {
    std::string::size_type result = ostream_output.find(expected);
    if (result == std::string::npos)
    {
      std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n';
    }
    ASSERT_NE(result, std::string::npos);
  }
}

// Test using the factory to create the ostream exporter
TEST(OStreamLogRecordExporter, Factory)
{
  auto exporter = OStreamLogRecordExporterFactory::Create();
  ASSERT_NE(exporter, nullptr);
}

}  // namespace logs
}  // namespace exporter
OPENTELEMETRY_END_NAMESPACE