Skip to content

Commit

Permalink
Rename InstrumentationLibrary -> InstrumentationScope
Browse files Browse the repository at this point in the history
Signed-off-by: owentou <[email protected]>
  • Loading branch information
owent committed Jul 22, 2022
1 parent 09092cd commit 2e6ad6f
Show file tree
Hide file tree
Showing 59 changed files with 476 additions and 366 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Increment the:
* [EXT] `curl::HttpClient` use `curl_multi_handle` instead of creating a thread
for every request and it's able to reuse connections now. ([#1317](https:/open-telemetry/opentelemetry-cpp/pull/1317))
* [SEMANTIC CONVENTIONS] Upgrade to version 1.12.0 [#873](https:/open-telemetry/opentelemetry-cpp/pull/873)
* [SDK] Rename `InstrumentationLibrary` to `InstrumentationScope` [#1507](https:/open-telemetry/opentelemetry-cpp/pull/1507)

## [1.4.1] 2022-06-19

Expand Down
1 change: 1 addition & 0 deletions docs/public/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ INPUT = \
../../api/include/opentelemetry/nostd/unique_ptr.h \
../../api/include/opentelemetry/nostd/variant.h \
../../api/include/opentelemetry/trace \
../../sdk/include/opentelemetry/sdk/instrumentationscope \
../../sdk/include/opentelemetry/sdk/instrumentationlibrary \
../../sdk/include/opentelemetry/sdk/resource \
../../sdk/include/opentelemetry/sdk/trace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# include <unordered_map>

# include "nlohmann/json.hpp"
# include "opentelemetry/common/macros.h"
# include "opentelemetry/sdk/common/attribute_utils.h"
# include "opentelemetry/sdk/logs/recordable.h"
# include "opentelemetry/version.h"
Expand Down Expand Up @@ -201,27 +202,42 @@ class ElasticSearchRecordable final : public sdk::logs::Recordable
nlohmann::json GetJSON() noexcept { return json_; }

/**
* Set instrumentation_library for this log.
* @param instrumentation_library the instrumentation library to set
* Set instrumentation_scope for this log.
* @param instrumentation_scopehe instrumentation library to set
*/
void SetInstrumentationScope(const opentelemetry::sdk::instrumentationscope::InstrumentationScope
&instrumentation_scope) noexcept
{
json_["name"] = instrumentation_scope.GetName();
instrumentation_scope_ = &instrumentation_scope;
}

OPENTELEMETRY_DEPRECATED_MESSAGE("Please use SetInstrumentationScope instead")
void SetInstrumentationLibrary(
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
&instrumentation_library) noexcept
const opentelemetry::sdk::instrumentationscope::InstrumentationScope
&instrumentation_scope) noexcept
{
SetInstrumentationScope(instrumentation_scope);
}

/** Returns the associated instruementation library */
OPENTELEMETRY_DEPRECATED_MESSAGE("Please use GetInstrumentationScope instead")
const opentelemetry::sdk::instrumentationscope::InstrumentationScope &GetInstrumentationLibrary()
const noexcept
{
json_["name"] = instrumentation_library.GetName();
instrumentation_library_ = &instrumentation_library;
return GetInstrumentationScope();
}

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

private:
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
*instrumentation_library_ = nullptr;
const opentelemetry::sdk::instrumentationscope::InstrumentationScope *instrumentation_scope_ =
nullptr;
};
} // namespace logs
} // namespace exporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ class JaegerRecordable final : public sdk::trace::Recordable

void SetDuration(std::chrono::nanoseconds duration) noexcept override;

void SetInstrumentationLibrary(
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
&instrumentation_library) noexcept override;
void SetInstrumentationScope(const opentelemetry::sdk::instrumentationscope::InstrumentationScope
&instrumentation_scope) noexcept override;

private:
void AddTag(const std::string &key, const std::string &value, std::vector<thrift::Tag> &tags);
Expand Down
10 changes: 5 additions & 5 deletions exporters/jaeger/src/recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ void JaegerRecordable::AddEvent(nostd::string_view name,
logs_.push_back(log);
}

void JaegerRecordable::SetInstrumentationLibrary(
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
&instrumentation_library) noexcept
void JaegerRecordable::SetInstrumentationScope(
const opentelemetry::sdk::instrumentationscope::InstrumentationScope
&instrumentation_scope) noexcept
{
AddTag("otel.library.name", instrumentation_library.GetName(), tags_);
AddTag("otel.library.version", instrumentation_library.GetVersion(), tags_);
AddTag("otel.library.name", instrumentation_scope.GetName(), tags_);
AddTag("otel.library.version", instrumentation_scope.GetVersion(), tags_);
}

void JaegerRecordable::AddLink(const trace::SpanContext &span_context,
Expand Down
14 changes: 7 additions & 7 deletions exporters/jaeger/test/jaeger_recordable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <vector>
#include "opentelemetry/exporters/jaeger/recordable.h"
#include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h"
#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
#include "opentelemetry/sdk/trace/simple_processor.h"
#include "opentelemetry/sdk/trace/span_data.h"
#include "opentelemetry/sdk/trace/tracer_provider.h"
Expand All @@ -18,7 +18,7 @@ namespace common = opentelemetry::common;

using namespace jaegertracing;
using namespace opentelemetry::exporter::jaeger;
using namespace opentelemetry::sdk::instrumentationlibrary;
using namespace opentelemetry::sdk::instrumentationscope;
using std::vector;

using Attributes = std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>;
Expand Down Expand Up @@ -247,15 +247,15 @@ TEST(JaegerSpanRecordable, SetAttributes)
EXPECT_EQ(tags, expected_tags);
}

TEST(JaegerSpanRecordable, SetInstrumentationLibrary)
TEST(JaegerSpanRecordable, SetInstrumentationScope)
{
JaegerRecordable rec;

std::string library_name = "opentelemetry-cpp";
std::string library_version = "0.1.0";
auto instrumentation_library = InstrumentationLibrary::Create(library_name, library_version);
std::string library_name = "opentelemetry-cpp";
std::string library_version = "0.1.0";
auto instrumentation_scope = InstrumentationScope::Create(library_name, library_version);

rec.SetInstrumentationLibrary(*instrumentation_library);
rec.SetInstrumentationScope(*instrumentation_scope);

auto tags = rec.Tags();
EXPECT_EQ(tags.size(), 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ class OStreamSpanExporter final : public opentelemetry::sdk::trace::SpanExporter

void printResources(const opentelemetry::sdk::resource::Resource &resources);

void printInstrumentationLibrary(
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
&instrumentation_library);
void printInstrumentationScope(
const opentelemetry::sdk::instrumentationscope::InstrumentationScope &instrumentation_scope);
};
} // namespace trace
} // namespace exporter
Expand Down
11 changes: 5 additions & 6 deletions exporters/ostream/src/span_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ sdk::common::ExportResult OStreamSpanExporter::Export(
sout_ << "\n resources : ";
printResources(span->GetResource());
sout_ << "\n instr-lib : ";
printInstrumentationLibrary(span->GetInstrumentationLibrary());
printInstrumentationScope(span->GetInstrumentationScope());
sout_ << "\n}\n";
}
}
Expand Down Expand Up @@ -161,12 +161,11 @@ void OStreamSpanExporter::printResources(const opentelemetry::sdk::resource::Res
}
}

void OStreamSpanExporter::printInstrumentationLibrary(
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
&instrumentation_library)
void OStreamSpanExporter::printInstrumentationScope(
const opentelemetry::sdk::instrumentationscope::InstrumentationScope &instrumentation_scope)
{
sout_ << instrumentation_library.GetName();
auto version = instrumentation_library.GetVersion();
sout_ << instrumentation_scope.GetName();
auto version = instrumentation_scope.GetVersion();
if (version.size())
{
sout_ << "-" << version;
Expand Down
8 changes: 4 additions & 4 deletions exporters/ostream/test/ostream_metric_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ TEST(OStreamMetricsExporter, ExportSumPointData)
auto resource = opentelemetry::sdk::resource::Resource::Create(
opentelemetry::sdk::resource::ResourceAttributes{});
data.resource_ = &resource;
auto scope = opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary::Create(
auto scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create(
"library_name", "1.2.0");
metric_sdk::MetricData metric_data{
metric_sdk::InstrumentDescriptor{"library_name", "description", "unit",
Expand Down Expand Up @@ -104,7 +104,7 @@ TEST(OStreamMetricsExporter, ExportHistogramPointData)
auto resource = opentelemetry::sdk::resource::Resource::Create(
opentelemetry::sdk::resource::ResourceAttributes{});
data.resource_ = &resource;
auto scope = opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary::Create(
auto scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create(
"library_name", "1.2.0");
metric_sdk::MetricData metric_data{
metric_sdk::InstrumentDescriptor{"library_name", "description", "unit",
Expand Down Expand Up @@ -164,7 +164,7 @@ TEST(OStreamMetricsExporter, ExportLastValuePointData)
auto resource = opentelemetry::sdk::resource::Resource::Create(
opentelemetry::sdk::resource::ResourceAttributes{});
data.resource_ = &resource;
auto scope = opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary::Create(
auto scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create(
"library_name", "1.2.0");
metric_sdk::LastValuePointData last_value_point_data{};
last_value_point_data.value_ = 10.0;
Expand Down Expand Up @@ -227,7 +227,7 @@ TEST(OStreamMetricsExporter, ExportDropPointData)
auto resource = opentelemetry::sdk::resource::Resource::Create(
opentelemetry::sdk::resource::ResourceAttributes{});
data.resource_ = &resource;
auto scope = opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary::Create(
auto scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create(
"library_name", "1.2.0");
metric_sdk::DropPointData drop_point_data{};
metric_sdk::DropPointData drop_point_data2{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

# include "opentelemetry/proto/logs/v1/logs.pb.h"
# include "opentelemetry/proto/resource/v1/resource.pb.h"
# include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h"
# include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"

# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h"
// clang-format on

# include "opentelemetry/common/macros.h"
# include "opentelemetry/sdk/common/attribute_utils.h"
# include "opentelemetry/sdk/logs/recordable.h"

Expand Down Expand Up @@ -91,24 +92,30 @@ class OtlpLogRecordable final : public opentelemetry::sdk::logs::Recordable
void SetTraceFlags(opentelemetry::trace::TraceFlags trace_flags) noexcept override;

/**
* Set instrumentation_library for this log.
* @param instrumentation_library the instrumentation library to set
* Set instrumentation_scope for this log.
* @param instrumentation_scopehe instrumentation library to set
*/
void SetInstrumentationLibrary(
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
&instrumentation_library) noexcept override;
void SetInstrumentationScope(const opentelemetry::sdk::instrumentationscope::InstrumentationScope
&instrumentation_scope) noexcept override;

OPENTELEMETRY_DEPRECATED_MESSAGE("Please use GetInstrumentationScope instead")
const opentelemetry::sdk::instrumentationscope::InstrumentationScope &GetInstrumentationLibrary()
const noexcept
{
return GetInstrumentationScope();
}

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

private:
proto::logs::v1::LogRecord log_record_;
const opentelemetry::sdk::resource::Resource *resource_ = nullptr;
// TODO shared resource
// const opentelemetry::sdk::resource::Resource *resource_ = nullptr;
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
*instrumentation_library_ = nullptr;
const opentelemetry::sdk::instrumentationscope::InstrumentationScope *instrumentation_scope_ =
nullptr;
};

} // namespace otlp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ class OtlpRecordable final : public opentelemetry::sdk::trace::Recordable

void SetDuration(std::chrono::nanoseconds duration) noexcept override;

void SetInstrumentationLibrary(
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
&instrumentation_library) noexcept override;
void SetInstrumentationScope(
const opentelemetry::sdk::instrumentationscope::InstrumentationScope
&instrumentation_scope) noexcept override;

private:
proto::trace::v1::Span span_;
const opentelemetry::sdk::resource::Resource *resource_ = nullptr;
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
*instrumentation_library_ = nullptr;
const opentelemetry::sdk::instrumentationscope::InstrumentationScope *instrumentation_scope_ =
nullptr;
};
} // namespace otlp
} // namespace exporter
Expand Down
18 changes: 9 additions & 9 deletions exporters/otlp/src/otlp_log_recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,22 @@ void OtlpLogRecordable::SetTraceFlags(opentelemetry::trace::TraceFlags trace_fla
log_record_.set_flags(trace_flags.flags());
}

void OtlpLogRecordable::SetInstrumentationLibrary(
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
&instrumentation_library) noexcept
void OtlpLogRecordable::SetInstrumentationScope(
const opentelemetry::sdk::instrumentationscope::InstrumentationScope
&instrumentation_scope) noexcept
{
instrumentation_library_ = &instrumentation_library;
instrumentation_scope_ = &instrumentation_scope;
}

const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary &
OtlpLogRecordable::GetInstrumentationLibrary() const noexcept
const opentelemetry::sdk::instrumentationscope::InstrumentationScope &
OtlpLogRecordable::GetInstrumentationScope() const noexcept
{
OPENTELEMETRY_LIKELY_IF(nullptr != instrumentation_library_) { return *instrumentation_library_; }
OPENTELEMETRY_LIKELY_IF(nullptr != instrumentation_scope_) { return *instrumentation_scope_; }

static opentelemetry::nostd::unique_ptr<
opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary>
opentelemetry::sdk::instrumentationscope::InstrumentationScope>
default_instrumentation =
opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary::Create(
opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create(
"default", "1.0.0", "https://opentelemetry.io/schemas/1.11.0");
return *default_instrumentation;
}
Expand Down
18 changes: 9 additions & 9 deletions exporters/otlp/src/otlp_recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ const std::string OtlpRecordable::GetResourceSchemaURL() const noexcept
const std::string OtlpRecordable::GetInstrumentationLibrarySchemaURL() const noexcept
{
std::string schema_url;
if (instrumentation_library_)
if (instrumentation_scope_)
{
schema_url = instrumentation_library_->GetSchemaURL();
schema_url = instrumentation_scope_->GetSchemaURL();
}

return schema_url;
Expand All @@ -66,10 +66,10 @@ proto::common::v1::InstrumentationScope OtlpRecordable::GetProtoInstrumentationS
const noexcept
{
proto::common::v1::InstrumentationScope instrumentation_scope;
if (instrumentation_library_)
if (instrumentation_scope_)
{
instrumentation_scope.set_name(instrumentation_library_->GetName());
instrumentation_scope.set_version(instrumentation_library_->GetVersion());
instrumentation_scope.set_name(instrumentation_scope_->GetName());
instrumentation_scope.set_version(instrumentation_scope_->GetVersion());
}
return instrumentation_scope;
}
Expand Down Expand Up @@ -176,11 +176,11 @@ void OtlpRecordable::SetDuration(std::chrono::nanoseconds duration) noexcept
span_.set_end_time_unix_nano(unix_end_time);
}

void OtlpRecordable::SetInstrumentationLibrary(
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
&instrumentation_library) noexcept
void OtlpRecordable::SetInstrumentationScope(
const opentelemetry::sdk::instrumentationscope::InstrumentationScope
&instrumentation_scope) noexcept
{
instrumentation_library_ = &instrumentation_library;
instrumentation_scope_ = &instrumentation_scope;
}

} // namespace otlp
Expand Down
Loading

0 comments on commit 2e6ad6f

Please sign in to comment.