]> Sergey Matveev's repositories - btrtrc.git/blob - webtorrent/otel.go
d939c3f83401d7ac6c36cf039d2d54d8079fdc47
[btrtrc.git] / webtorrent / otel.go
1 package webtorrent
2
3 import (
4         "context"
5         "github.com/pion/webrtc/v3"
6         "go.opentelemetry.io/otel"
7         "go.opentelemetry.io/otel/trace"
8 )
9
10 const (
11         tracerName        = "anacrolix.torrent.webtorrent"
12         webrtcConnTypeKey = "webtorrent.webrtc.conn.type"
13 )
14
15 func dataChannelStarted(peerConnectionCtx context.Context, dc *webrtc.DataChannel) (dataChannelCtx context.Context, span trace.Span) {
16         trace.SpanFromContext(peerConnectionCtx).AddEvent("starting data channel")
17         dataChannelCtx, span = otel.Tracer(tracerName).Start(peerConnectionCtx, "DataChannel")
18         dc.OnClose(func() {
19                 span.End()
20         })
21         return
22 }