Skip to content

Commit

Permalink
Fix log sdk builder (open-telemetry#1486)
Browse files Browse the repository at this point in the history
Implemented code review comments.

Fixed typo (processor -> processors)
in TracerContextFactory
  • Loading branch information
marcalff committed Jul 29, 2022
1 parent 5996d8d commit 6e2cc90
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 13 deletions.
1 change: 0 additions & 1 deletion exporters/otlp/src/otlp_grpc_log_exporter_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

# include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h"
# include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h"
# include "opentelemetry/sdk/common/global_log_handler.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
Expand Down
43 changes: 43 additions & 0 deletions sdk/include/opentelemetry/sdk/logs/logger_context_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#ifdef ENABLE_LOGS_PREVIEW

# include "opentelemetry/sdk/logs/logger_context.h"
# include "opentelemetry/sdk/logs/processor.h"
# include "opentelemetry/sdk/resource/resource.h"
# include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace logs
{

/**
* Factory class for LoggerContext.
*/
class LoggerContextFactory
{
public:
/**
* Create a LoggerContext.
*/
static std::unique_ptr<LoggerContext> Create(
std::vector<std::unique_ptr<LogProcessor>> &&processors);

/**
* Create a LoggerContext.
*/
static std::unique_ptr<LoggerContext> Create(
std::vector<std::unique_ptr<LogProcessor>> &&processors,
const opentelemetry::sdk::resource::Resource &resource);
};

} // namespace logs
} // namespace sdk

OPENTELEMETRY_END_NAMESPACE
#endif
8 changes: 4 additions & 4 deletions sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ class TracerContextFactory
* Create a TracerContext.
*/
static std::unique_ptr<TracerContext> Create(
std::vector<std::unique_ptr<SpanProcessor>> &&processor);
std::vector<std::unique_ptr<SpanProcessor>> &&processors);

/**
* Create a TracerContext.
*/
static std::unique_ptr<TracerContext> Create(
std::vector<std::unique_ptr<SpanProcessor>> &&processor,
std::vector<std::unique_ptr<SpanProcessor>> &&processors,
const opentelemetry::sdk::resource::Resource &resource);

/**
* Create a TracerContext.
*/
static std::unique_ptr<TracerContext> Create(
std::vector<std::unique_ptr<SpanProcessor>> &&processor,
std::vector<std::unique_ptr<SpanProcessor>> &&processors,
const opentelemetry::sdk::resource::Resource &resource,
std::unique_ptr<Sampler> sampler);

/**
* Create a TracerContext.
*/
static std::unique_ptr<TracerContext> Create(
std::vector<std::unique_ptr<SpanProcessor>> &&processor,
std::vector<std::unique_ptr<SpanProcessor>> &&processors,
const opentelemetry::sdk::resource::Resource &resource,
std::unique_ptr<Sampler> sampler,
std::unique_ptr<IdGenerator> id_generator);
Expand Down
1 change: 1 addition & 0 deletions sdk/src/logs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_library(
batch_log_processor.cc
batch_log_processor_factory.cc
logger_context.cc
logger_context_factory.cc
multi_log_processor.cc
multi_log_processor_factory.cc
multi_recordable.cc)
Expand Down
36 changes: 36 additions & 0 deletions sdk/src/logs/logger_context_factory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#ifdef ENABLE_LOGS_PREVIEW

# include "opentelemetry/sdk/logs/logger_context_factory.h"

# include <memory>
# include <vector>

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace logs
{

std::unique_ptr<LoggerContext> LoggerContextFactory::Create(
std::vector<std::unique_ptr<LogProcessor>> &&processors)
{
auto resource = opentelemetry::sdk::resource::Resource::Create({});
return Create(std::move(processors), resource);
}

std::unique_ptr<LoggerContext> LoggerContextFactory::Create(
std::vector<std::unique_ptr<LogProcessor>> &&processors,
const opentelemetry::sdk::resource::Resource &resource)
{
std::unique_ptr<LoggerContext> context(new LoggerContext(std::move(processors), resource));
return context;
}

} // namespace logs
} // namespace sdk

OPENTELEMETRY_END_NAMESPACE
#endif
16 changes: 8 additions & 8 deletions sdk/src/trace/tracer_context_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ namespace trace
{

std::unique_ptr<TracerContext> TracerContextFactory::Create(
std::vector<std::unique_ptr<SpanProcessor>> &&processor)
std::vector<std::unique_ptr<SpanProcessor>> &&processors)
{
auto resource = opentelemetry::sdk::resource::Resource::Create({});
return Create(std::move(processor), resource);
return Create(std::move(processors), resource);
}

std::unique_ptr<TracerContext> TracerContextFactory::Create(
std::vector<std::unique_ptr<SpanProcessor>> &&processor,
std::vector<std::unique_ptr<SpanProcessor>> &&processors,
const opentelemetry::sdk::resource::Resource &resource)
{
auto sampler = AlwaysOnSamplerFactory::Create();
return Create(std::move(processor), resource, std::move(sampler));
return Create(std::move(processors), resource, std::move(sampler));
}

std::unique_ptr<TracerContext> TracerContextFactory::Create(
std::vector<std::unique_ptr<SpanProcessor>> &&processor,
std::vector<std::unique_ptr<SpanProcessor>> &&processors,
const opentelemetry::sdk::resource::Resource &resource,
std::unique_ptr<Sampler> sampler)
{
auto id_generator = RandomIdGeneratorFactory::Create();
return Create(std::move(processor), resource, std::move(sampler), std::move(id_generator));
return Create(std::move(processors), resource, std::move(sampler), std::move(id_generator));
}

std::unique_ptr<TracerContext> TracerContextFactory::Create(
std::vector<std::unique_ptr<SpanProcessor>> &&processor,
std::vector<std::unique_ptr<SpanProcessor>> &&processors,
const opentelemetry::sdk::resource::Resource &resource,
std::unique_ptr<Sampler> sampler,
std::unique_ptr<IdGenerator> id_generator)
{
std::unique_ptr<TracerContext> context(new TracerContext(
std::move(processor), resource, std::move(sampler), std::move(id_generator)));
std::move(processors), resource, std::move(sampler), std::move(id_generator)));
return context;
}

Expand Down

0 comments on commit 6e2cc90

Please sign in to comment.