in finagle-zipkin-core/src/main/scala/com/twitter/finagle/zipkin/core/RawZipkinTracer.scala [53:155]
def record(record: Record): Unit = {
record.annotation match {
case tracing.Annotation.WireSend =>
annotate(record, thrift.Constants.WIRE_SEND)
case tracing.Annotation.WireRecv =>
annotate(record, thrift.Constants.WIRE_RECV)
case tracing.Annotation.WireRecvError(error: String) =>
annotate(record, ErrorAnnotation.format(thrift.Constants.WIRE_RECV_ERROR, error))
case tracing.Annotation.ClientSend =>
annotate(record, thrift.Constants.CLIENT_SEND)
case tracing.Annotation.ClientRecv =>
annotate(record, thrift.Constants.CLIENT_RECV)
case tracing.Annotation.ClientRecvError(error: String) =>
annotate(record, ErrorAnnotation.format(thrift.Constants.CLIENT_RECV_ERROR, error))
case tracing.Annotation.ServerSend =>
annotate(record, thrift.Constants.SERVER_SEND)
case tracing.Annotation.ServerRecv =>
annotate(record, thrift.Constants.SERVER_RECV)
case tracing.Annotation.ServerSendError(error: String) =>
annotate(record, ErrorAnnotation.format(thrift.Constants.SERVER_SEND_ERROR, error))
case tracing.Annotation.ClientSendFragment =>
annotate(record, thrift.Constants.CLIENT_SEND_FRAGMENT)
case tracing.Annotation.ClientRecvFragment =>
annotate(record, thrift.Constants.CLIENT_RECV_FRAGMENT)
case tracing.Annotation.ServerSendFragment =>
annotate(record, thrift.Constants.SERVER_SEND_FRAGMENT)
case tracing.Annotation.ServerRecvFragment =>
annotate(record, thrift.Constants.SERVER_RECV_FRAGMENT)
case tracing.Annotation.Message(value) =>
annotate(record, value)
case tracing.Annotation.Rpc(name: String) =>
spanMap.update(record.traceId)(_.setName(name))
case tracing.Annotation.ServiceName(serviceName: String) =>
spanMap.update(record.traceId)(_.setServiceName(serviceName))
case tracing.Annotation.BinaryAnnotation(key: String, value: Boolean) =>
binaryAnnotation(
record,
key,
(if (value) TrueBB else FalseBB).duplicate(),
thrift.AnnotationType.BOOL
)
case tracing.Annotation.BinaryAnnotation(key: String, value: Array[Byte]) =>
binaryAnnotation(record, key, ByteBuffer.wrap(value), thrift.AnnotationType.BYTES)
case tracing.Annotation.BinaryAnnotation(key: String, value: ByteBuffer) =>
binaryAnnotation(record, key, value, thrift.AnnotationType.BYTES)
case tracing.Annotation.BinaryAnnotation(key: String, value: Short) =>
binaryAnnotation(
record,
key,
ByteBuffer.allocate(2).putShort(0, value),
thrift.AnnotationType.I16
)
case tracing.Annotation.BinaryAnnotation(key: String, value: Int) =>
binaryAnnotation(
record,
key,
ByteBuffer.allocate(4).putInt(0, value),
thrift.AnnotationType.I32
)
case tracing.Annotation.BinaryAnnotation(key: String, value: Long) =>
binaryAnnotation(
record,
key,
ByteBuffer.allocate(8).putLong(0, value),
thrift.AnnotationType.I64
)
case tracing.Annotation.BinaryAnnotation(key: String, value: Double) =>
binaryAnnotation(
record,
key,
ByteBuffer.allocate(8).putDouble(0, value),
thrift.AnnotationType.DOUBLE
)
case tracing.Annotation.BinaryAnnotation(key: String, value: String) =>
binaryAnnotation(record, key, ByteBuffer.wrap(value.getBytes), thrift.AnnotationType.STRING)
case tracing.Annotation.BinaryAnnotation(key @ _, value @ _) => // Throw error?
case tracing.Annotation.LocalAddr(ia: InetSocketAddress) =>
setEndpoint(record, ia)
case tracing.Annotation.ClientAddr(ia: InetSocketAddress) =>
// use a binary annotation over a regular annotation to avoid a misleading timestamp
spanMap.update(record.traceId) {
_.addBinaryAnnotation(
BinaryAnnotation(
thrift.Constants.CLIENT_ADDR,
TrueBB.duplicate(),
thrift.AnnotationType.BOOL,
Endpoint.fromSocketAddress(ia)
)
)
}
case tracing.Annotation.ServerAddr(ia: InetSocketAddress) =>
spanMap.update(record.traceId) {
_.addBinaryAnnotation(
BinaryAnnotation(
thrift.Constants.SERVER_ADDR,
TrueBB.duplicate(),
thrift.AnnotationType.BOOL,
Endpoint.fromSocketAddress(ia)
)
)
}
}
}