Skip to content

Commit

Permalink
Merge remote-tracking branch 'opentelemetry/main' into async-changes
Browse files Browse the repository at this point in the history
Signed-off-by: WenTao Ou <admin@owent.net>

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
owent committed Jun 7, 2022
2 parents 0abf162 + 7e90dae commit c484d16
Show file tree
Hide file tree
Showing 24 changed files with 251 additions and 113 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ LICENSE* text
## git files
.gitignore text eol=lf
.gitattributes text eol=lf

## bazel files
WORKSPACE text eol=lf
BUILD text eol=lf
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Increment the:
* [EXPORTER] OTLP http exporter allow concurrency session ([#1209](https://github.com/open-telemetry/opentelemetry-cpp/pull/1209))
* [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://github.com/open-telemetry/opentelemetry-cpp/pull/1317))
* [METRICS] Only record non-negative / finite / Non-NAN histogram values([#1427](https://github.com/open-telemetry/opentelemetry-cpp/pull/1427))

## [1.4.0] 2022-05-17

Expand Down
45 changes: 26 additions & 19 deletions api/include/opentelemetry/metrics/meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,26 @@ class Meter
nostd::string_view unit = "") noexcept = 0;

/**
* Creates a Asynchronouse (Observable) counter with the passed characteristics and returns a
* Creates a Asynchronous (Observable) counter with the passed characteristics and returns a
* shared_ptr to that Observable Counter
*
* @param name the name of the new Observable Counter.
* @param callback the function to be observed by the instrument.
* @param description a brief description of what the Observable Counter is used for.
* @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
* @param callback the function to be observed by the instrument.
* @return a shared pointer to the created Observable Counter.
* @param state to be passed back to callback
*/
virtual void CreateLongObservableCounter(nostd::string_view name,
void (*callback)(ObserverResult<long> &),
void (*callback)(ObserverResult<long> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;
nostd::string_view unit = "",
void *state = nullptr) noexcept = 0;

virtual void CreateDoubleObservableCounter(nostd::string_view name,
void (*callback)(ObserverResult<double> &),
void (*callback)(ObserverResult<double> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;
nostd::string_view unit = "",
void *state = nullptr) noexcept = 0;

/**
* Creates a Histogram with the passed characteristics and returns a shared_ptr to that Histogram.
Expand All @@ -89,20 +91,22 @@ class Meter
* shared_ptr to that Observable Counter
*
* @param name the name of the new Observable Gauge.
* @param callback the function to be observed by the instrument.
* @param description a brief description of what the Observable Gauge is used for.
* @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
* @param callback the function to be observed by the instrument.
* @return a shared pointer to the created Observable Gauge.
* @param state to be passed back to callback
*/
virtual void CreateLongObservableGauge(nostd::string_view name,
void (*callback)(ObserverResult<long> &),
void (*callback)(ObserverResult<long> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;
nostd::string_view unit = "",
void *state = nullptr) noexcept = 0;

virtual void CreateDoubleObservableGauge(nostd::string_view name,
void (*callback)(ObserverResult<double> &),
void (*callback)(ObserverResult<double> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;
nostd::string_view unit = "",
void *state = nullptr) noexcept = 0;

/**
* Creates an UpDownCounter with the passed characteristics and returns a shared_ptr to that
Expand All @@ -128,20 +132,23 @@ class Meter
* a shared_ptr to that Observable UpDownCounter
*
* @param name the name of the new Observable UpDownCounter.
* @param callback the function to be observed by the instrument.
* @param description a brief description of what the Observable UpDownCounter is used for.
* @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
* @param callback the function to be observed by the instrument.
* @return a shared pointer to the created Observable UpDownCounter.
* @param state to be passed back to callback
*/
virtual void CreateLongObservableUpDownCounter(nostd::string_view name,
void (*callback)(ObserverResult<long> &),
void (*callback)(ObserverResult<long> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;
nostd::string_view unit = "",
void *state = nullptr) noexcept = 0;

virtual void CreateDoubleObservableUpDownCounter(nostd::string_view name,
void (*callback)(ObserverResult<double> &),
void (*callback)(ObserverResult<double> &,
void *),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;
nostd::string_view unit = "",
void *state = nullptr) noexcept = 0;
};
} // namespace metrics
OPENTELEMETRY_END_NAMESPACE
Expand Down
30 changes: 18 additions & 12 deletions api/include/opentelemetry/metrics/noop.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,17 @@ class NoopMeter final : public Meter
}

void CreateLongObservableCounter(nostd::string_view name,
void (*callback)(ObserverResult<long> &),
void (*callback)(ObserverResult<long> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
nostd::string_view unit = "",
void *state = nullptr) noexcept override
{}

void CreateDoubleObservableCounter(nostd::string_view name,
void (*callback)(ObserverResult<double> &),
void (*callback)(ObserverResult<double> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
nostd::string_view unit = "",
void *state = nullptr) noexcept override
{}

nostd::shared_ptr<Histogram<long>> CreateLongHistogram(
Expand All @@ -166,15 +168,17 @@ class NoopMeter final : public Meter
}

void CreateLongObservableGauge(nostd::string_view name,
void (*callback)(ObserverResult<long> &),
void (*callback)(ObserverResult<long> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
nostd::string_view unit = "",
void *state = nullptr) noexcept override
{}

void CreateDoubleObservableGauge(nostd::string_view name,
void (*callback)(ObserverResult<double> &),
void (*callback)(ObserverResult<double> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
nostd::string_view unit = "",
void *state = nullptr) noexcept override
{}

nostd::shared_ptr<UpDownCounter<long>> CreateLongUpDownCounter(
Expand All @@ -196,15 +200,17 @@ class NoopMeter final : public Meter
}

void CreateLongObservableUpDownCounter(nostd::string_view name,
void (*callback)(ObserverResult<long> &),
void (*callback)(ObserverResult<long> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
nostd::string_view unit = "",
void *state = nullptr) noexcept override
{}

void CreateDoubleObservableUpDownCounter(nostd::string_view name,
void (*callback)(ObserverResult<double> &),
void (*callback)(ObserverResult<double> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
nostd::string_view unit = "",
void *state = nullptr) noexcept override
{}
};

Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/trace/span_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class SpanContext final

bool IsRemote() const noexcept { return is_remote_; }

static SpanContext GetInvalid() { return SpanContext(false, false); }
static SpanContext GetInvalid() noexcept { return SpanContext(false, false); }

bool IsSampled() const noexcept { return trace_flags_.IsSampled(); }

Expand Down
2 changes: 1 addition & 1 deletion examples/common/metrics_foo_library/foo_library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ std::map<std::string, std::string> get_random_attr()
class MeasurementFetcher
{
public:
static void Fetcher(opentelemetry::metrics::ObserverResult<double> &observer_result)
static void Fetcher(opentelemetry::metrics::ObserverResult<double> &observer_result, void *state)
{
double val = (rand() % 700) + 1.1;
std::map<std::string, std::string> labels = get_random_attr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# include "opentelemetry/common/key_value_iterable_view.h"

# include "opentelemetry/logs/tracer_provider.h"
# include "opentelemetry/logs/logger_provider.h"
# include "opentelemetry/trace/span_id.h"
# include "opentelemetry/trace/trace_id.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class PropertyValue : public PropertyVariant
{}

/**
* @brief Convert owning PropertyValue to non-owning common::AttributeValue
* @brief Convert non-owning common::AttributeValue to owning PropertyValue.
* @return
*/
PropertyValue &FromAttributeValue(const common::AttributeValue &v)
Expand Down Expand Up @@ -222,7 +222,8 @@ class PropertyValue : public PropertyVariant
break;
}
case common::AttributeType::kTypeString: {
PropertyVariant::operator=(nostd::string_view(nostd::get<nostd::string_view>(v)).data());
PropertyVariant::operator=
(std::string{nostd::string_view(nostd::get<nostd::string_view>(v)).data()});
break;
}

Expand Down
2 changes: 1 addition & 1 deletion exporters/etw/test/etw_logger_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# include <map>
# include <string>

# include "opentelemetry/exporters/etw/etw_logger.h"
# include "opentelemetry/exporters/etw/etw_logger_exporter.h"
# include "opentelemetry/sdk/trace/simple_processor.h"

using namespace OPENTELEMETRY_NAMESPACE;
Expand Down
1 change: 1 addition & 0 deletions exporters/jaeger/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ cc_library(
tags = ["jaeger"],
deps = [
":jaeger_exporter",
"//sdk/src/common:global_log_handler",
],
)

Expand Down
39 changes: 8 additions & 31 deletions sdk/include/opentelemetry/sdk/common/global_log_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ inline std::string LevelToString(LogLevel level)
class LogHandler
{
public:
virtual ~LogHandler() = default;
virtual ~LogHandler();

virtual void Handle(LogLevel level,
const char *file,
Expand All @@ -71,22 +71,7 @@ class DefaultLogHandler : public LogHandler
const char *file,
int line,
const char *msg,
const sdk::common::AttributeMap &attributes) noexcept override
{
std::stringstream output_s;
output_s << "[" << LevelToString(level) << "] ";
if (file != nullptr)
{
output_s << "File: " << file << ":" << line;
}
if (msg != nullptr)
{
output_s << msg;
}
output_s << std::endl;
// TBD - print attributes
std::cout << output_s.str(); // thread safe.
}
const sdk::common::AttributeMap &attributes) noexcept override;
};

class NoopLogHandler : public LogHandler
Expand All @@ -96,10 +81,7 @@ class NoopLogHandler : public LogHandler
const char *file,
int line,
const char *msg,
const sdk::common::AttributeMap &error_attributes) noexcept override
{
// ignore the log message
}
const sdk::common::AttributeMap &error_attributes) noexcept override;
};

/**
Expand All @@ -113,7 +95,7 @@ class GlobalLogHandler
*
* By default, a default LogHandler is returned.
*/
static const nostd::shared_ptr<LogHandler> &GetLogHandler() noexcept
static inline const nostd::shared_ptr<LogHandler> &GetLogHandler() noexcept
{
return GetHandlerAndLevel().first;
}
Expand All @@ -123,7 +105,7 @@ class GlobalLogHandler
* This should be called once at the start of application before creating any Provider
* instance.
*/
static void SetLogHandler(nostd::shared_ptr<LogHandler> eh) noexcept
static inline void SetLogHandler(nostd::shared_ptr<LogHandler> eh) noexcept
{
GetHandlerAndLevel().first = eh;
}
Expand All @@ -133,22 +115,17 @@ class GlobalLogHandler
*
* By default, a default log level is returned.
*/
static LogLevel GetLogLevel() noexcept { return GetHandlerAndLevel().second; }
static inline LogLevel GetLogLevel() noexcept { return GetHandlerAndLevel().second; }

/**
* Changes the singleton Log level.
* This should be called once at the start of application before creating any Provider
* instance.
*/
static void SetLogLevel(LogLevel level) noexcept { GetHandlerAndLevel().second = level; }
static inline void SetLogLevel(LogLevel level) noexcept { GetHandlerAndLevel().second = level; }

private:
static std::pair<nostd::shared_ptr<LogHandler>, LogLevel> &GetHandlerAndLevel() noexcept
{
static std::pair<nostd::shared_ptr<LogHandler>, LogLevel> handler_and_level{
nostd::shared_ptr<LogHandler>(new DefaultLogHandler), LogLevel::Warning};
return handler_and_level;
}
static std::pair<nostd::shared_ptr<LogHandler>, LogLevel> &GetHandlerAndLevel() noexcept;
};

} // namespace internal_log
Expand Down
Loading

0 comments on commit c484d16

Please sign in to comment.