Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ Increment the:
the API `SpinLockMutex` and all other SDK locks are unchanged.
[#4245](https://github.com/open-telemetry/opentelemetry-cpp/pull/4245)

* [SDK] Create instrumentation scope library
[#4351](https://github.com/open-telemetry/opentelemetry-cpp/pull/4351)

* [CONFIGURATION] Update ViewSelector to comply with schema v1.1.0
[#4384](https://github.com/open-telemetry/opentelemetry-cpp/pull/4384)

Expand Down
1 change: 1 addition & 0 deletions sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ otel_add_component(
opentelemetry_common
opentelemetry_resources
opentelemetry_version
opentelemetry_instrumentation_scope
opentelemetry_logs
opentelemetry_trace
opentelemetry_metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

#pragma once

#include <cstddef>
#include <string>
#include <type_traits>

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/common/key_value_iterable.h"
#include "opentelemetry/common/key_value_iterable_view.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/type_traits.h"
#include "opentelemetry/nostd/unique_ptr.h"
#include "opentelemetry/nostd/variant.h"
#include "opentelemetry/nostd/utility.h"
#include "opentelemetry/sdk/common/attribute_utils.h"
#include "opentelemetry/version.h"

Expand Down Expand Up @@ -44,12 +45,7 @@ class InstrumentationScope
nostd::string_view name,
nostd::string_view version = "",
nostd::string_view schema_url = "",
InstrumentationScopeAttributes &&attributes = {})
{
return nostd::unique_ptr<InstrumentationScope>(
new InstrumentationScope{name, version, schema_url, std::move(attributes)});
}

InstrumentationScopeAttributes &&attributes = {});
/**
* Returns a newly created InstrumentationScope with the specified library name and version.
* @param name name of the instrumentation scope.
Expand All @@ -62,11 +58,7 @@ class InstrumentationScope
nostd::string_view name,
nostd::string_view version,
nostd::string_view schema_url,
const InstrumentationScopeAttributes &attributes)
{
return nostd::unique_ptr<InstrumentationScope>(new InstrumentationScope{
name, version, schema_url, InstrumentationScopeAttributes(attributes)});
}
const InstrumentationScopeAttributes &attributes);

/**
* Returns a newly created InstrumentationScope with the specified library name and version.
Expand Down Expand Up @@ -98,18 +90,14 @@ class InstrumentationScope
return result;
}

std::size_t HashCode() const noexcept { return hash_code_; }
std::size_t HashCode() const noexcept;

/**
* Compare 2 instrumentation libraries.
* @param other the instrumentation scope to compare to.
* @returns true if the 2 instrumentation libraries are equal, false otherwise.
*/
bool operator==(const InstrumentationScope &other) const noexcept
{
return this->name_ == other.name_ && this->version_ == other.version_ &&
this->schema_url_ == other.schema_url_ && this->attributes_ == other.attributes_;
}
bool operator==(const InstrumentationScope &other) const noexcept;

/**
* Check whether the instrumentation scope has given name and version.
Expand All @@ -124,52 +112,21 @@ class InstrumentationScope
bool equal(const nostd::string_view name,
const nostd::string_view version,
const nostd::string_view schema_url = "",
const opentelemetry::common::KeyValueIterable *attributes = nullptr) const noexcept
{
const opentelemetry::common::KeyValueIterable *attributes = nullptr) const noexcept;

if (this->name_ != name || this->version_ != version || this->schema_url_ != schema_url)
{
return false;
}

if (attributes == nullptr)
{
if (attributes_.empty())
{
return true;
}
return false;
}

return attributes_.EqualTo(*attributes);
}

const std::string &GetName() const noexcept { return name_; }
const std::string &GetVersion() const noexcept { return version_; }
const std::string &GetSchemaURL() const noexcept { return schema_url_; }
const InstrumentationScopeAttributes &GetAttributes() const noexcept { return attributes_; }
const std::string &GetName() const noexcept;
const std::string &GetVersion() const noexcept;
const std::string &GetSchemaURL() const noexcept;
const InstrumentationScopeAttributes &GetAttributes() const noexcept;

void SetAttribute(nostd::string_view key,
const opentelemetry::common::AttributeValue &value) noexcept
{
attributes_[std::string(key)] =
nostd::visit(opentelemetry::sdk::common::AttributeConverter(), value);
}
const opentelemetry::common::AttributeValue &value) noexcept;

private:
InstrumentationScope(nostd::string_view name,
nostd::string_view version,
nostd::string_view schema_url = "",
InstrumentationScopeAttributes &&attributes = {})
: name_(name), version_(version), schema_url_(schema_url), attributes_(std::move(attributes))
{
std::string hash_data;
hash_data.reserve(name_.size() + version_.size() + schema_url_.size());
hash_data += name_;
hash_data += version_;
hash_data += schema_url_;
hash_code_ = std::hash<std::string>{}(hash_data);
}
InstrumentationScopeAttributes &&attributes = {});

private:
std::string name_;
Expand Down
1 change: 1 addition & 0 deletions sdk/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

add_subdirectory(common)
add_subdirectory(instrumentationscope)
add_subdirectory(trace)
add_subdirectory(metrics)
add_subdirectory(logs)
Expand Down
18 changes: 18 additions & 0 deletions sdk/src/instrumentationscope/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

load("@rules_cc//cc:cc_library.bzl", "cc_library")

package(default_visibility = ["//visibility:public"])

cc_library(
name = "instrumentationscope",
srcs = [
"instrumentation_scope.cc",
],
include_prefix = "src/instrumentationscope",
deps = [
"//api",
"//sdk:headers",
],
)
23 changes: 23 additions & 0 deletions sdk/src/instrumentationscope/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

add_library(opentelemetry_instrumentation_scope instrumentation_scope.cc)

set_target_properties(opentelemetry_instrumentation_scope
PROPERTIES EXPORT_NAME instrumentation_scope)
set_target_version(opentelemetry_instrumentation_scope)

target_include_directories(
opentelemetry_instrumentation_scope
PUBLIC "$<BUILD_INTERFACE:${OTEL_SDK_DIR}>" "$<INSTALL_INTERFACE:include>")

target_link_libraries(opentelemetry_instrumentation_scope
PUBLIC opentelemetry_common)

if(OPENTELEMETRY_INSTALL)
opentelemetry_add_pkgconfig(
instrumentation_scope
"OpenTelemetry SDK - Instrumentation Scope"
"Instrumentation Scope components for the OpenTelemetry SDK, a library for exporting telemetry."
"opentelemetry_common")
endif()
113 changes: 113 additions & 0 deletions sdk/src/instrumentationscope/instrumentation_scope.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
#include <unordered_map>
#include <utility>
#include <vector>
#include "opentelemetry/nostd/variant.h"
Comment on lines +4 to +8

OPENTELEMETRY_BEGIN_NAMESPACE

namespace sdk
{
namespace instrumentationscope
{

nostd::unique_ptr<InstrumentationScope> InstrumentationScope::Create(
nostd::string_view name,
nostd::string_view version,
nostd::string_view schema_url,
InstrumentationScopeAttributes &&attributes)
{
return nostd::unique_ptr<InstrumentationScope>(
new InstrumentationScope{name, version, schema_url, std::move(attributes)});
}

nostd::unique_ptr<InstrumentationScope> InstrumentationScope::Create(
nostd::string_view name,
nostd::string_view version,
nostd::string_view schema_url,
const InstrumentationScopeAttributes &attributes)
{
return nostd::unique_ptr<InstrumentationScope>(new InstrumentationScope{
name, version, schema_url, InstrumentationScopeAttributes(attributes)});
}

std::size_t InstrumentationScope::HashCode() const noexcept
{
return hash_code_;
}

bool InstrumentationScope::operator==(const InstrumentationScope &other) const noexcept
{
return this->name_ == other.name_ && this->version_ == other.version_ &&
this->schema_url_ == other.schema_url_ && this->attributes_ == other.attributes_;
}

bool InstrumentationScope::equal(
const nostd::string_view name,
const nostd::string_view version,
const nostd::string_view schema_url,
const opentelemetry::common::KeyValueIterable *attributes) const noexcept
{

if (this->name_ != name || this->version_ != version || this->schema_url_ != schema_url)
{
return false;
}

if (attributes == nullptr)
{
if (attributes_.empty())
{
return true;
}
return false;
}

return attributes_.EqualTo(*attributes);
}

const std::string &InstrumentationScope::GetName() const noexcept
{
return name_;
}
const std::string &InstrumentationScope::GetVersion() const noexcept
{
return version_;
}
const std::string &InstrumentationScope::GetSchemaURL() const noexcept
{
return schema_url_;
}
const InstrumentationScopeAttributes &InstrumentationScope::GetAttributes() const noexcept
{
return attributes_;
}

void InstrumentationScope::SetAttribute(nostd::string_view key,
const opentelemetry::common::AttributeValue &value) noexcept
{
attributes_[std::string(key)] =
nostd::visit(opentelemetry::sdk::common::AttributeConverter(), value);
}

InstrumentationScope::InstrumentationScope(nostd::string_view name,
nostd::string_view version,
nostd::string_view schema_url,
InstrumentationScopeAttributes &&attributes)
: name_(name), version_(version), schema_url_(schema_url), attributes_(std::move(attributes))
{
std::string hash_data;
hash_data.reserve(name_.size() + version_.size() + schema_url_.size());
hash_data += name_;
hash_data += version_;
hash_data += schema_url_;
hash_code_ = std::hash<std::string>{}(hash_data);
}

} // namespace instrumentationscope
} // namespace sdk

OPENTELEMETRY_END_NAMESPACE
1 change: 1 addition & 0 deletions sdk/src/logs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cc_library(
"//sdk:headers",
"//sdk/src/common:disabled",
"//sdk/src/common:global_log_handler",
"//sdk/src/instrumentationscope",
"//sdk/src/resource",
],
)
5 changes: 3 additions & 2 deletions sdk/src/logs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ add_library(

set_target_properties(opentelemetry_logs PROPERTIES EXPORT_NAME logs)

target_link_libraries(opentelemetry_logs PUBLIC opentelemetry_resources
opentelemetry_common)
target_link_libraries(
opentelemetry_logs PUBLIC opentelemetry_resources opentelemetry_common
opentelemetry_instrumentation_scope)
set_target_version(opentelemetry_logs)

target_include_directories(
Expand Down
1 change: 1 addition & 0 deletions sdk/src/metrics/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cc_library(
"//sdk/src/common:global_log_handler",
"//sdk/src/common:random",
"//sdk/src/common:wildcard_match",
"//sdk/src/instrumentationscope",
"//sdk/src/resource",
],
)
5 changes: 3 additions & 2 deletions sdk/src/metrics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ add_library(
set_target_properties(opentelemetry_metrics PROPERTIES EXPORT_NAME metrics)
set_target_version(opentelemetry_metrics)

target_link_libraries(opentelemetry_metrics PUBLIC opentelemetry_common
opentelemetry_resources)
target_link_libraries(
opentelemetry_metrics PUBLIC opentelemetry_common opentelemetry_resources
opentelemetry_instrumentation_scope)

target_include_directories(
opentelemetry_metrics
Expand Down
1 change: 1 addition & 0 deletions sdk/src/trace/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ cc_library(
"//sdk/src/common:global_log_handler",
"//sdk/src/common:random",
"//sdk/src/common:wildcard_match",
"//sdk/src/instrumentationscope",
"//sdk/src/resource",
],
)
5 changes: 3 additions & 2 deletions sdk/src/trace/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ add_library(
set_target_properties(opentelemetry_trace PROPERTIES EXPORT_NAME trace)
set_target_version(opentelemetry_trace)

target_link_libraries(opentelemetry_trace PUBLIC opentelemetry_common
opentelemetry_resources)
target_link_libraries(
opentelemetry_trace PUBLIC opentelemetry_common opentelemetry_resources
opentelemetry_instrumentation_scope)

target_include_directories(
opentelemetry_trace
Expand Down
2 changes: 2 additions & 0 deletions sdk/test/instrumentationscope/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ cc_test(
deps = [
"//api",
"//sdk:headers",
"//sdk/src/common:env_variables",
"//sdk/src/instrumentationscope",
"@com_google_googletest//:gtest_main",
],
)
5 changes: 3 additions & 2 deletions sdk/test/instrumentationscope/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ include(GoogleTest)

foreach(testname instrumentationscope_test)
add_executable(${testname} "${testname}.cc")
target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} opentelemetry_sdk)
target_link_libraries(
${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
opentelemetry_instrumentation_scope)
gtest_add_tests(
TARGET ${testname}
TEST_PREFIX instrumentationscope.
Expand Down
Loading