Class DslJsonSerializer
- java.lang.Object
-
- co.elastic.apm.agent.report.serialize.DslJsonSerializer
-
- All Implemented Interfaces:
PayloadSerializer
public class DslJsonSerializer extends java.lang.Object implements PayloadSerializer
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface co.elastic.apm.agent.report.serialize.PayloadSerializer
PayloadSerializer.UninitializedException
-
-
Field Summary
Fields Modifier and Type Field Description static intBUFFER_SIZEMatches default ZLIB buffer size.static intMAX_LONG_STRING_VALUE_LENGTHstatic intMAX_VALUE_LENGTH
-
Constructor Summary
Constructors Constructor Description DslJsonSerializer(StacktraceConfiguration stacktraceConfiguration, ApmServerClient apmServerClient, java.util.concurrent.Future<MetaData> metaData)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendMetaDataNdJsonToStream()Appends the serialized metadata to ND-JSON as ametadataline.voidappendMetadataToStream()Appends the serialized metadata to the underlyingOutputStream.voidblockUntilReady()Blocking until thisPayloadSerializeris ready for use.voidflushToOutputStream()Flushes content that has been written so far to theOutputStreamwhich has been set viasetOutputStream(OutputStream), without flushing theOutputStreamitself.voidfullFlush()Flushes theOutputStreamwhich has been set viasetOutputStream(OutputStream)and detaches thatOutputStreamfrom the serializer.intgetBufferSize()Returns the number of bytes already serialized and waiting in the underlyingJsonWriter's buffer.com.dslplatform.json.JsonWritergetJsonWriter()static java.lang.CharSequencesanitizePropertyName(java.lang.String key, java.lang.StringBuilder replaceBuilder)voidserializeErrorNdJson(ErrorCapture error)voidserializeFileMetaData(java.io.File file)voidserializeSpanNdJson(Span span)voidserializeTransactionNdJson(Transaction transaction)voidsetOutputStream(java.io.OutputStream os)Sets the output stream which the*NdJsonmethods should write to.java.lang.StringtoJsonString(ErrorCapture error)java.lang.StringtoJsonString(Span span)java.lang.StringtoJsonString(Transaction transaction)java.lang.StringtoJsonString(java.lang.StackTraceElement stackTraceElement)java.lang.StringtoString()voidwriteBytes(byte[] bytes, int len)static voidwriteFieldName(java.lang.String fieldName, com.dslplatform.json.JsonWriter jw)static voidwriteLastField(java.lang.String fieldName, java.lang.CharSequence value, java.lang.StringBuilder replaceBuilder, com.dslplatform.json.JsonWriter jw)static voidwriteStringValue(java.lang.CharSequence value, java.lang.StringBuilder replaceBuilder, com.dslplatform.json.JsonWriter jw)
-
-
-
Field Detail
-
BUFFER_SIZE
public static final int BUFFER_SIZE
Matches default ZLIB buffer size. Lets us assume the ZLIB buffer is always empty, so thatgetBufferSize()is the total amount of buffered bytes.- See Also:
- Constant Field Values
-
MAX_VALUE_LENGTH
public static final int MAX_VALUE_LENGTH
- See Also:
- Constant Field Values
-
MAX_LONG_STRING_VALUE_LENGTH
public static final int MAX_LONG_STRING_VALUE_LENGTH
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DslJsonSerializer
public DslJsonSerializer(StacktraceConfiguration stacktraceConfiguration, ApmServerClient apmServerClient, java.util.concurrent.Future<MetaData> metaData)
-
-
Method Detail
-
setOutputStream
public void setOutputStream(java.io.OutputStream os)
Description copied from interface:PayloadSerializerSets the output stream which the*NdJsonmethods should write to.- Specified by:
setOutputStreamin interfacePayloadSerializer- Parameters:
os- theOutputStreamto which all contents are to be serialized
-
fullFlush
public void fullFlush() throws java.io.IOExceptionFlushes theOutputStreamwhich has been set viasetOutputStream(OutputStream)and detaches thatOutputStreamfrom the serializer.- Specified by:
fullFlushin interfacePayloadSerializer- Throws:
java.io.IOException
-
flushToOutputStream
public void flushToOutputStream()
Flushes content that has been written so far to theOutputStreamwhich has been set viasetOutputStream(OutputStream), without flushing theOutputStreamitself. Subsequent serializations will be made to the sameOutputStream.- Specified by:
flushToOutputStreamin interfacePayloadSerializer
-
appendMetaDataNdJsonToStream
public void appendMetaDataNdJsonToStream() throws PayloadSerializer.UninitializedExceptionAppends the serialized metadata to ND-JSON as ametadataline.NOTE: Must be called after
PayloadSerializer.blockUntilReady()was called and returned, otherwise the cached serialized metadata may not be ready yet.- Specified by:
appendMetaDataNdJsonToStreamin interfacePayloadSerializer- Throws:
PayloadSerializer.UninitializedException- may be thrown ifPayloadSerializer.blockUntilReady()was not invoked
-
appendMetadataToStream
public void appendMetadataToStream() throws PayloadSerializer.UninitializedExceptionAppends the serialized metadata to the underlyingOutputStream.NOTE: Must be called after
PayloadSerializer.blockUntilReady()was called and returned, otherwise the cached serialized metadata may not be ready yet.- Specified by:
appendMetadataToStreamin interfacePayloadSerializer- Throws:
PayloadSerializer.UninitializedException- may be thrown ifPayloadSerializer.blockUntilReady()was not invoked
-
blockUntilReady
public void blockUntilReady() throws java.lang.ExceptionBlocking until thisPayloadSerializeris ready for use. Blocking will be timed out with aTimeoutExceptionif the serializer is not ready within 5 seconds. Since the requirement is to call this method is called on the same thread that calls subsequently callsappendMetadataToStream(), there is no risk of visibility issues with regard toserializedMetaData.- Specified by:
blockUntilReadyin interfacePayloadSerializer- Throws:
java.lang.Exception- if blocking was interrupted, or timed out or an error occurred in the underlying implementation
-
serializeTransactionNdJson
public void serializeTransactionNdJson(Transaction transaction)
- Specified by:
serializeTransactionNdJsonin interfacePayloadSerializer
-
serializeSpanNdJson
public void serializeSpanNdJson(Span span)
- Specified by:
serializeSpanNdJsonin interfacePayloadSerializer
-
serializeErrorNdJson
public void serializeErrorNdJson(ErrorCapture error)
- Specified by:
serializeErrorNdJsonin interfacePayloadSerializer
-
getBufferSize
public int getBufferSize()
Returns the number of bytes already serialized and waiting in the underlyingJsonWriter's buffer. Note that the resulting JSON can be bigger if a Stream is set to the writer and some data was already flushed- Specified by:
getBufferSizein interfacePayloadSerializer- Returns:
- number of bytes currently waiting in the underlying
JsonWriterto be flushed to the underlying stream
-
serializeFileMetaData
public void serializeFileMetaData(java.io.File file)
- Specified by:
serializeFileMetaDatain interfacePayloadSerializer
-
getJsonWriter
public com.dslplatform.json.JsonWriter getJsonWriter()
- Specified by:
getJsonWriterin interfacePayloadSerializer
-
writeBytes
public void writeBytes(byte[] bytes, int len)- Specified by:
writeBytesin interfacePayloadSerializer
-
toJsonString
public java.lang.String toJsonString(Transaction transaction)
-
toJsonString
public java.lang.String toJsonString(Span span)
-
toJsonString
public java.lang.String toJsonString(ErrorCapture error)
-
toJsonString
public java.lang.String toJsonString(java.lang.StackTraceElement stackTraceElement)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
sanitizePropertyName
public static java.lang.CharSequence sanitizePropertyName(java.lang.String key, java.lang.StringBuilder replaceBuilder)
-
writeStringValue
public static void writeStringValue(java.lang.CharSequence value, java.lang.StringBuilder replaceBuilder, com.dslplatform.json.JsonWriter jw)
-
writeLastField
public static void writeLastField(java.lang.String fieldName, @Nullable java.lang.CharSequence value, java.lang.StringBuilder replaceBuilder, com.dslplatform.json.JsonWriter jw)
-
writeFieldName
public static void writeFieldName(java.lang.String fieldName, com.dslplatform.json.JsonWriter jw)
-
-