Skip to content

Commit

Permalink
[Geneva] Add prepopulated dimension names to Geneva Metrics Exporter (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomsonTan authored Mar 18, 2024
1 parent 8bf5ebe commit 09f638f
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

#pragma once

#include "opentelemetry/version.h"
#include <string>

#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter {
namespace geneva {
Expand All @@ -22,6 +23,7 @@ struct ExporterOptions {
*/
// clang-format off
std::string connection_string;
const std::map<std::string, std::string> prepopulated_dimensions;
};
} // namespace metrics
} // namespace geneva
Expand Down
44 changes: 44 additions & 0 deletions exporters/geneva/src/exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ size_t Exporter::SerializeNonHistogramMetrics(
SerializeString(buffer_, bufferIndex, metric_name);

uint16_t attributes_size = 0;

// serialize prepopulated names
for (const auto &kv : options_.prepopulated_dimensions) {
if (kv.first.size() > kMaxDimensionNameSize) {
LOG_WARN("Dimension name limit overflow: %s Limit: %zd", kv.first.c_str(),
kMaxDimensionNameSize);
continue;
}
attributes_size++;
SerializeString(buffer_, bufferIndex, kv.first);
}

for (const auto &kv : attributes) {
if (kv.first.size() > kMaxDimensionNameSize) {
LOG_WARN("Dimension name limit overflow: %s Limit: %d", kv.first.c_str(),
Expand All @@ -225,6 +237,16 @@ size_t Exporter::SerializeNonHistogramMetrics(
attributes_size++;
SerializeString(buffer_, bufferIndex, kv.first);
}

// serialize prepopulated values
for (const auto &kv : options_.prepopulated_dimensions) {
if (kv.second.size() > kMaxDimensionNameSize) {
// warning is already logged earlier, no logging again
continue;
}
SerializeString(buffer_, bufferIndex, kv.second);
}

for (const auto &kv : attributes) {
if (kv.first.size() > kMaxDimensionNameSize) {
LOG_WARN("Dimension name limit overflow: %s Limit: %d", kv.first.c_str(),
Expand Down Expand Up @@ -326,6 +348,18 @@ size_t Exporter::SerializeHistogramMetrics(
SerializeString(buffer_, bufferIndex, metric_name);

uint16_t attributes_size = 0;

// dimensions - prepopulated names
for (const auto &kv : options_.prepopulated_dimensions) {
if (kv.first.size() > kMaxDimensionNameSize) {
LOG_WARN("Dimension name limit overflow: %s Limit: %zd", kv.first.c_str(),
kMaxDimensionNameSize);
continue;
}
attributes_size++;
SerializeString(buffer_, bufferIndex, kv.first);
}

// dimentions - name
for (const auto &kv : attributes) {
if (kv.first.size() > kMaxDimensionNameSize) {
Expand All @@ -343,6 +377,16 @@ size_t Exporter::SerializeHistogramMetrics(
SerializeString(buffer_, bufferIndex, kv.first);
}


// dimensions - prepopulated values
for (const auto &kv : options_.prepopulated_dimensions) {
if (kv.second.size() > kMaxDimensionNameSize) {
// warning is already logged earlier, no logging again
continue;
}
SerializeString(buffer_, bufferIndex, kv.second);
}

// dimentions - value
for (const auto &kv : attributes) {
if (kv.first.size() > kMaxDimensionNameSize) {
Expand Down
4 changes: 4 additions & 0 deletions exporters/geneva/test/common/generate_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const std::string kCounterDoubleAttributeKey2 = "counter_double_key2";
const std::string kCounterDoubleAttributeValue2 = "counter_double_value2";
const std::string kCounterDoubleAttributeKey3 = "counter_double_key3";
const std::string kCounterDoubleAttributeValue3 = "counter_double_value3";
const std::string kPrepopulatedDimensionKey1 = "prepopulated_key1";
const std::string kPrepopulatedDimensionValue1 = "prepopulated_value1";
const std::string kPrepopulatedDimensionKey2 = "prepopulated_key2";
const std::string kPrepopulatedDimensionValue2 = "prepopulated_value2";
const uint16_t kCounterDoubleCountDimensions = 1;
const uint16_t kCounterDoubleEventId = 55;

Expand Down
Loading

0 comments on commit 09f638f

Please sign in to comment.