Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions internal/infra/open_telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ package infra
import (
"context"
"fmt"
"io"
"log"
"os"
"path"
"path/filepath"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/network"
"github.com/goware/prefixer"
"github.com/moby/moby/client"
"log"
"os"
"path"
"path/filepath"
"github.com/moby/moby/pkg/stdcopy"
)

// CollectorImageName is the default Docker image used
Expand Down Expand Up @@ -101,7 +105,23 @@ func NewCollector(ctx context.Context, cli *client.Client, net *Networks, params
}

return collector, nil
}

func (c *Collector) TailLogs(ctx context.Context, cli *client.Client) {
out, err := cli.ContainerLogs(ctx, c.containerID, container.LogsOptions{
ShowStdout: true,
ShowStderr: true,
Follow: true,
})
if err != nil {
return
}

r, w := io.Pipe()
go func() {
_, _ = io.Copy(os.Stderr, prefixer.New(r, " otel | "))
}()
_, _ = stdcopy.StdCopy(w, w, out)
}

// Close stops and removes the container.
Expand Down
3 changes: 3 additions & 0 deletions internal/infra/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ func runContainers(ctx context.Context, params RunParams) (err error) {
if err != nil {
fmt.Println("Failed to create OpenTelemetry collector:", err)
}
if !params.Debug {
go collector.TailLogs(ctx, cli)
}
defer collector.Close()
}

Expand Down