Skip to content

Commit a8cb945

Browse files
committed
Add example
1 parent d364047 commit a8cb945

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

export/otelsdk/example_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package otelsdk_test
2+
3+
import (
4+
"context"
5+
"os/signal"
6+
"sync"
7+
"syscall"
8+
9+
"go.opentelemetry.io/auto"
10+
"go.opentelemetry.io/auto/export/otelsdk"
11+
)
12+
13+
func Example_multiplex() {
14+
ctx := context.Background()
15+
m, err := otelsdk.NewMultiplexer(ctx)
16+
if err != nil {
17+
panic(err)
18+
}
19+
20+
pids := []int{1297, 1331, 9827} // Simulated PIDs
21+
22+
var wg sync.WaitGroup
23+
for _, pid := range pids {
24+
wg.Add(1)
25+
go func() {
26+
defer wg.Done()
27+
28+
ctx, stop := signal.NotifyContext(ctx, syscall.SIGTERM)
29+
defer stop()
30+
31+
// Note: do not ignore errors in normal use.
32+
inst, _ := auto.NewInstrumentation(
33+
ctx, auto.WithPID(pid), auto.WithHandler(m.Handler(pid)),
34+
)
35+
_ = inst.Load(ctx)
36+
_ = inst.Run(ctx)
37+
}()
38+
}
39+
40+
wg.Wait()
41+
_ = m.Shutdown(ctx)
42+
}

export/otelsdk/multiplex.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,7 @@ func (m Multiplexer) withProcResAttrs(pid int) (c config) {
7777

7878
return c
7979
}
80+
81+
func (m Multiplexer) Shutdown(ctx context.Context) error {
82+
return m.cfg.spanProcessor.Shutdown(ctx)
83+
}

0 commit comments

Comments
 (0)