From 1e685f348091642007bb23a0556cef326263ff95 Mon Sep 17 00:00:00 2001 From: Jack Berg Date: Mon, 26 Sep 2022 14:28:40 -0500 Subject: [PATCH] Encode enums as numbers in logging OTLP exporters --- .../exporter/internal/marshal/JsonSerializer.java | 2 +- .../otlp/OtlpJsonLoggingLogRecordExporterTest.java | 4 ++-- .../logging/otlp/OtlpJsonLoggingMetricExporterTest.java | 4 ++-- .../logging/otlp/OtlpJsonLoggingSpanExporterTest.java | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/JsonSerializer.java b/exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/JsonSerializer.java index 75430d69752..ec805fc1fbf 100644 --- a/exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/JsonSerializer.java +++ b/exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/JsonSerializer.java @@ -43,7 +43,7 @@ public void writeBool(ProtoFieldInfo field, boolean value) throws IOException { @Override protected void writeEnum(ProtoFieldInfo field, ProtoEnumInfo enumValue) throws IOException { - generator.writeStringField(field.getJsonName(), enumValue.getJsonName()); + generator.writeNumberField(field.getJsonName(), enumValue.getEnumNumber()); } @Override diff --git a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingLogRecordExporterTest.java b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingLogRecordExporterTest.java index 876f13a7143..ec37ce9adb8 100644 --- a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingLogRecordExporterTest.java +++ b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingLogRecordExporterTest.java @@ -110,7 +110,7 @@ void log() throws Exception { + " }," + " \"logRecords\": [{" + " \"timeUnixNano\":\"1631533710000000\"," - + " \"severityNumber\":\"SEVERITY_NUMBER_INFO\"," + + " \"severityNumber\":9," + " \"severityText\":\"INFO\"," + " \"body\": {" + " \"stringValue\":\"body2\"" @@ -137,7 +137,7 @@ void log() throws Exception { + " }," + " \"logRecords\": [{" + " \"timeUnixNano\":\"1631533710000000\"," - + " \"severityNumber\":\"SEVERITY_NUMBER_INFO\"," + + " \"severityNumber\":9," + " \"severityText\":\"INFO\"," + " \"body\": {" + " \"stringValue\":\"body1\"" diff --git a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingMetricExporterTest.java b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingMetricExporterTest.java index 22053528842..78155aa8b95 100644 --- a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingMetricExporterTest.java +++ b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingMetricExporterTest.java @@ -122,7 +122,7 @@ void log() throws Exception { + " \"timeUnixNano\": \"2\"," + " \"asDouble\": 4.0" + " }]," - + " \"aggregationTemporality\": \"AGGREGATION_TEMPORALITY_CUMULATIVE\"," + + " \"aggregationTemporality\": 2," + " \"isMonotonic\": true" + " }" + " }]" @@ -151,7 +151,7 @@ void log() throws Exception { + " \"timeUnixNano\": \"2\"," + " \"asDouble\": 4.0" + " }]," - + " \"aggregationTemporality\": \"AGGREGATION_TEMPORALITY_CUMULATIVE\"," + + " \"aggregationTemporality\": 2," + " \"isMonotonic\": true" + " }" + " }]" diff --git a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingSpanExporterTest.java b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingSpanExporterTest.java index 9c429003c44..63f7fb6aa9c 100644 --- a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingSpanExporterTest.java +++ b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingSpanExporterTest.java @@ -126,11 +126,11 @@ void log() throws Exception { + " \"traceId\": \"12340000000043211234000000004321\"," + " \"spanId\": \"8765000000005678\"," + " \"name\": \"testSpan2\"," - + " \"kind\": \"SPAN_KIND_CLIENT\"," + + " \"kind\": 3," + " \"startTimeUnixNano\": \"500\"," + " \"endTimeUnixNano\": \"1501\"," + " \"status\": {" - + " \"code\": \"STATUS_CODE_ERROR\"" + + " \"code\": 2" + " }" + " }]" + " }, {" @@ -148,7 +148,7 @@ void log() throws Exception { + " \"traceId\": \"12345678876543211234567887654321\"," + " \"spanId\": \"8765432112345678\"," + " \"name\": \"testSpan1\"," - + " \"kind\": \"SPAN_KIND_INTERNAL\"," + + " \"kind\": 1," + " \"startTimeUnixNano\": \"100\"," + " \"endTimeUnixNano\": \"1100\"," + " \"attributes\": [{" @@ -173,7 +173,7 @@ void log() throws Exception { + " }]" + " }]," + " \"status\": {" - + " \"code\": \"STATUS_CODE_OK\"" + + " \"code\": 1" + " }" + " }]" + " }]"