Skip to content

Commit

Permalink
otlp_log_recordable test
Browse files Browse the repository at this point in the history
  • Loading branch information
esigo committed Dec 10, 2021
1 parent f398951 commit d77e4c5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ class ElasticSearchRecordable final : public sdk::logs::Recordable
instrumentation_library_ = &instrumentation_library;
}

/** Returns the associated instruementation library */
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary &
GetInstrumentationLibrary() const noexcept
{
return *instrumentation_library_;
}

private:
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
*instrumentation_library_ = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,17 @@ class OtlpLogRecordable final : public opentelemetry::sdk::logs::Recordable
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
&instrumentation_library) noexcept override;

/** Returns the associated instruementation library */
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary &
GetInstrumentationLibrary() const noexcept;

private:
proto::logs::v1::LogRecord log_record_;
opentelemetry::sdk::common::AttributeMap resource_attributes_;
// TODO shared resource
// const opentelemetry::sdk::resource::Resource *resource_ = nullptr;
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
*instrumentation_library_ = nullptr;

};

} // namespace otlp
Expand Down
5 changes: 5 additions & 0 deletions exporters/otlp/src/otlp_log_recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ void OtlpLogRecordable::SetInstrumentationLibrary(
instrumentation_library_ = &instrumentation_library;
}

const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary &
OtlpLogRecordable::GetInstrumentationLibrary() const noexcept
{
return *instrumentation_library_;
}
} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
Expand Down
9 changes: 9 additions & 0 deletions exporters/otlp/test/otlp_log_recordable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ TEST(OtlpLogRecordable, SetArrayAttribute)
}
}

TEST(OtlpLogRecordable, SetInstrumentationLibrary)
{
OtlpLogRecordable rec;
auto inst_lib =
opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary::Create("test", "v1");
rec.SetInstrumentationLibrary(*inst_lib);
EXPECT_EQ(rec.GetInstrumentationLibrary(), *inst_lib);
}

/**
* AttributeValue can contain different int types, such as int, int64_t,
* unsigned int, and uint64_t. To avoid writing test cases for each, we can
Expand Down
4 changes: 4 additions & 0 deletions sdk/include/opentelemetry/sdk/logs/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class Logger final : public opentelemetry::logs::Logger
opentelemetry::trace::TraceFlags trace_flags,
opentelemetry::common::SystemTimestamp timestamp) noexcept override;

/** Returns the associated instruementation library */
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary &
GetInstrumentationLibrary() const noexcept;

private:
// The name of this logger
std::string logger_name_;
Expand Down
6 changes: 6 additions & 0 deletions sdk/src/logs/logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ void Logger::Log(opentelemetry::logs::Severity severity,
processor->OnReceive(std::move(recordable));
}

const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary &
Logger::GetInstrumentationLibrary() const noexcept
{
return *instrumentation_library_;
}

} // namespace logs
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
Expand Down

0 comments on commit d77e4c5

Please sign in to comment.