File tree Expand file tree Collapse file tree 6 files changed +405
-10
lines changed Expand file tree Collapse file tree 6 files changed +405
-10
lines changed Original file line number Diff line number Diff line change @@ -9,3 +9,4 @@ gem "irb"
99gem "rake" , "~> 13.0"
1010gem "rubocop" , "~> 1.75"
1111gem "test-unit" , "~> 3.0"
12+ gem "timecop"
Original file line number Diff line number Diff line change @@ -10,10 +10,10 @@ class Fluent::Plugin::Otlp::Request
1010 class Logs
1111 def initialize ( body )
1212 @request =
13- if body . encoding == Encoding ::BINARY
14- Opentelemetry ::Proto ::Collector ::Logs ::V1 ::ExportLogsServiceRequest . decode ( body )
15- else
13+ if body . start_with? ( "{" )
1614 Opentelemetry ::Proto ::Collector ::Logs ::V1 ::ExportLogsServiceRequest . decode_json ( body )
15+ else
16+ Opentelemetry ::Proto ::Collector ::Logs ::V1 ::ExportLogsServiceRequest . decode ( body )
1717 end
1818 end
1919
@@ -29,10 +29,10 @@ def record
2929 class Metrics
3030 def initialize ( body )
3131 @request =
32- if body . encoding == Encoding ::BINARY
33- Opentelemetry ::Proto ::Collector ::Metrics ::V1 ::ExportMetricsServiceRequest . decode ( body )
34- else
32+ if body . start_with? ( "{" )
3533 Opentelemetry ::Proto ::Collector ::Metrics ::V1 ::ExportMetricsServiceRequest . decode_json ( body )
34+ else
35+ Opentelemetry ::Proto ::Collector ::Metrics ::V1 ::ExportMetricsServiceRequest . decode ( body )
3636 end
3737 end
3838
@@ -48,10 +48,10 @@ def record
4848 class Traces
4949 def initialize ( body )
5050 @request =
51- if body . encoding == Encoding ::BINARY
52- Opentelemetry ::Proto ::Collector ::Trace ::V1 ::ExportTraceServiceRequest . decode ( body )
53- else
51+ if body . start_with? ( "{" )
5452 Opentelemetry ::Proto ::Collector ::Trace ::V1 ::ExportTraceServiceRequest . decode_json ( body )
53+ else
54+ Opentelemetry ::Proto ::Collector ::Trace ::V1 ::ExportTraceServiceRequest . decode ( body )
5555 end
5656 end
5757
Original file line number Diff line number Diff line change 1+ {
2+ "resourceMetrics" : [
3+ {
4+ "resource" : {
5+ "attributes" : [
6+ {
7+ "key" : " service.name" ,
8+ "value" : {
9+ "stringValue" : " test-unit"
10+ }
11+ },
12+ {
13+ "key" : " process.pid" ,
14+ "value" : {
15+ "intValue" : " 28670"
16+ }
17+ },
18+ {
19+ "key" : " process.command" ,
20+ "value" : {
21+ "stringValue" : " metrics.rb"
22+ }
23+ },
24+ {
25+ "key" : " process.runtime.name" ,
26+ "value" : {
27+ "stringValue" : " ruby"
28+ }
29+ },
30+ {
31+ "key" : " process.runtime.version" ,
32+ "value" : {
33+ "stringValue" : " 3.4.2"
34+ }
35+ },
36+ {
37+ "key" : " process.runtime.description" ,
38+ "value" : {
39+ "stringValue" : " ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [x86_64-linux]"
40+ }
41+ },
42+ {
43+ "key" : " telemetry.sdk.name" ,
44+ "value" : {
45+ "stringValue" : " opentelemetry"
46+ }
47+ },
48+ {
49+ "key" : " telemetry.sdk.language" ,
50+ "value" : {
51+ "stringValue" : " ruby"
52+ }
53+ },
54+ {
55+ "key" : " telemetry.sdk.version" ,
56+ "value" : {
57+ "stringValue" : " 1.8.0"
58+ }
59+ }
60+ ]
61+ },
62+ "scopeMetrics" : [
63+ {
64+ "scope" : {
65+ "name" : " SAMPLE_METER_NAME"
66+ },
67+ "metrics" : [
68+ {
69+ "name" : " gauge" ,
70+ "description" : " desscription" ,
71+ "unit" : " cpu" ,
72+ "gauge" : {
73+ "dataPoints" : [
74+ {
75+ "startTimeUnixNano" : " 1744246311257468167" ,
76+ "timeUnixNano" : " 1744246311257652701" ,
77+ "asInt" : " 67" ,
78+ "attributes" : [
79+ {
80+ "key" : " cpuid" ,
81+ "value" : {
82+ "stringValue" : " 1"
83+ }
84+ },
85+ {
86+ "key" : " type" ,
87+ "value" : {
88+ "stringValue" : " user"
89+ }
90+ }
91+ ]
92+ },
93+ {
94+ "startTimeUnixNano" : " 1744246311257468167" ,
95+ "timeUnixNano" : " 1744246311257652701" ,
96+ "asInt" : " 42" ,
97+ "attributes" : [
98+ {
99+ "key" : " cpuid" ,
100+ "value" : {
101+ "stringValue" : " 2"
102+ }
103+ },
104+ {
105+ "key" : " type" ,
106+ "value" : {
107+ "stringValue" : " user"
108+ }
109+ }
110+ ]
111+ }
112+ ]
113+ }
114+ }
115+ ]
116+ }
117+ ]
118+ }
119+ ]
120+ }
You can’t perform that action at this time.
0 commit comments