otlpstream

package
v1.0.0-beta.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package otlpstream implements the binary framing Dagger Cloud's OTLP read streams speak — a byte-for-byte mirror of the server's api/otlpstream package (dagger.io#5226, "feat(cloud): stream telemetry over binary OTLP"), kept here because the server repository is not importable.

A stream is a sequence of frames. Each frame is a 16-byte header — 4 bytes of magic naming the frame kind, an 8-byte big-endian cursor, a 4-byte big-endian payload length — followed by the payload:

  • a DATA frame carries one binary-protobuf OTLP export request; a data frame with an EMPTY payload is a heartbeat, keeping intermediaries from closing a quiet connection;
  • a TERMINAL frame ends the stream: every selected row has been emitted;
  • an ERROR frame carries a UTF-8 message and ends the stream in failure.

Cursors increase monotonically, and a connection that ends without a terminal or error frame was TRUNCATED — which is what lets a consumer tell "the trace is fully transferred" from "the edge dropped the connection", a distinction the SSE protocol this replaced could not make.

Index

Constants

View Source
const (
	// ContentType is the media type of a framed stream; it doubles as the
	// Accept value a consumer negotiates with.
	ContentType = "application/vnd.dagger.otlp.stream"
	// CursorHeader is the resume header the server recognizes (and, today,
	// refuses for any cursor but 0).
	CursorHeader   = "X-Dagger-Telemetry-Cursor"
	FrameHeaderLen = 16
	MaxPayloadSize = 64 << 20
)

Variables

View Source
var (
	DataMagic     = [4]byte{'D', 'T', 'P', 1}
	TerminalMagic = [4]byte{'D', 'T', 'E', 1}
	ErrorMagic    = [4]byte{'D', 'T', 'X', 1}
)

Functions

func WriteFrame

func WriteFrame(w io.Writer, kind FrameKind, cursor uint64, payload []byte) error

WriteFrame writes one frame with an explicit cursor. The CLI only ever consumes these streams; the writing half exists for the test fakes that stand in for Cloud (and for tests that need to misbehave, e.g. repeat a cursor).

Types

type Frame

type Frame struct {
	Kind    FrameKind
	Cursor  uint64
	Payload []byte
}

func ReadFrame

func ReadFrame(r io.Reader) (Frame, error)

ReadFrame reads one complete frame, tolerating arbitrary fragmentation of both the fixed-size header and payload.

type FrameKind

type FrameKind uint8
const (
	FrameData FrameKind = iota + 1
	FrameTerminal
	FrameError
)

type FrameWriter

type FrameWriter struct {
	// contains filtered or unexported fields
}

FrameWriter emits frames the way the server's live writer does: cursors assigned sequentially from 1, heartbeats as empty data frames.

func NewFrameWriter

func NewFrameWriter(w io.Writer) *FrameWriter

func (*FrameWriter) WriteData

func (fw *FrameWriter) WriteData(payload []byte) error

func (*FrameWriter) WriteError

func (fw *FrameWriter) WriteError(msg string) error

func (*FrameWriter) WriteHeartbeat

func (fw *FrameWriter) WriteHeartbeat() error

func (*FrameWriter) WriteTerminal

func (fw *FrameWriter) WriteTerminal() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL