diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/DslJsonDataWriter.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/DslJsonDataWriter.java index b17cf31b98..54f4d7ff7b 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/DslJsonDataWriter.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/DslJsonDataWriter.java @@ -86,13 +86,8 @@ public void serialize(double value) { } @Override - public void writeAscii(String value) { - jw.writeAscii(value); - } - - @Override - public void writeString(CharSequence replaceBuilder) { - jw.writeString(replaceBuilder); + public void writeString(CharSequence value) { + jw.writeString(value); } @Override diff --git a/apm-agent-plugins/apm-micrometer-plugin/pom.xml b/apm-agent-plugins/apm-micrometer-plugin/pom.xml index 1939b8ca2f..61b8f25b10 100644 --- a/apm-agent-plugins/apm-micrometer-plugin/pom.xml +++ b/apm-agent-plugins/apm-micrometer-plugin/pom.xml @@ -20,12 +20,6 @@ - - - ${project.groupId} - apm-agent-core - ${project.version} - io.micrometer micrometer-core diff --git a/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMeterRegistrySerializer.java b/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMeterRegistrySerializer.java index f794f78ccb..e06145f7b7 100644 --- a/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMeterRegistrySerializer.java +++ b/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMeterRegistrySerializer.java @@ -18,6 +18,7 @@ */ package co.elastic.apm.agent.micrometer; +import co.elastic.apm.agent.report.serialize.DslJsonDataWriter; import co.elastic.apm.agent.sdk.internal.util.PrivilegedActionUtils; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -26,6 +27,8 @@ import co.elastic.apm.agent.tracer.configuration.MetricsConfiguration; import co.elastic.apm.agent.tracer.reporting.DataWriter; import co.elastic.apm.agent.tracer.reporting.ReportingTracer; +import com.dslplatform.json.DslJson; +import com.dslplatform.json.JsonWriter; import io.micrometer.core.instrument.Counter; import io.micrometer.core.instrument.DistributionSummary; import io.micrometer.core.instrument.FunctionCounter; @@ -256,9 +259,7 @@ private static void serializeHistogram(Meter.Id id, HistogramSnapshot histogramS } writer.write(ARRAY_END); writer.write(COMMA); - writer.write(QUOTE); - writer.writeAscii("counts"); - writer.write(QUOTE); + writer.writeString("counts"); writer.write(SEMI); writer.write(ARRAY_START); // Micrometer bucket counts are cumulative: E.g. the count at bucket with upper @@ -277,7 +278,8 @@ private static void serializeHistogram(Meter.Id id, HistogramSnapshot histogramS writer.write(ARRAY_END); writer.write(COMMA); - writer.writeAscii("\"type\":\"histogram\""); + writer.writeFieldName("type"); + writer.writeString("histogram"); writer.write(OBJECT_END); } @@ -335,13 +337,20 @@ private static void serializeObjectStart(String key, String objectName, String s writer.write(SEMI); writer.write(OBJECT_START); - writer.write(QUOTE); - writer.writeAscii(objectName); - writer.write(QUOTE); - writer.write(SEMI); + writer.writeFieldName(objectName); } private static boolean isValidValue(double value) { return !Double.isNaN(value) && !Double.isInfinite(value); } + + public static void main(String[] args) { + DslJson dslJson = new DslJson<>(new DslJson.Settings<>()); + JsonWriter jw = dslJson.newWriter(512); + jw.writeAscii("\"foo\""); + //jw.writeString("foo"); + String string = jw.toString(); + System.out.println(string); + + } } diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/main/java/co/elastic/apm/agent/otelmetricsdk/MetricSetSerializer.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/main/java/co/elastic/apm/agent/otelmetricsdk/MetricSetSerializer.java index 9d86b59c50..5dd92dd73d 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/main/java/co/elastic/apm/agent/otelmetricsdk/MetricSetSerializer.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/main/java/co/elastic/apm/agent/otelmetricsdk/MetricSetSerializer.java @@ -107,7 +107,8 @@ public void addExplicitBucketHistogram(CharSequence metricName, List bou serializeFieldKeyAscii("counts"); convertAndSerializeHistogramBucketCounts(counts); writer.write(COMMA); - writer.writeAscii("\"type\":\"histogram\""); + writer.writeFieldName("type"); + writer.writeString("histogram"); } writer.write(OBJECT_END); anySamplesWritten = true; @@ -172,10 +173,7 @@ private void serializeFieldKey(CharSequence fieldName) { } private void serializeFieldKeyAscii(String fieldName) { - writer.write(QUOTE); - writer.writeAscii(fieldName); - writer.write(QUOTE); - writer.write(SEMI); + writer.writeFieldName(fieldName); } private void serializeAttributes(CharSequence instrumentationScopeName, Attributes attributes) { @@ -187,7 +185,7 @@ private void serializeAttributes(CharSequence instrumentationScopeName, Attribut writer.write(OBJECT_START); boolean anyWritten = false; if (instrumentationScopeName.length() > 0) { - writer.writeAscii("\"otel_instrumentation_scope_name\":"); + writer.writeFieldName("otel_instrumentation_scope_name"); writer.writeString(instrumentationScopeName); anyWritten = true; } diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/reporting/DataWriter.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/reporting/DataWriter.java index 7035fe4f34..0a0b2e9c0b 100644 --- a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/reporting/DataWriter.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/reporting/DataWriter.java @@ -30,9 +30,7 @@ public interface DataWriter { void serialize(double value); - void writeAscii(String value); - - void writeString(CharSequence replaceBuilder); + void writeString(CharSequence value); void writeStringValue(CharSequence value, StringBuilder replaceBuilder);