Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agents: preliminar changes to support logs in otlp #152

Merged
merged 1 commit into from
Aug 8, 2024
Merged
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
23 changes: 19 additions & 4 deletions agents/otlp/src/otlp_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "env-inl.h"
#include "nlohmann/json.hpp"
#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
#include "opentelemetry/sdk/logs/recordable.h"
#include "opentelemetry/sdk/resource/resource.h"
#include "opentelemetry/sdk/resource/semantic_conventions.h"
#include "opentelemetry/sdk/trace/recordable.h"
Expand All @@ -21,7 +22,9 @@ using std::chrono::microseconds;
using std::chrono::milliseconds;
using std::chrono::nanoseconds;

using opentelemetry::common::SystemTimestamp;
using opentelemetry::sdk::instrumentationscope::InstrumentationScope;
using LogsRecordable = opentelemetry::sdk::logs::Recordable;
using opentelemetry::sdk::metrics::AggregationTemporality;
using opentelemetry::sdk::metrics::MetricData;
using opentelemetry::sdk::metrics::InstrumentDescriptor;
Expand Down Expand Up @@ -73,8 +76,8 @@ static void add_counter(std::vector<MetricData>& metrics,
MetricData metric_data{
InstrumentDescriptor{ name, "", unit, InstrumentType::kCounter, type},
AggregationTemporality::kCumulative,
opentelemetry::common::SystemTimestamp{ start },
opentelemetry::common::SystemTimestamp{ end },
SystemTimestamp{ start },
SystemTimestamp{ end },
std::vector<PointDataAttributes>{{ attrs, sum_point_data }}
};
metrics.push_back(metric_data);
Expand All @@ -94,8 +97,8 @@ static void add_gauge(std::vector<MetricData>& metrics,
InstrumentDescriptor{
name, "", unit, InstrumentType::kObservableGauge, type },
AggregationTemporality::kCumulative,
opentelemetry::common::SystemTimestamp{ start },
opentelemetry::common::SystemTimestamp{ end },
SystemTimestamp{ start },
SystemTimestamp{ end },
std::vector<PointDataAttributes>{{ attrs, lv_point_data }}
};
metrics.push_back(metric_data);
Expand Down Expand Up @@ -254,6 +257,18 @@ NSOLID_ENV_METRICS_NUMBERS(V)
#undef V
}

void fill_log_recordable(LogsRecordable* recordable,
const LogWriteInfo& info) {
recordable->SetBody(info.msg);
recordable->SetSeverity(static_cast<opentelemetry::logs::Severity>(info.severity));
SystemTimestamp ts(duration_cast<time_point::duration>(
milliseconds(static_cast<uint64_t>(info.timestamp))));
recordable->SetTimestamp(ts);
recordable->SetObservedTimestamp(ts);
recordable->SetResource(*GetResource());
recordable->SetInstrumentationScope(*GetScope());
}

void fill_recordable(Recordable* recordable, const Tracer::SpanStor& s) {
recordable->SetName(s.name);
time_point start{
Expand Down
21 changes: 21 additions & 0 deletions agents/otlp/src/otlp_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ class Recordable;
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE

// Class pre-declaration
OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk {
namespace instrumentationscope {
class InstrumentationScope;
}
namespace logs {
class Recordable;
}
namespace resource {
class Resource;
}
namespace trace {
class Recordable;
}
}
OPENTELEMETRY_END_NAMESPACE

namespace node {
namespace nsolid {
namespace otlp {
Expand All @@ -34,6 +52,9 @@ void fill_proc_metrics(std::vector<opentelemetry::sdk::metrics::MetricData>&,
void fill_env_metrics(std::vector<opentelemetry::sdk::metrics::MetricData>&,
const ThreadMetrics::MetricsStor& stor);

void fill_log_recordable(OPENTELEMETRY_NAMESPACE::sdk::logs::Recordable*,
const LogWriteInfo&);

void fill_recordable(OPENTELEMETRY_NAMESPACE::sdk::trace::Recordable*,
const Tracer::SpanStor&);

Expand Down
5 changes: 5 additions & 0 deletions deps/opentelemetry-cpp/otlp-http-exporter.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
'exporters/otlp/src/otlp_grpc_client.cc',
'exporters/otlp/src/otlp_grpc_exporter_options.cc',
'exporters/otlp/src/otlp_grpc_exporter.cc',
'exporters/otlp/src/otlp_grpc_log_record_exporter.cc',
'exporters/otlp/src/otlp_grpc_log_record_exporter_options.cc',
'exporters/otlp/src/otlp_grpc_metric_exporter_options.cc',
'exporters/otlp/src/otlp_grpc_metric_exporter.cc',
'exporters/otlp/src/otlp_grpc_utils.cc',
'exporters/otlp/src/otlp_http.cc',
'exporters/otlp/src/otlp_http_client.cc',
'exporters/otlp/src/otlp_http_exporter.cc',
'exporters/otlp/src/otlp_http_exporter_options.cc',
'exporters/otlp/src/otlp_http_log_record_exporter.cc',
'exporters/otlp/src/otlp_http_log_record_exporter_options.cc',
'exporters/otlp/src/otlp_http_metric_exporter.cc',
'exporters/otlp/src/otlp_http_metric_exporter_options.cc',
'exporters/otlp/src/otlp_log_recordable.cc',
Expand All @@ -28,6 +32,7 @@
'sdk/src/common/base64.cc',
'sdk/src/common/env_variables.cc',
'sdk/src/common/global_log_handler.cc',
'sdk/src/logs/exporter.cc',
'sdk/src/logs/readable_log_record.cc',
'sdk/src/resource/resource.cc',
'sdk/src/resource/resource_detector.cc',
Expand Down
Loading