@@ -47,7 +47,9 @@ type explicitHistogram struct {
47
47
bounds []float64
48
48
49
49
maxExemplarCount * int
50
- startTimestamp pcommon.Timestamp
50
+
51
+ startTimestamp pcommon.Timestamp
52
+ lastSeenTimestamp pcommon.Timestamp
51
53
}
52
54
53
55
type exponentialHistogram struct {
@@ -57,7 +59,9 @@ type exponentialHistogram struct {
57
59
histogram * structure.Histogram [float64 ]
58
60
59
61
maxExemplarCount * int
60
- startTimestamp pcommon.Timestamp
62
+
63
+ startTimestamp pcommon.Timestamp
64
+ lastSeenTimestamp pcommon.Timestamp
61
65
}
62
66
63
67
type generateStartTimestamp = func (Key ) pcommon.Timestamp
@@ -91,6 +95,7 @@ func (m *explicitHistogramMetrics) GetOrCreate(key Key, attributes pcommon.Map,
91
95
m .metrics [key ] = h
92
96
}
93
97
98
+ h .lastSeenTimestamp = startTimestamp
94
99
return h
95
100
}
96
101
@@ -104,8 +109,14 @@ func (m *explicitHistogramMetrics) BuildMetrics(
104
109
dps .EnsureCapacity (len (m .metrics ))
105
110
for _ , h := range m .metrics {
106
111
dp := dps .AppendEmpty ()
112
+ var startTimeStamp pcommon.Timestamp
113
+ if temporality == pmetric .AggregationTemporalityDelta {
114
+ startTimeStamp = h .lastSeenTimestamp
115
+ } else {
116
+ startTimeStamp = h .startTimestamp
117
+ }
118
+ dp .SetStartTimestamp (startTimeStamp )
107
119
dp .SetTimestamp (timestamp )
108
- dp .SetStartTimestamp (h .startTimestamp )
109
120
dp .ExplicitBounds ().FromRaw (h .bounds )
110
121
dp .BucketCounts ().FromRaw (h .bucketCounts )
111
122
dp .SetCount (h .count )
@@ -115,7 +126,6 @@ func (m *explicitHistogramMetrics) BuildMetrics(
115
126
}
116
127
h .exemplars .CopyTo (dp .Exemplars ())
117
128
h .attributes .CopyTo (dp .Attributes ())
118
- dp .Attributes ().PutInt ("startTimestamp" , int64 (h .startTimestamp ))
119
129
}
120
130
}
121
131
@@ -143,6 +153,7 @@ func (m *exponentialHistogramMetrics) GetOrCreate(key Key, attributes pcommon.Ma
143
153
m .metrics [key ] = h
144
154
}
145
155
156
+ h .lastSeenTimestamp = startTimeStamp
146
157
return h
147
158
}
148
159
@@ -156,15 +167,20 @@ func (m *exponentialHistogramMetrics) BuildMetrics(
156
167
dps .EnsureCapacity (len (m .metrics ))
157
168
for _ , e := range m .metrics {
158
169
dp := dps .AppendEmpty ()
159
- dp .SetStartTimestamp (e .startTimestamp )
170
+ var startTimeStamp pcommon.Timestamp
171
+ if temporality == pmetric .AggregationTemporalityDelta {
172
+ startTimeStamp = e .lastSeenTimestamp
173
+ } else {
174
+ startTimeStamp = e .startTimestamp
175
+ }
176
+ dp .SetStartTimestamp (startTimeStamp )
160
177
dp .SetTimestamp (timestamp )
161
178
expoHistToExponentialDataPoint (e .histogram , dp )
162
179
for i := 0 ; i < e .exemplars .Len (); i ++ {
163
180
e .exemplars .At (i ).SetTimestamp (timestamp )
164
181
}
165
182
e .exemplars .CopyTo (dp .Exemplars ())
166
183
e .attributes .CopyTo (dp .Attributes ())
167
- dp .Attributes ().PutInt ("startTimestamp" , int64 (e .startTimestamp ))
168
184
}
169
185
}
170
186
@@ -239,11 +255,14 @@ func (h *exponentialHistogram) AddExemplar(traceID pcommon.TraceID, spanID pcomm
239
255
}
240
256
241
257
type Sum struct {
242
- attributes pcommon.Map
243
- count uint64
258
+ attributes pcommon.Map
259
+ count uint64
260
+
244
261
exemplars pmetric.ExemplarSlice
245
262
maxExemplarCount * int
246
- startTimestamp pcommon.Timestamp
263
+
264
+ startTimestamp pcommon.Timestamp
265
+ lastSeenTimestamp pcommon.Timestamp
247
266
}
248
267
249
268
func (s * Sum ) Add (value uint64 ) {
@@ -273,6 +292,7 @@ func (m *SumMetrics) GetOrCreate(key Key, attributes pcommon.Map, startTimestamp
273
292
}
274
293
m .metrics [key ] = s
275
294
}
295
+ s .lastSeenTimestamp = startTimestamp
276
296
return s
277
297
}
278
298
@@ -298,7 +318,13 @@ func (m *SumMetrics) BuildMetrics(
298
318
dps .EnsureCapacity (len (m .metrics ))
299
319
for _ , s := range m .metrics {
300
320
dp := dps .AppendEmpty ()
301
- dp .SetStartTimestamp (s .startTimestamp )
321
+ var startTimeStamp pcommon.Timestamp
322
+ if temporality == pmetric .AggregationTemporalityDelta {
323
+ startTimeStamp = s .lastSeenTimestamp
324
+ } else {
325
+ startTimeStamp = s .startTimestamp
326
+ }
327
+ dp .SetStartTimestamp (startTimeStamp )
302
328
dp .SetTimestamp (timestamp )
303
329
dp .SetIntValue (int64 (s .count ))
304
330
for i := 0 ; i < s .exemplars .Len (); i ++ {
0 commit comments