Skip to content

Commit d327f47

Browse files
committed
WIP
1 parent 06bb6eb commit d327f47

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

lib/fluent/plugin/in_opentelemetry_metrics.rb

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,9 @@ def metrics_data
5151
{
5252
"resource" => {
5353
"attributes" => [
54-
{
55-
"key" => "service.name",
56-
"value" => {
57-
"stringValue" => "fluentd"
58-
}
59-
},
60-
{
61-
"key" => "service.version",
62-
"value" => {
63-
"stringValue" => Fluent::VERSION
64-
}
65-
},
66-
{
67-
"key" => "process.pid",
68-
"value" => {
69-
"intValue" => Process.pid
70-
}
71-
}
54+
string_value_attribute("service.name", "fluentd"),
55+
string_value_attribute("service.version", Fluent::VERSION),
56+
int_value_attribute("process.pid", Process.pid)
7257
]
7358
},
7459
"scopeMetrics" => scope_metrics
@@ -104,14 +89,7 @@ def scope_metrics
10489
end
10590

10691
def metrics_value(time, record, attrs, metrics = [])
107-
attributes = attrs.map do |k, v|
108-
{
109-
"key" => k.to_s,
110-
"value" => {
111-
"stringValue" => v.to_s
112-
}
113-
}
114-
end
92+
attributes = attrs.map { |k, v| string_value_attribute(k, v) }
11593

11694
record.each do |key, value|
11795
if value.is_a?(Numeric)
@@ -133,6 +111,24 @@ def metrics_value(time, record, attrs, metrics = [])
133111
end
134112
end
135113
end
114+
115+
def string_value_attribute(key, value)
116+
{
117+
"key" => key.to_s,
118+
"value" => {
119+
"stringValue" => value.to_s
120+
}
121+
}
122+
end
123+
124+
def int_value_attribute(key, value)
125+
{
126+
"key" => key.to_s,
127+
"value" => {
128+
"intValue" => value
129+
}
130+
}
131+
end
136132
end
137133

138134
class MonitorInfo

0 commit comments

Comments
 (0)