Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OStreamLogRecordExporterFactory #2240

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions exporters/ostream/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ cc_library(
name = "ostream_log_record_exporter",
srcs = [
"src/log_record_exporter.cc",
"src/log_record_exporter_factory.cc",
],
hdrs = [
"include/opentelemetry/exporters/ostream/common_utils.h",
"include/opentelemetry/exporters/ostream/log_record_exporter.h",
"include/opentelemetry/exporters/ostream/log_record_exporter_factory.h",
],
strip_include_prefix = "include",
tags = ["ostream"],
Expand Down
12 changes: 7 additions & 5 deletions exporters/ostream/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if(OPENTELEMETRY_INSTALL)
DIRECTORY include/opentelemetry/exporters/ostream
DESTINATION include/opentelemetry/exporters
PATTERN "*.h"
PATTERN "log_Exporter.h" EXCLUDE)
PATTERN "log_record_exporter.h" EXCLUDE)
lalitb marked this conversation as resolved.
Show resolved Hide resolved
endif()

if(BUILD_TESTING)
Expand Down Expand Up @@ -77,7 +77,8 @@ if(BUILD_TESTING)
endif()

if(WITH_LOGS_PREVIEW)
add_library(opentelemetry_exporter_ostream_logs src/log_record_exporter.cc)
add_library(opentelemetry_exporter_ostream_logs
src/log_record_exporter.cc src/log_record_exporter_factory.cc)
set_target_properties(opentelemetry_exporter_ostream_logs
PROPERTIES EXPORT_NAME ostream_log_record_exporter)
set_target_version(opentelemetry_exporter_ostream_logs)
Expand All @@ -96,9 +97,10 @@ if(WITH_LOGS_PREVIEW)
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(
DIRECTORY include/opentelemetry/exporters/ostream
DESTINATION include/opentelemetry/exporters
PATTERN "log_record_exporter.h")
FILES
"include/opentelemetry/exporters/ostream/log_record_exporter.h"
"include/opentelemetry/exporters/ostream/log_record_exporter_factory.h"
DESTINATION include/opentelemetry/exporters/ostream)
endif()

if(BUILD_TESTING)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#ifdef ENABLE_LOGS_PREVIEW
# include <iostream>
# include <memory>

# include "opentelemetry/sdk/version/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace logs
{
class LogRecordExporter;
} // namespace logs
} // namespace sdk

namespace exporter
{
namespace logs
{

/**
* Factory class for OStreamLogRecordExporter.
*/
class OPENTELEMETRY_EXPORT OStreamLogRecordExporterFactory
{
public:
/**
* Creates an OStreamLogRecordExporter writing to the default location.
*/
static std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create();

/**
* Creates an OStreamLogRecordExporter writing to the given location.
*/
static std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create(std::ostream &sout);
};

} // namespace logs
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
#endif
31 changes: 31 additions & 0 deletions exporters/ostream/src/log_record_exporter_factory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#ifdef ENABLE_LOGS_PREVIEW
# include "opentelemetry/exporters/ostream/log_record_exporter_factory.h"
# include "opentelemetry/exporters/ostream/log_record_exporter.h"

namespace logs_sdk = opentelemetry::sdk::logs;

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace logs
{

std::unique_ptr<logs_sdk::LogRecordExporter> OStreamLogRecordExporterFactory::Create()
{
return Create(std::cout);
}

std::unique_ptr<logs_sdk::LogRecordExporter> OStreamLogRecordExporterFactory::Create(
std::ostream &sout)
{
std::unique_ptr<logs_sdk::LogRecordExporter> exporter(new OStreamLogRecordExporter(sout));
return exporter;
}

} // namespace logs
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
#endif
8 changes: 8 additions & 0 deletions exporters/ostream/test/ostream_log_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifdef ENABLE_LOGS_PREVIEW

# include "opentelemetry/exporters/ostream/log_record_exporter.h"
# include "opentelemetry/exporters/ostream/log_record_exporter_factory.h"
# include "opentelemetry/logs/provider.h"
# include "opentelemetry/nostd/span.h"
# include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
Expand Down Expand Up @@ -507,6 +508,13 @@ TEST(OStreamLogRecordExporter, IntegrationTestWithEventId)
}
}

// 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
Expand Down