diff --git a/data-prepper-api/src/main/java/org/opensearch/dataprepper/model/log/JacksonOtelLog.java b/data-prepper-api/src/main/java/org/opensearch/dataprepper/model/log/JacksonOtelLog.java index 23127b153e..bb0c02be6d 100644 --- a/data-prepper-api/src/main/java/org/opensearch/dataprepper/model/log/JacksonOtelLog.java +++ b/data-prepper-api/src/main/java/org/opensearch/dataprepper/model/log/JacksonOtelLog.java @@ -33,6 +33,7 @@ public class JacksonOtelLog extends JacksonEvent implements OpenTelemetryLog { protected static final String SPAN_ID_KEY = "spanId"; protected static final String TRACE_ID_KEY = "traceId"; protected static final String SEVERITY_NUMBER_KEY = "severityNumber"; + protected static final String SEVERITY_TEXT_KEY = "severityText"; protected static final String DROPPED_ATTRIBUTES_COUNT_KEY = "droppedAttributesCount"; @@ -87,6 +88,11 @@ public Integer getSeverityNumber() { return this.get(SEVERITY_NUMBER_KEY, Integer.class); } + @Override + public String getSeverityText() { + return this.get(SEVERITY_TEXT_KEY, String.class); + } + @Override public Integer getDroppedAttributesCount() { return this.get(DROPPED_ATTRIBUTES_COUNT_KEY, Integer.class); @@ -262,6 +268,18 @@ public Builder withSeverityNumber(final Integer severityNumber) { return getThis(); } + /** + * Sets the severity text of this log event + * + * @param severityText sets the severity text of this log event + * @return the builder + * @since 2.5 + */ + public Builder withSeverityText(final String severityText) { + data.put(SEVERITY_TEXT_KEY, severityText); + return getThis(); + } + /** * Sets the dropped attributes count of this log event * diff --git a/data-prepper-api/src/main/java/org/opensearch/dataprepper/model/log/OpenTelemetryLog.java b/data-prepper-api/src/main/java/org/opensearch/dataprepper/model/log/OpenTelemetryLog.java index 6214eaf3ad..62d6d7fe06 100644 --- a/data-prepper-api/src/main/java/org/opensearch/dataprepper/model/log/OpenTelemetryLog.java +++ b/data-prepper-api/src/main/java/org/opensearch/dataprepper/model/log/OpenTelemetryLog.java @@ -88,6 +88,15 @@ public interface OpenTelemetryLog extends Log { */ Integer getSeverityNumber(); + /** + * Gets the severity text of this log event. + * + * @return the severity number encoded as Integer + * @since 2.5 + */ + String getSeverityText(); + + /** * Gets the dropped attributes count of this log event. * diff --git a/data-prepper-api/src/test/java/org/opensearch/dataprepper/model/log/JacksonOtelLogTest.java b/data-prepper-api/src/test/java/org/opensearch/dataprepper/model/log/JacksonOtelLogTest.java index 85c763ba38..fc8213323b 100644 --- a/data-prepper-api/src/test/java/org/opensearch/dataprepper/model/log/JacksonOtelLogTest.java +++ b/data-prepper-api/src/test/java/org/opensearch/dataprepper/model/log/JacksonOtelLogTest.java @@ -39,6 +39,7 @@ public class JacksonOtelLogTest { private static final String TEST_TRACE_ID = "1234"; private static final String TEST_SPAN_ID = "4321"; private static final Integer TEST_SEVERITY_NUMBER = 2; + private static final String TEST_SEVERITY_TEXT = "severity"; private static final Integer TEST_DROPPED_ATTRIBUTES_COUNT = 4; private static final Object TEST_BODY = Map.of("log", "message"); @@ -57,6 +58,7 @@ public void setup() { .withTraceId(TEST_TRACE_ID) .withSpanId(TEST_SPAN_ID) .withSeverityNumber(TEST_SEVERITY_NUMBER) + .withSeverityText(TEST_SEVERITY_TEXT) .withDroppedAttributesCount(TEST_DROPPED_ATTRIBUTES_COUNT) .withBody(TEST_BODY); @@ -105,6 +107,12 @@ public void testGetSpanId() { assertThat(spanId, is(equalTo(TEST_SPAN_ID))); } + @Test + public void testGetServerityText() { + final String severityText = log.getSeverityText(); + assertThat(severityText, is(equalTo(TEST_SEVERITY_TEXT))); + } + @Test public void testGetServerityNumber() { final Integer observedTime = log.getSeverityNumber(); diff --git a/data-prepper-plugins/otel-proto-common/src/main/java/org/opensearch/dataprepper/plugins/otel/codec/OTelProtoCodec.java b/data-prepper-plugins/otel-proto-common/src/main/java/org/opensearch/dataprepper/plugins/otel/codec/OTelProtoCodec.java index 9e40772989..16f596c989 100644 --- a/data-prepper-plugins/otel-proto-common/src/main/java/org/opensearch/dataprepper/plugins/otel/codec/OTelProtoCodec.java +++ b/data-prepper-plugins/otel-proto-common/src/main/java/org/opensearch/dataprepper/plugins/otel/codec/OTelProtoCodec.java @@ -252,6 +252,7 @@ protected List processLogsList(final List logsList, .withTraceId(OTelProtoCodec.convertByteStringToString(log.getTraceId())) .withSpanId(OTelProtoCodec.convertByteStringToString(log.getSpanId())) .withSeverityNumber(log.getSeverityNumberValue()) + .withSeverityText(log.getSeverityText()) .withDroppedAttributesCount(log.getDroppedAttributesCount()) .withBody(OTelProtoCodec.convertAnyValue(log.getBody())) .build()) diff --git a/data-prepper-plugins/otel-proto-common/src/test/java/org/opensearch/dataprepper/plugins/otel/codec/OTelProtoCodecTest.java b/data-prepper-plugins/otel-proto-common/src/test/java/org/opensearch/dataprepper/plugins/otel/codec/OTelProtoCodecTest.java index aff982b214..afc4cf2ab3 100644 --- a/data-prepper-plugins/otel-proto-common/src/test/java/org/opensearch/dataprepper/plugins/otel/codec/OTelProtoCodecTest.java +++ b/data-prepper-plugins/otel-proto-common/src/test/java/org/opensearch/dataprepper/plugins/otel/codec/OTelProtoCodecTest.java @@ -444,6 +444,7 @@ private void validateLog(OpenTelemetryLog logRecord) { assertThat(logRecord.getDroppedAttributesCount(), is(3)); assertThat(logRecord.getSchemaUrl(), is("schemaurl")); assertThat(logRecord.getSeverityNumber(), is(5)); + assertThat(logRecord.getSeverityText(), is("Severity value")); assertThat(logRecord.getTraceId(), is("ba1a1c23b4093b63")); assertThat(logRecord.getSpanId(), is("2cc83ac90ebc469c")); Map mergedAttributes = logRecord.getAttributes(); diff --git a/data-prepper-plugins/otel-proto-common/src/test/resources/test-request-log-is.json b/data-prepper-plugins/otel-proto-common/src/test/resources/test-request-log-is.json index 20971f9ad8..f598d05730 100644 --- a/data-prepper-plugins/otel-proto-common/src/test/resources/test-request-log-is.json +++ b/data-prepper-plugins/otel-proto-common/src/test/resources/test-request-log-is.json @@ -13,6 +13,7 @@ "logRecords": [{ "timeUnixNano": "1590328800000000000", "severityNumber": "SEVERITY_NUMBER_DEBUG", + "severityText": "Severity value", "body": { "stringValue": "Log value" }, diff --git a/data-prepper-plugins/otel-proto-common/src/test/resources/test-request-log.json b/data-prepper-plugins/otel-proto-common/src/test/resources/test-request-log.json index 9f58703d17..48b822bd3a 100644 --- a/data-prepper-plugins/otel-proto-common/src/test/resources/test-request-log.json +++ b/data-prepper-plugins/otel-proto-common/src/test/resources/test-request-log.json @@ -12,6 +12,7 @@ "logRecords": [{ "timeUnixNano": "1590328800000000000", "severityNumber": "SEVERITY_NUMBER_DEBUG", + "severityText": "Severity value", "body": { "stringValue": "Log value" },