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 int
BUFFER_SIZE
Matches default ZLIB buffer size.static int
MAX_LONG_STRING_VALUE_LENGTH
static int
MAX_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 void
appendMetaDataNdJsonToStream()
Appends the serialized metadata to ND-JSON as ametadata
line.void
appendMetadataToStream()
Appends the serialized metadata to the underlyingOutputStream
.void
blockUntilReady()
Blocking until thisPayloadSerializer
is ready for use.void
flushToOutputStream()
Flushes content that has been written so far to theOutputStream
which has been set viasetOutputStream(OutputStream)
, without flushing theOutputStream
itself.void
fullFlush()
Flushes theOutputStream
which has been set viasetOutputStream(OutputStream)
and detaches thatOutputStream
from the serializer.int
getBufferSize()
Returns the number of bytes already serialized and waiting in the underlyingJsonWriter
's buffer.com.dslplatform.json.JsonWriter
getJsonWriter()
static java.lang.CharSequence
sanitizeLabelKey(java.lang.String key, java.lang.StringBuilder replaceBuilder)
void
serializeErrorNdJson(ErrorCapture error)
void
serializeFileMetaData(java.io.File file)
void
serializeSpanNdJson(Span span)
void
serializeTransactionNdJson(Transaction transaction)
void
setOutputStream(java.io.OutputStream os)
Sets the output stream which the*NdJson
methods should write to.java.lang.String
toJsonString(ErrorCapture error)
java.lang.String
toJsonString(Span span)
java.lang.String
toJsonString(Transaction transaction)
java.lang.String
toJsonString(java.lang.StackTraceElement stackTraceElement)
java.lang.String
toString()
void
writeBytes(byte[] bytes, int len)
static void
writeFieldName(java.lang.String fieldName, com.dslplatform.json.JsonWriter jw)
static void
writeLastField(java.lang.String fieldName, java.lang.CharSequence value, java.lang.StringBuilder replaceBuilder, com.dslplatform.json.JsonWriter jw)
static void
writeStringValue(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:PayloadSerializer
Sets the output stream which the*NdJson
methods should write to.- Specified by:
setOutputStream
in interfacePayloadSerializer
- Parameters:
os
- theOutputStream
to which all contents are to be serialized
-
fullFlush
public void fullFlush() throws java.io.IOException
Flushes theOutputStream
which has been set viasetOutputStream(OutputStream)
and detaches thatOutputStream
from the serializer.- Specified by:
fullFlush
in interfacePayloadSerializer
- Throws:
java.io.IOException
-
flushToOutputStream
public void flushToOutputStream()
Flushes content that has been written so far to theOutputStream
which has been set viasetOutputStream(OutputStream)
, without flushing theOutputStream
itself. Subsequent serializations will be made to the sameOutputStream
.- Specified by:
flushToOutputStream
in interfacePayloadSerializer
-
appendMetaDataNdJsonToStream
public void appendMetaDataNdJsonToStream() throws PayloadSerializer.UninitializedException
Appends the serialized metadata to ND-JSON as ametadata
line.NOTE: Must be called after
PayloadSerializer.blockUntilReady()
was called and returned, otherwise the cached serialized metadata may not be ready yet.- Specified by:
appendMetaDataNdJsonToStream
in interfacePayloadSerializer
- Throws:
PayloadSerializer.UninitializedException
- may be thrown ifPayloadSerializer.blockUntilReady()
was not invoked
-
appendMetadataToStream
public void appendMetadataToStream() throws PayloadSerializer.UninitializedException
Appends 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:
appendMetadataToStream
in interfacePayloadSerializer
- Throws:
PayloadSerializer.UninitializedException
- may be thrown ifPayloadSerializer.blockUntilReady()
was not invoked
-
blockUntilReady
public void blockUntilReady() throws java.lang.Exception
Blocking until thisPayloadSerializer
is ready for use. Blocking will be timed out with aTimeoutException
if 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:
blockUntilReady
in 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:
serializeTransactionNdJson
in interfacePayloadSerializer
-
serializeSpanNdJson
public void serializeSpanNdJson(Span span)
- Specified by:
serializeSpanNdJson
in interfacePayloadSerializer
-
serializeErrorNdJson
public void serializeErrorNdJson(ErrorCapture error)
- Specified by:
serializeErrorNdJson
in 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:
getBufferSize
in interfacePayloadSerializer
- Returns:
- number of bytes currently waiting in the underlying
JsonWriter
to be flushed to the underlying stream
-
serializeFileMetaData
public void serializeFileMetaData(java.io.File file)
- Specified by:
serializeFileMetaData
in interfacePayloadSerializer
-
getJsonWriter
public com.dslplatform.json.JsonWriter getJsonWriter()
- Specified by:
getJsonWriter
in interfacePayloadSerializer
-
writeBytes
public void writeBytes(byte[] bytes, int len)
- Specified by:
writeBytes
in 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:
toString
in classjava.lang.Object
-
sanitizeLabelKey
public static java.lang.CharSequence sanitizeLabelKey(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)
-
-