Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/soreing/motel
Go manual open telemetry span creator
https://github.com/soreing/motel
go golang open-telemetry tracing
Last synced: 27 days ago
JSON representation
Go manual open telemetry span creator
- Host: GitHub
- URL: https://github.com/soreing/motel
- Owner: Soreing
- Created: 2022-10-28T08:57:25.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-04T00:22:03.000Z (5 months ago)
- Last Synced: 2024-10-09T20:02:32.122Z (27 days ago)
- Topics: go, golang, open-telemetry, tracing
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Manual Open Telemetry
Motel is a simple library that lets you create Open Telemetry ReadOnlySpan objects with a constructor function instead of a tracer. The library batches and sends spans to one or more exporters.## Usage
Create a Motel Span Collector that will accept Open Telemetry ReadOnlySpans. You need to specify a list of exporters and a batch interval with batch limit. Spans will be sent to exporters periodically specified by the batch interval or when the number of batched spans reach the limit. Setting the batch interval and limit to 0 will disable batching and skip creating the resources for it.
```golang
coll := motel.NewSpanCollector(
[]trace.SpanExporter{},
time.Second * 5,
10,
)
```You can submit spans to the collector with the Feed method.
```golang
coll.Feed([]trace.ReadOnlySpan{/* spans */})
```To stop using the collector, use the Close method. The collector will close the channel used for batching and wait for the goroutine to stop before calling Shutdown on each exporter.
```golang
coll.Close(context.TODO())
```## Creating Spans
You can create Spans that implement ReadOnlySpan with a constructor function. You will need to provide required information from a traceparent header and additional details about the span, such name, as id, uccess, start and end time.
```golang
// W3C traceparent Header (ver-tid-pid-flg)
trc := "00-6aa68cc5f3ec62cc7311d38af7fb4176-b5e0e5ec613d07ab-01"
// Span Id
sId := "a4dfd4db502cf69a"tid := [16]byte{ /* Convert "6aa68cc5f3ec62cc7311d38af7fb4176" */}
pid := [8]byte{ /* Convert "b5e0e5ec613d07ab" */}
sid := [8]byte{ /* Convert "a4dfd4db502cf69a" */}
flg := 0x01
success := true
start, end := time.Now(), time.Now().Add(time.Second)// Create span with details
span := motel.CreateSpan(
"Span Name", trace.SpanKindServer,
resource.Default{},
tid, pid, sid, flg, success
startTime, endTime,
)
```