Skip to content

Commit 71ef246

Browse files
kkondakaGalactus22625
authored andcommitted
Add missing OTEL standard fields (opensearch-project#5635)
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
1 parent ecf1213 commit 71ef246

18 files changed

Lines changed: 268 additions & 37 deletions

File tree

data-prepper-api/src/main/java/org/opensearch/dataprepper/model/metric/JacksonMetric.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public abstract class JacksonMetric extends JacksonEvent implements Metric {
3737
protected static final String SCHEMA_URL_KEY = "schemaUrl";
3838
protected static final String EXEMPLARS_KEY = "exemplars";
3939
protected static final String FLAGS_KEY = "flags";
40+
protected static final String METADATA_KEY = "metadata";
4041
private boolean flattenAttributes;
4142

4243
protected JacksonMetric(Builder builder, boolean flattenAttributes) {
@@ -101,6 +102,11 @@ public String getKind() {
101102
return this.get(KIND_KEY, String.class);
102103
}
103104

105+
@Override
106+
public Map<String, Object> getMetricMetadata() {
107+
return this.get(METADATA_KEY, Map.class);
108+
}
109+
104110
@Override
105111
public String getStartTime() {
106112
return this.get(START_TIME_KEY, String.class);
@@ -256,7 +262,7 @@ public T withServiceName(final String serviceName) {
256262
}
257263

258264
/**
259-
* Sets the scope of the log event
265+
* Sets the scope of the metric event
260266
*
261267
* @param scope scope to be set
262268
* @return the builder
@@ -268,7 +274,19 @@ public T withScope(final Map<String, Object> scope) {
268274
}
269275

270276
/**
271-
* Sets the resource of the log event
277+
* Sets the metadata of the metric event
278+
*
279+
* @param metadata metadata to be set
280+
* @return the builder
281+
* @since 2.11
282+
*/
283+
public T withMetricMetadata(final Map<String, Object> metadata) {
284+
put(METADATA_KEY, metadata);
285+
return getThis();
286+
}
287+
288+
/**
289+
* Sets the resource of the metric event
272290
*
273291
* @param resource resource to be set
274292
* @return the builder

data-prepper-api/src/main/java/org/opensearch/dataprepper/model/metric/Metric.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,23 @@ enum KIND {GAUGE, HISTOGRAM, EXPONENTIAL_HISTOGRAM, SUM, SUMMARY}
116116
Integer getFlags();
117117

118118
/**
119-
* Gets the scope of this log event.
119+
* Gets the scope of this metric event.
120120
*
121121
* @return the scope
122122
* @since 2.11
123123
*/
124124
Map<String, Object> getScope();
125125

126126
/**
127-
* Gets the resource of this log event.
127+
* Gets the metadata of this metric event.
128+
*
129+
* @return the metadata
130+
* @since 2.11
131+
*/
132+
Map<String, Object> getMetricMetadata();
133+
134+
/**
135+
* Gets the resource of this metric event.
128136
*
129137
* @return the resource
130138
* @since 2.11

data-prepper-api/src/main/java/org/opensearch/dataprepper/model/trace/JacksonSpan.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class JacksonSpan extends JacksonEvent implements Span {
4848
protected static final String ATTRIBUTES_KEY = "attributes";
4949
private static final String DROPPED_ATTRIBUTES_COUNT_KEY = "droppedAttributesCount";
5050
private static final String EVENTS_KEY = "events";
51+
private static final String SCHEMA_URL_KEY = "schemaUrl";
5152
private static final String DROPPED_EVENTS_COUNT_KEY = "droppedEventsCount";
5253
private static final String LINKS_KEY = "links";
5354
private static final String DROPPED_LINKS_COUNT_KEY = "droppedLinksCount";
@@ -91,6 +92,11 @@ protected void checkAndSetDefaultValues() {
9192
putIfAbsent(DROPPED_EVENTS_COUNT_KEY, Integer.class, 0);
9293
}
9394

95+
@Override
96+
public String getSchemaUrl() {
97+
return this.get(SCHEMA_URL_KEY, String.class);
98+
}
99+
94100
@Override
95101
public String getTraceId() {
96102
return this.get(TRACE_ID_KEY, String.class);
@@ -406,7 +412,19 @@ public Builder withFlags(final Integer flags) {
406412
}
407413

408414
/**
409-
* Sets the status of the log event
415+
* Sets the schema url of span
416+
*
417+
* @param schemaUrl schema url
418+
* @return returns the builder
419+
* @since 2.11
420+
*/
421+
public Builder withSchemaUrl(final String schemaUrl) {
422+
data.put(SCHEMA_URL_KEY, schemaUrl);
423+
return this;
424+
}
425+
426+
/**
427+
* Sets the status of the span event
410428
*
411429
* @param status status to be set
412430
* @return the builder
@@ -418,7 +436,7 @@ public Builder withStatus(final Map<String, Object> status) {
418436
}
419437

420438
/**
421-
* Sets the scope of the log event
439+
* Sets the scope of the span event
422440
*
423441
* @param scope scope to be set
424442
* @return the builder
@@ -430,7 +448,7 @@ public Builder withScope(final Map<String, Object> scope) {
430448
}
431449

432450
/**
433-
* Sets the resource of the log event
451+
* Sets the resource of the span event
434452
*
435453
* @param resource resource to be set
436454
* @return the builder

data-prepper-api/src/main/java/org/opensearch/dataprepper/model/trace/Span.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,23 +168,31 @@ public interface Span extends Event {
168168
void setServiceName(final String serviceName);
169169

170170
/**
171-
* Gets the scope of this log event.
171+
* Gets the schema url of this span event.
172+
*
173+
* @return the schema url
174+
* @since 2.11
175+
*/
176+
String getSchemaUrl();
177+
178+
/**
179+
* Gets the scope of this span event.
172180
*
173181
* @return the scope
174182
* @since 2.11
175183
*/
176184
Map<String, Object> getScope();
177185

178186
/**
179-
* Gets the resource of this log event.
187+
* Gets the resource of this span event.
180188
*
181189
* @return the resource
182190
* @since 2.11
183191
*/
184192
Map<String, Object> getResource();
185193

186194
/**
187-
* Gets the status of this log event.
195+
* Gets the status of this span event.
188196
*
189197
* @return the status
190198
* @since 2.11

data-prepper-api/src/test/java/org/opensearch/dataprepper/model/metric/JacksonGaugeTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class JacksonGaugeTest {
4040
"key2", TEST_KEY2);
4141
protected static final Map<String, Object> TEST_SCOPE = ImmutableMap.of("name", UUID.randomUUID().toString(), "version", UUID.randomUUID().toString(), "attributes", List.of(Map.of("key", UUID.randomUUID().toString(), "value", UUID.randomUUID().toString())));
4242
protected static final Map<String, Object> TEST_RESOURCE = ImmutableMap.of("attributes", List.of(Map.of("key", UUID.randomUUID().toString(), "value", UUID.randomUUID().toString())));
43+
protected static final Map<String, Object> TEST_METADATA = ImmutableMap.of("metadataKey1", UUID.randomUUID().toString(), "metadataKey2", UUID.randomUUID().toString(), "metadataKey3", UUID.randomUUID().toString());
4344
protected static final String TEST_SERVICE_NAME = "service";
4445
protected static final String TEST_NAME = "name";
4546
protected static final String TEST_DESCRIPTION = "description";
@@ -72,6 +73,7 @@ public void setup() {
7273
.withUnit(TEST_UNIT_NAME)
7374
.withScope(TEST_SCOPE)
7475
.withResource(TEST_RESOURCE)
76+
.withMetricMetadata(TEST_METADATA)
7577
.withValue(TEST_VALUE)
7678
.withServiceName(TEST_SERVICE_NAME)
7779
.withExemplars(TEST_EXEMPLARS)
@@ -160,6 +162,12 @@ public void testGetResource() {
160162
assertThat(resource, is(equalTo(TEST_RESOURCE)));
161163
}
162164

165+
@Test
166+
public void testGetMetricMetadata() {
167+
final Map<String, Object> metadata = gauge.getMetricMetadata();
168+
assertThat(metadata, is(equalTo(TEST_METADATA)));
169+
}
170+
163171
@Test
164172
public void testGetTime() {
165173
final String endTime = gauge.getTime();

data-prepper-api/src/test/java/org/opensearch/dataprepper/model/trace/JacksonSpanTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class JacksonSpanTest {
4747
protected static final String TEST_PARENT_SPAN_ID = UUID.randomUUID().toString();
4848
protected static final String TEST_NAME = UUID.randomUUID().toString();
4949
protected static final String TEST_KIND = UUID.randomUUID().toString();
50+
protected static final String TEST_SCHEMA_URL = UUID.randomUUID().toString();
5051
protected static final int TEST_FLAGS = 10;
5152
protected static final String TEST_START_TIME = UUID.randomUUID().toString();
5253
protected static final String TEST_END_TIME = UUID.randomUUID().toString();
@@ -106,6 +107,7 @@ public void setup() {
106107
.withResource(TEST_RESOURCE)
107108
.withStatus(TEST_STATUS)
108109
.withStartTime(TEST_START_TIME)
110+
.withSchemaUrl(TEST_SCHEMA_URL)
109111
.withEndTime(TEST_END_TIME)
110112
.withAttributes(TEST_ATTRIBUTES)
111113
.withDroppedAttributesCount(TEST_DROPPED_ATTRIBUTES_COUNT)
@@ -168,6 +170,12 @@ public void testGetFlags() {
168170
assertThat(flags, is(equalTo(TEST_FLAGS)));
169171
}
170172

173+
@Test
174+
public void testGetSchemaUrl() {
175+
final String schemaUrl = jacksonSpan.getSchemaUrl();
176+
assertThat(schemaUrl, is(equalTo(TEST_SCHEMA_URL)));
177+
}
178+
171179
@Test
172180
public void testGetStartTime() {
173181
final String GetStartTime = jacksonSpan.getStartTime();

0 commit comments

Comments
 (0)