diff --git a/agents/otlp/src/otlp_common.cc b/agents/otlp/src/otlp_common.cc index 4e646d907b..33e6a31145 100644 --- a/agents/otlp/src/otlp_common.cc +++ b/agents/otlp/src/otlp_common.cc @@ -46,6 +46,7 @@ using opentelemetry::trace::SpanKind; using opentelemetry::trace::TraceFlags; using opentelemetry::trace::TraceId; using opentelemetry::trace::propagation::detail::HexToBinary; +using opentelemetry::v1::trace::SemanticConventions::kProcessOwner; using opentelemetry::v1::trace::SemanticConventions::kThreadId; using opentelemetry::v1::trace::SemanticConventions::kThreadName; @@ -179,7 +180,9 @@ Resource* UpdateResource(ResourceAttributes&& attrs) { // NOLINTNEXTLINE(runtime/references) void fill_proc_metrics(std::vector& metrics, - const ProcessMetrics::MetricsStor& stor) { + const ProcessMetrics::MetricsStor& stor, + const ProcessMetrics::MetricsStor& prev_stor, + bool use_snake_case) { time_point end{ duration_cast( milliseconds(static_cast(stor.timestamp)))}; @@ -211,7 +214,7 @@ void fill_proc_metrics(std::vector& metrics, add_counter(metrics, \ process_start, \ end, \ - #CName, \ + use_snake_case ? #CName : #JSName, \ Unit, \ type, \ value); \ @@ -219,7 +222,13 @@ void fill_proc_metrics(std::vector& metrics, break; \ case MetricsType::EGauge: \ { \ - add_gauge(metrics, process_start, end, #CName, Unit, type, value); \ + add_gauge(metrics, \ + process_start, \ + end, \ + use_snake_case ? #CName : #JSName, \ + Unit, \ + type, \ + value); \ } \ break; \ default: \ @@ -230,11 +239,23 @@ void fill_proc_metrics(std::vector& metrics, NSOLID_PROCESS_METRICS_UINT64(V) NSOLID_PROCESS_METRICS_DOUBLE(V) #undef V + + // Update Resource if needed: + // Check if 'user' or 'title' are different from the previous metrics. + if (prev_stor.user != stor.user || prev_stor.title != stor.title) { + ResourceAttributes attrs = { + { kProcessOwner, stor.user }, + { "process.title", stor.title }, + }; + + USE(UpdateResource(std::move(attrs))); + } } // NOLINTNEXTLINE(runtime/references) void fill_env_metrics(std::vector& metrics, - const ThreadMetrics::MetricsStor& stor) { + const ThreadMetrics::MetricsStor& stor, + bool use_snake_case) { time_point end{ duration_cast( milliseconds(static_cast(stor.timestamp)))}; @@ -271,7 +292,7 @@ void fill_env_metrics(std::vector& metrics, add_counter(metrics, \ process_start, \ end, \ - #CName, \ + use_snake_case ? #CName : #JSName, \ Unit, \ type, \ value, \ @@ -283,7 +304,7 @@ void fill_env_metrics(std::vector& metrics, add_gauge(metrics, \ process_start, \ end, \ - #CName, \ + use_snake_case ? #CName : #JSName, \ Unit, \ type, \ value, \ @@ -301,7 +322,7 @@ NSOLID_ENV_METRICS_NUMBERS(V) add_summary(metrics, process_start, end, - "gc_dur", + use_snake_case ? "gc_dur_us" : "gcDurUs", kNSUSecs, InstrumentValueType::kDouble, {{ 0.5, stor.gc_dur_us_median }, @@ -318,7 +339,7 @@ NSOLID_ENV_METRICS_NUMBERS(V) add_summary(metrics, process_start, end, - "http_client", + use_snake_case ? "http_client" : "httpClient", kNSMSecs, InstrumentValueType::kDouble, {{ 0.5, stor.http_client99_ptile }, @@ -327,7 +348,7 @@ NSOLID_ENV_METRICS_NUMBERS(V) add_summary(metrics, process_start, end, - "http_server", + use_snake_case ? "http_server" : "httpServer", kNSMSecs, InstrumentValueType::kDouble, {{ 0.5, stor.http_server_median }, @@ -391,6 +412,7 @@ void fill_recordable(Recordable* recordable, const Tracer::SpanStor& s) { } recordable->SetAttribute("thread.id", s.thread_id); + recordable->SetAttribute("nsolid.span_type", s.type); recordable->SetResource(*GetResource()); } diff --git a/agents/otlp/src/otlp_common.h b/agents/otlp/src/otlp_common.h index 871e8261b8..8c8bd8cdc6 100644 --- a/agents/otlp/src/otlp_common.h +++ b/agents/otlp/src/otlp_common.h @@ -48,10 +48,13 @@ OPENTELEMETRY_NAMESPACE::sdk::resource::Resource* UpdateResource( OPENTELEMETRY_NAMESPACE::sdk::resource::ResourceAttributes&&); void fill_proc_metrics(std::vector&, - const ProcessMetrics::MetricsStor& stor); + const ProcessMetrics::MetricsStor& stor, + const ProcessMetrics::MetricsStor& prev_stor, + bool use_snake_case = true); void fill_env_metrics(std::vector&, - const ThreadMetrics::MetricsStor& stor); + const ThreadMetrics::MetricsStor& stor, + bool use_snake_case = true); void fill_log_recordable(OPENTELEMETRY_NAMESPACE::sdk::logs::Recordable*, const LogWriteInfo&); diff --git a/agents/otlp/src/otlp_metrics.cc b/agents/otlp/src/otlp_metrics.cc index 3718d15ea0..92f5704e92 100644 --- a/agents/otlp/src/otlp_metrics.cc +++ b/agents/otlp/src/otlp_metrics.cc @@ -39,14 +39,11 @@ using opentelemetry::sdk::metrics::ScopeMetrics; using opentelemetry::sdk::metrics::SumPointData; using opentelemetry::sdk::metrics::ValueType; using opentelemetry::sdk::resource::Resource; -using opentelemetry::sdk::resource::ResourceAttributes; using opentelemetry::v1::exporter::otlp::GetOtlpDefaultHttpMetricsProtocol; using opentelemetry::v1::exporter::otlp::OtlpGrpcMetricExporter; using opentelemetry::v1::exporter::otlp::OtlpGrpcMetricExporterOptions; using opentelemetry::v1::exporter::otlp::OtlpHttpMetricExporter; using opentelemetry::v1::exporter::otlp::OtlpHttpMetricExporterOptions; -using opentelemetry::v1::trace::SemanticConventions::kProcessOwner; -using opentelemetry::v1::trace::SemanticConventions::kThreadId; namespace node { namespace nsolid { @@ -104,23 +101,10 @@ OTLPMetrics::~OTLPMetrics() { /*virtual*/ void OTLPMetrics::got_proc_metrics(const ProcessMetricsStor& stor, const ProcessMetricsStor& prev_stor) { - ResourceMetrics data; - Resource* resource; - // Check if 'user' or 'title' are different from the previous metrics - if (prev_stor.user != stor.user || prev_stor.title != stor.title) { - ResourceAttributes attrs = { - { kProcessOwner, stor.user }, - { "process.title", stor.title }, - }; - - resource = UpdateResource(std::move(attrs)); - } else { - resource = GetResource(); - } - - data.resource_ = resource; std::vector metrics; - fill_proc_metrics(metrics, stor); + fill_proc_metrics(metrics, stor, prev_stor); + ResourceMetrics data; + data.resource_ = GetResource(); data.scope_metric_data_ = std::vector{{scope_, metrics}}; auto result = otlp_metric_exporter_->Export(data); Debug("# ProcessMetrics Exported. Result: %d\n", static_cast(result)); diff --git a/doc/changelogs/NSOLID_CHANGELOG_V5_NODE_V20.md b/doc/changelogs/NSOLID_CHANGELOG_V5_NODE_V20.md index 53bf9880be..f131bc918f 100644 --- a/doc/changelogs/NSOLID_CHANGELOG_V5_NODE_V20.md +++ b/doc/changelogs/NSOLID_CHANGELOG_V5_NODE_V20.md @@ -26,7 +26,6 @@ * \[[`3913f0e27f`](https://github.com/nodesource/nsolid/commit/3913f0e27f)] - **agents:** refactor ZmqAgent to use ProfileCollector (Santiago Gimeno) [nodesource/nsolid#161](https://github.com/nodesource/nsolid/pull/161) * \[[`183b115e48`](https://github.com/nodesource/nsolid/commit/183b115e48)] - **agents:** implement ProfileCollector class (Santiago Gimeno) [nodesource/nsolid#161](https://github.com/nodesource/nsolid/pull/161) - ## 2024-08-23, Version 20.17.0-nsolid-v5.3.3 'Iron' ### Commits diff --git a/test/agents/test-otlp-grpc-metrics.mjs b/test/agents/test-otlp-grpc-metrics.mjs index fa853ccce4..2446c06788 100644 --- a/test/agents/test-otlp-grpc-metrics.mjs +++ b/test/agents/test-otlp-grpc-metrics.mjs @@ -122,7 +122,7 @@ if (process.argv[2] === 'child') { ['loop_avg_tasks', undefined, 'asDouble', 'gauge'], ['loop_estimated_lag', 'ms', 'asDouble', 'gauge'], ['loop_idle_percent', undefined, 'asDouble', 'gauge'], - ['gc_dur', 'us', 'asDouble', 'summary'], + ['gc_dur_us', 'us', 'asDouble', 'summary'], ['dns', 'ms', 'asDouble', 'summary'], ['http_client', 'ms', 'asDouble', 'summary'], ['http_server', 'ms', 'asDouble', 'summary'], diff --git a/test/agents/test-otlp-grpc-traces.mjs b/test/agents/test-otlp-grpc-traces.mjs index 2acae5154a..d328a56b14 100644 --- a/test/agents/test-otlp-grpc-traces.mjs +++ b/test/agents/test-otlp-grpc-traces.mjs @@ -160,7 +160,7 @@ if (process.argv[2] === 'child') { const endTimeUnixNano = BigInt(serverSpan.endTimeUnixNano); assert.ok(endTimeUnixNano); validateArray(serverSpan.attributes, 'serverSpan.attributes'); - assert.strictEqual(serverSpan.attributes.length, 5); + assert.strictEqual(serverSpan.attributes.length, 6); assert.strictEqual(serverSpan.attributes[0].key, 'http.method'); assert.strictEqual(serverSpan.attributes[0].value.stringValue, 'GET'); assert.strictEqual(serverSpan.attributes[1].key, 'http.status_code'); @@ -172,6 +172,8 @@ if (process.argv[2] === 'child') { `http://127.0.0.1:${port}/`); assert.strictEqual(serverSpan.attributes[4].key, 'thread.id'); assert.strictEqual(serverSpan.attributes[4].value.intValue, `${threadId}`); + assert.strictEqual(serverSpan.attributes[5].key, 'nsolid.span_type'); + assert.strictEqual(serverSpan.attributes[5].value.intValue, '8'); const clientSpan = spans[1]; validateId(serverSpan.traceId, 16); @@ -183,7 +185,7 @@ if (process.argv[2] === 'child') { const endTimeUnixNano2 = BigInt(clientSpan.endTimeUnixNano); assert.ok(endTimeUnixNano2); validateArray(clientSpan.attributes, 'clientSpan.attributes'); - assert.strictEqual(clientSpan.attributes.length, 5); + assert.strictEqual(clientSpan.attributes.length, 6); assert.strictEqual(clientSpan.attributes[0].key, 'http.method'); assert.strictEqual(clientSpan.attributes[0].value.stringValue, 'GET'); assert.strictEqual(clientSpan.attributes[1].key, 'http.status_code'); @@ -195,6 +197,8 @@ if (process.argv[2] === 'child') { `http://127.0.0.1:${port}/`); assert.strictEqual(clientSpan.attributes[4].key, 'thread.id'); assert.strictEqual(clientSpan.attributes[4].value.intValue, `${threadId}`); + assert.strictEqual(clientSpan.attributes[5].key, 'nsolid.span_type'); + assert.strictEqual(clientSpan.attributes[5].value.intValue, '4'); } function mergeResourceSpans(data, result) { diff --git a/test/agents/test-otlp-metrics.mjs b/test/agents/test-otlp-metrics.mjs index e570610750..4f0ee3b926 100644 --- a/test/agents/test-otlp-metrics.mjs +++ b/test/agents/test-otlp-metrics.mjs @@ -122,7 +122,7 @@ if (process.argv[2] === 'child') { ['loop_avg_tasks', undefined, 'asDouble', 'gauge'], ['loop_estimated_lag', 'ms', 'asDouble', 'gauge'], ['loop_idle_percent', undefined, 'asDouble', 'gauge'], - ['gc_dur', 'us', 'asDouble', 'summary'], + ['gc_dur_us', 'us', 'asDouble', 'summary'], ['dns', 'ms', 'asDouble', 'summary'], ['http_client', 'ms', 'asDouble', 'summary'], ['http_server', 'ms', 'asDouble', 'summary'], diff --git a/test/agents/test-otlp-traces.mjs b/test/agents/test-otlp-traces.mjs index 06f1b5cbc7..fb6cf19071 100644 --- a/test/agents/test-otlp-traces.mjs +++ b/test/agents/test-otlp-traces.mjs @@ -145,7 +145,7 @@ if (process.argv[2] === 'child') { const endTimeUnixNano = BigInt(serverSpan.endTimeUnixNano); assert.ok(endTimeUnixNano); validateArray(serverSpan.attributes, 'serverSpan.attributes'); - assert.strictEqual(serverSpan.attributes.length, 5); + assert.strictEqual(serverSpan.attributes.length, 6); assert.strictEqual(serverSpan.attributes[0].key, 'http.method'); assert.strictEqual(serverSpan.attributes[0].value.stringValue, 'GET'); assert.strictEqual(serverSpan.attributes[1].key, 'http.status_code'); @@ -157,6 +157,8 @@ if (process.argv[2] === 'child') { `http://127.0.0.1:${port}/`); assert.strictEqual(serverSpan.attributes[4].key, 'thread.id'); assert.strictEqual(serverSpan.attributes[4].value.intValue, `${threadId}`); + assert.strictEqual(serverSpan.attributes[5].key, 'nsolid.span_type'); + assert.strictEqual(serverSpan.attributes[5].value.intValue, '8'); const clientSpan = spans[1]; validateString(clientSpan.traceId, 'clientSpan.traceId'); @@ -168,7 +170,7 @@ if (process.argv[2] === 'child') { const endTimeUnixNano2 = BigInt(clientSpan.endTimeUnixNano); assert.ok(endTimeUnixNano2); validateArray(clientSpan.attributes, 'clientSpan.attributes'); - assert.strictEqual(clientSpan.attributes.length, 5); + assert.strictEqual(clientSpan.attributes.length, 6); assert.strictEqual(clientSpan.attributes[0].key, 'http.method'); assert.strictEqual(clientSpan.attributes[0].value.stringValue, 'GET'); assert.strictEqual(clientSpan.attributes[1].key, 'http.status_code'); @@ -180,6 +182,8 @@ if (process.argv[2] === 'child') { `http://127.0.0.1:${port}/`); assert.strictEqual(clientSpan.attributes[4].key, 'thread.id'); assert.strictEqual(clientSpan.attributes[4].value.intValue, `${threadId}`); + assert.strictEqual(clientSpan.attributes[5].key, 'nsolid.span_type'); + assert.strictEqual(clientSpan.attributes[5].value.intValue, '4'); } function mergeResourceSpans(data, result) {